Skip to content
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

VRP solver & task-manager #595

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions charts/navi-vrp-solver/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
19 changes: 19 additions & 0 deletions charts/navi-vrp-solver/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v2
name: navi-vrp-solver
description: Navi VRP Solver helm chart for Kubernetes
type: application
keywords:
- navi
- vrp
- tsp
- solver
version: 1.34.0
appVersion: 1.12.0
dependencies:
- name: generic-chart
version: '*'
repository: file://../generic-chart
maintainers:
- name: 2gis
url: https://github.com/2gis
email: [email protected]
161 changes: 161 additions & 0 deletions charts/navi-vrp-solver/README.md

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions charts/navi-vrp-solver/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "generic-chart.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "generic-chart.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "generic-chart.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "generic-chart.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
98 changes: 98 additions & 0 deletions charts/navi-vrp-solver/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{{- /*
Collect merged Kafka properties from these dictionaries:
- kafka.properties: this is a simple key/value dictionary
- kafka.fileProperties: this is a key/content dictionary given in values,
content is sensitive and stored in Secret resource, they get
mounted as files sonamed after key. While actual secret values are
hidden this way, what actually goes here in environment properties is
file names. This value substitution is implemented down here.
*/ -}}

{{- /* Merge .kafka.properties and .kafka.fileProperties dictionaries.

Context:
.kafka.properties
.kafka.fileProperties
.overrides.properties
.overrides.fileProperties
.mountpoint

File properties values (file contents) replaced with keys (file names).
File names prepended with the supposed directory from .mountpoint.
overrides.* are merged with kafka.* accordingly.

Returns {"ret": that-merged-dict}.
Folding result in "ret" needed for marshalling.
*/ -}}
{{- define "navi-vrp-solver.kafkaProperties" -}}
{{- $ctx := . -}}
{{- $kafkaProperties := dict -}}
{{- $fileProperties := deepCopy $ctx.kafka.fileProperties | mustMerge (($ctx.overrides).fileProperties | default dict) -}}
{{- range $key, $_ := $fileProperties -}}
{{- $_ := set $kafkaProperties $key (printf "%s/%s" $ctx.mountpoint $key) -}}
{{- end -}}
{{- $regularProperties := deepCopy $ctx.kafka.properties | mustMerge (($ctx.overrides).properties | default dict) -}}
{{- $kafkaProperties = deepCopy $regularProperties | mustMerge $kafkaProperties -}}
{{- dict "ret" $kafkaProperties | toYaml }}
{{- end }}

