-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/grpc support #40
Changes from 6 commits
0951c46
26d0f41
e7dca6f
7d7378b
58e1de3
6e864d8
d01de7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,7 @@ type ContainerInstance struct { | |
Name string `yaml:"name"` | ||
Image string `yaml:"image"` | ||
ImagePullPolicy string `yaml:"imagePullPolicy"` | ||
Env []EnvInstance `yaml:"env"` | ||
Ports []ContainerPortInstance `yaml:"ports"` | ||
Volumes []ContainerVolumeInstance `yaml:"volumeMounts"` | ||
ReadinessProbe ReadinessProbeInstance `yaml:"readinessProbe,omitempty"` | ||
|
@@ -110,16 +111,24 @@ type ContainerPortInstance struct { | |
ContainerPort int `yaml:"containerPort"` | ||
} | ||
|
||
type EnvInstance struct { | ||
Name string `yaml:"name"` | ||
Value string `yaml:"value"` | ||
} | ||
|
||
type ContainerVolumeInstance struct { | ||
MountPath string `yaml:"mountPath,omitempty"` | ||
MountName string `yaml:"name,omitempty"` | ||
} | ||
|
||
type ReadinessProbeInstance struct { | ||
HttpGet struct { | ||
Path string `yaml:"path"` | ||
Port int `yaml:"port"` | ||
} `yaml:"httpGet"` | ||
Path string `yaml:"path,omitempty"` | ||
Port int `yaml:"port,omitempty"` | ||
} `yaml:"httpGet,omitempty"` | ||
Exec struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this so you can probe readiness in grpc with your own implemented mechanism? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes |
||
Command []string `yaml:"command,flow,omitempty"` | ||
} `yaml:"exec,omitempty"` | ||
InitialDelaySeconds int `yaml:"initialDelaySeconds"` | ||
PeriodSeconds int `yaml:"periodSeconds"` | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,15 +23,18 @@ import ( | |
func CreateDeployment(metadataName, selectorAppName, selectorClusterName string, numberOfReplicas int, | ||
templateAppLabel, templateClusterLabel, namespace string, containerPort int, containerName, containerImage, | ||
mountPath string, volumeName, configMapName string, readinessProbe int, requestCPU, requestMemory, limitCPU, | ||
limitMemory string) (deploymentInstance model.DeploymentInstance) { | ||
limitMemory, protocol string) (deploymentInstance model.DeploymentInstance) { | ||
|
||
var deployment model.DeploymentInstance | ||
var containerInstance model.ContainerInstance | ||
var envInstance model.EnvInstance | ||
|
||
var containerPortInstance model.ContainerPortInstance | ||
var containerVolume model.ContainerVolumeInstance | ||
var volumeInstance model.VolumeInstance | ||
|
||
envInstance.Name = "SERVICE_NAME" | ||
envInstance.Value = metadataName | ||
containerPortInstance.ContainerPort = containerPort | ||
volumeInstance.Name = volumeName | ||
volumeInstance.ConfigMap.Name = configMapName | ||
|
@@ -44,8 +47,14 @@ func CreateDeployment(metadataName, selectorAppName, selectorClusterName string, | |
containerInstance.Name = containerName | ||
containerInstance.Image = containerImage | ||
containerInstance.ImagePullPolicy = "Never" | ||
containerInstance.ReadinessProbe.HttpGet.Path = "/" | ||
containerInstance.ReadinessProbe.HttpGet.Port = containerPort | ||
if protocol == "http" { | ||
containerInstance.ReadinessProbe.HttpGet.Path = "/" | ||
containerInstance.ReadinessProbe.HttpGet.Port = containerPort | ||
} | ||
if protocol == "grpc" { | ||
containerInstance.ReadinessProbe.Exec.Command = append(containerInstance.ReadinessProbe.Exec.Command, string("/bin/grpc_health_probe")) | ||
containerInstance.ReadinessProbe.Exec.Command = append(containerInstance.ReadinessProbe.Exec.Command, "-addr=:5000") | ||
} | ||
containerInstance.ReadinessProbe.InitialDelaySeconds = readinessProbe | ||
containerInstance.ReadinessProbe.PeriodSeconds = 1 | ||
containerInstance.Resources.ResourceRequests.Cpu = requestCPU | ||
|
@@ -73,14 +82,17 @@ func CreateDeployment(metadataName, selectorAppName, selectorClusterName string, | |
func CreateDeploymentWithAffinity(metadataName, selectorAppName, selectorClusterName string, numberOfReplicas int, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The functions CreateDeployment() and CreateDeploymentWithAffinity() share several lines of similar code... we may consider here how to avoid duplicated code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be fixed by #41. |
||
templateAppLabel, templateClusterLabel, namespace string, containerPort int, containerName, containerImage, | ||
mountPath string, volumeName, configMapName string, readinessProbe int, requestCPU, requestMemory, limitCPU, | ||
limitMemory, nodeAffinity string) (deploymentInstance model.DeploymentInstanceWithAffinity) { | ||
limitMemory, nodeAffinity, protocol string) (deploymentInstance model.DeploymentInstanceWithAffinity) { | ||
|
||
var deployment model.DeploymentInstanceWithAffinity | ||
var containerInstance model.ContainerInstance | ||
var envInstance model.EnvInstance | ||
var containerPortInstance model.ContainerPortInstance | ||
var containerVolume model.ContainerVolumeInstance | ||
var volumeInstance model.VolumeInstance | ||
|
||
envInstance.Name = "SERVICE_NAME" | ||
envInstance.Value = metadataName | ||
containerPortInstance.ContainerPort = containerPort | ||
volumeInstance.Name = volumeName | ||
volumeInstance.ConfigMap.Name = configMapName | ||
|
@@ -93,8 +105,16 @@ func CreateDeploymentWithAffinity(metadataName, selectorAppName, selectorCluster | |
containerInstance.Name = containerName | ||
containerInstance.Image = containerImage | ||
containerInstance.ImagePullPolicy = "Never" | ||
containerInstance.ReadinessProbe.HttpGet.Path = "/" | ||
containerInstance.ReadinessProbe.HttpGet.Port = containerPort | ||
containerInstance.Env = append(containerInstance.Env, envInstance) | ||
if protocol == "http" { | ||
containerInstance.ReadinessProbe.HttpGet.Path = "/" | ||
containerInstance.ReadinessProbe.HttpGet.Port = containerPort | ||
} | ||
if protocol == "grpc" { | ||
containerInstance.ReadinessProbe.Exec.Command = append(containerInstance.ReadinessProbe.Exec.Command, ("/bin/grpc_health_probe"), "-addr=:"+string(containerPort)) | ||
|
||
} | ||
|
||
containerInstance.ReadinessProbe.InitialDelaySeconds = readinessProbe | ||
containerInstance.ReadinessProbe.PeriodSeconds = 1 | ||
containerInstance.Resources.ResourceRequests.Cpu = requestCPU | ||
|
@@ -194,7 +214,7 @@ func CreateServiceAccount(metadataName, accountName string) (serviceAccountInsta | |
return serviceAccount | ||
} | ||
|
||
func CreateConfig(metadataName, metadataLabelName, metadataLabelCluster, namespace, config string) (configMapInstance model.ConfigMapInstance) { | ||
func CreateConfig(metadataName, metadataLabelName, metadataLabelCluster, namespace, config, proto string) (configMapInstance model.ConfigMapInstance) { | ||
|
||
const apiVersion = "v1" | ||
|
||
|
@@ -209,6 +229,7 @@ func CreateConfig(metadataName, metadataLabelName, metadataLabelCluster, namespa | |
configMap.Metadata.Labels.Name = metadataLabelName | ||
configMap.Metadata.Namespace = namespace | ||
configMap.Data.Config = config | ||
configMap.Data.Service = proto | ||
|
||
return configMap | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
syntax = "proto3"; | ||
|
||
{{ range . }} | ||
service {{ .Name }} { | ||
{{ range .Endpoints }} | ||
rpc {{ .Name }} (Request) returns (Response) {} | ||
{{ end }} | ||
} | ||
{{ end }} | ||
|
||
message Request { | ||
string data = 1; | ||
} | ||
|
||
message Response { | ||
string data = 1; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,23 +14,30 @@ | |
# limitations under the License. | ||
# | ||
|
||
FROM python:3.8.0-alpine | ||
FROM python:3.8.0-slim | ||
|
||
RUN mkdir -p /usr/src/app | ||
|
||
RUN apk update \ | ||
&& apk add jq \ | ||
&& rm -rf /var/cache/apk/* | ||
RUN apt update | ||
RUN apt install -y jq \ | ||
wget \ | ||
2to3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need a package for translation from python2 to python3? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In
So we need to add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe in the future we can fully update the code to python 3... |
||
|
||
WORKDIR /usr/src/app | ||
RUN ls | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this line needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope. I'll delete it. |
||
|
||
ADD ./requirements.txt /usr/src/app/requirements.txt | ||
|
||
RUN pip install --upgrade pip | ||
RUN pip install -r requirements.txt | ||
|
||
# download the grpc health probe | ||
RUN GRPC_HEALTH_PROBE_VERSION=v0.4.8 && \ | ||
wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \ | ||
chmod +x /bin/grpc_health_probe | ||
|
||
ENV CONF="/usr/src/app/config/conf.json" | ||
|
||
COPY . /usr/src/app | ||
|
||
#EXPOSE 5000 | ||
EXPOSE 5000 | ||
ENTRYPOINT ["/usr/src/app/run.sh"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
""" | ||
Copyright 2021 Ericsson AB | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
""" | ||
Copyright 2021 Ericsson AB | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any restriction with special symbols? I guess that's why you had to change their format...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, for Now I'd suggest to don't use any specific symbols like dashes or underline. We can add the support of these symbols in #25.