{{- /* Translate properties into `env` construction as in containers:

Context:
.kafka.properties
.kafka.fileProperties
.kafka.sensitiveProperties
.overrides.properties
.overrides.fileProperties
.overrides.sensitiveProperties
.mountpoint
.secretname
.prefix

.kafka.properties and .kafka.fileProperties merged with kafkaProperties (defined above)
each entry translated into {"name":..., "value":...}
where name is in form <PREFIX><PROPERTY_NAME>
prefix is from .prefix
property name with '.' replaced with '_' and in upper-case
e.g.:
prefix=PRODUCER_CONFIG_
property-name=security.protocol
result: PRODUCER_CONFIG_SECURITY_PROTOCOL
merged with .sensitiveProperties where entries are in format:
{ "name": ...,
"valueFrom": {
"secretKeyRef": {
"name": ...,
"key": ...
}
}
}
where secretKeyRef.name is from .secretname
overrides.* are merged with kafka.* accordingly.

Resulting object folded in {"ret":...} for marshalling.
*/ -}}
{{- define "navi-vrp-solver.kafkaPropertiesEnv" -}}
{{- $ctx := . -}}
{{- $kafkaProperties := get (fromYaml (include "navi-vrp-solver.kafkaProperties" $ctx)) "ret" -}}
{{- $env := list -}}
{{- range $prop, $val := $kafkaProperties -}}
{{- $env = append $env (dict
"name" (print $ctx.prefix ($prop | upper | replace "." "_"))
"value" $val
) -}}
{{- end -}}
{{- $sensitiveProperties := deepCopy $ctx.kafka.sensitiveProperties | mustMerge (($ctx.overrides).sensitiveProperties | default dict) -}}
{{- range $prop, $val := $sensitiveProperties -}}
{{- $env = append $env (dict
"name" (print $ctx.prefix ($prop | upper | replace "." "_"))
"valueFrom" (dict
"secretKeyRef" (dict
"name" $ctx.secretname
"key" $prop
)
)
) -}}
{{- end -}}
{{- dict "ret" $env | toYaml }}
{{- end }}
155 changes: 155 additions & 0 deletions charts/navi-vrp-solver/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "generic-chart.fullname" . }}
labels:
{{- include "generic-chart.labels" . | nindent 4 }}
{{- with .Values.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if not .Values.hpa.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
revisionHistoryLimit: {{ .Values.revisionHistoryLimit }}
{{- if .Values.strategy }}
strategy:
{{- include "tplvalues.render" ( dict "value" .Values.strategy "context" $) | nindent 6 }}
{{- end }}
selector:
matchLabels:
{{- include "generic-chart.selectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
checksum/config: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "generic-chart.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "generic-chart.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
volumes:
{{- $kafkaVolumeMounted := (
.Values.kafka.fileProperties |
or (.Values.kafka.consumerOverrides).fileProperties |
or (.Values.kafka.producerOverrides).fileProperties
) }}
{{- if $kafkaVolumeMounted }}
- name: {{ printf "%s-consumer" (include "generic-chart.fullname" .) | quote }}
secret:
secretName: {{ printf "%s-consumer" (include "generic-chart.fullname" .) | quote }}
- name: {{ printf "%s-producer" (include "generic-chart.fullname" .) | quote }}
secret:
secretName: {{ printf "%s-producer" (include "generic-chart.fullname" .) | quote }}
{{- end }}
containers:
- name: {{ include "generic-chart.containerName" . }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ required "A valid .Values.dgctlDockerRegistry entry required" .Values.dgctlDockerRegistry }}/{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.vrpSolver.appPort }}
protocol: TCP
readinessProbe:
httpGet:
path: /healthcheck
port: http
initialDelaySeconds: 30
periodSeconds: 5
successThreshold: 1
timeoutSeconds: 3
failureThreshold: 2
livenessProbe:
httpGet:
path: /healthcheck
port: http
initialDelaySeconds: 45
periodSeconds: 5
successThreshold: 1
timeoutSeconds: 3
failureThreshold: 5
volumeMounts:
{{- if $kafkaVolumeMounted }}
- name: {{ printf "%s-consumer" (include "generic-chart.fullname" .) | quote }}
mountPath: /etc/2gis/secret/consumer/
- name: {{ printf "%s-producer" (include "generic-chart.fullname" .) | quote }}
mountPath: /etc/2gis/secret/producer/
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
envFrom:
- secretRef:
name: {{ include "generic-chart.fullname" . }}-secret-env
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: LOG_LEVEL
value: "{{ .Values.vrpSolver.logLevel }}"
- name: LOG_SERIALIZE
value: "{{ .Values.vrpSolver.logSerialize }}"
- name: STORAGE__S3_ENDPOINT_URL
value: "{{ .Values.s3.url }}"
- name: STORAGE__S3_PUBLIC_URL
value: "{{ .Values.s3.publicUrl }}"
- name: STORAGE__TYPE
value: "S3_STORAGE"
- name: VROOM__CPU
value: "{{ .Values.vrpSolver.cpu }}"
- name: STORAGE__VRP__BUCKET
value: "{{ .Values.s3.vrp.bucket }}"
- name: STORAGE__DM__BUCKET
value: "{{ .Values.s3.dm.bucket }}"
- name: MOSES__URL
value: "{{ .Values.naviBack.url }}"
- name: KAFKA__PRODUCER__TOPIC
value: "{{ .Values.kafka.statusTopic }}"
- name: KAFKA__CONSUMER__TOPIC
value: "{{ .Values.kafka.taskTopic }}"
- name: KAFKA__CONSUMER__CONFIG__GROUP_ID
value: "{{ .Values.kafka.groupId }}"
{{- range $kafkaRole, $overridesProperty := (dict
"PRODUCER" "producerOverrides"
"CONSUMER" "consumerOverrides"
) -}}
{{- $kafkaPropertyEnv := print "KAFKA__" $kafkaRole "__CONFIG__" -}}
{{- $kafkaPropertiesEnv := include "navi-vrp-solver.kafkaPropertiesEnv" (dict
"kafka" $.Values.kafka
"overrides" ($overridesProperty | get $.Values.kafka)
"secretname" (print
(include "generic-chart.fullname" $)
"-"
(lower $kafkaRole)
)
"mountpoint" (print "/etc/2gis/secret/" (lower $kafkaRole))
"prefix" $kafkaPropertyEnv
) | fromYaml }}
{{- get $kafkaPropertiesEnv "ret" | toYaml | nindent 12 }}
{{- end }}{{- /* range */}}
lifecycle:
# wait for the endpoint removal process
preStop:
exec:
command: ["/bin/sh", "-c", "sleep {{ .Values.preStopDelay | default 5 | int }}"]
terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds | default 60 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
affinity:
{{- include "tplvalues.render" ( dict "value" .Values.affinity "context" $) | nindent 8 }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
1 change: 1 addition & 0 deletions charts/navi-vrp-solver/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{- template "generic-chart.hpa.tpl" . }}
61 changes: 61 additions & 0 deletions charts/navi-vrp-solver/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "generic-chart.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
{{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}}
{{- end }}
{{- end }}
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1
{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "generic-chart.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
ingressClassName: {{ .Values.ingress.className }}
{{- end }}
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
{{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}
pathType: {{ .pathType }}
{{- end }}
backend:
{{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
service:
name: {{ $fullName }}
port:
number: {{ $svcPort }}
{{- else }}
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
1 change: 1 addition & 0 deletions charts/navi-vrp-solver/templates/pdb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{- template "generic-chart.pdb.tpl" . }}
Loading