| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 |
- {{- if .Values.apps.enabled }}
- {{- range $key, $app := .Values.apps }}
- {{- $ignoredKeys := list "enabled" -}}
- {{- if and (not ($ignoredKeys | has $key)) $app.enabled }}
- {{/* Merge .Values.app into $app, giving precedence to the values defined on the app. */}}
- {{- $appValues := mustDeepCopy (mustMerge $app $.Values.app) -}}
- {{/* use shuffle.appRegistry as default image registry */}}
- {{- $_ := set $appValues.image "registry" ($appValues.image.registry | default $.Values.shuffle.appRegistry) -}}
- {{/* use shuffle.appBaseImageName as default image repository */}}
- {{- $_ := set $appValues.image "repository" ($appValues.image.repository | default (printf "%s/%s" $.Values.shuffle.appBaseImageName $appValues.name)) -}}
- {{/* use app version as default tag */}}
- {{- $_ := set $appValues.image "tag" ($appValues.image.tag | default $appValues.version) -}}
- {{/* Only create a service account if create is explicitly enabled on that specific app ($app not $appValues). Otherwise the shared shuffle-app service account is used. */}}
- {{- $shouldCreateDedicatedServiceAccount := and $app.serviceAccount.create $app.serviceAccount.name -}}
- {{- if $shouldCreateDedicatedServiceAccount }}
- ---
- apiVersion: v1
- kind: ServiceAccount
- metadata:
- name: {{ $app.serviceAccount.name | trunc 63 | trimSuffix "-" }}
- namespace: {{ include "common.names.namespace" $ | quote }}
- labels: {{- include "shuffle.app.labels" ( dict "customLabels" $.Values.commonLabels "context" $ ) | nindent 4 }}
- {{- if or $appValues.serviceAccount.annotations $.Values.commonAnnotations }}
- {{- $annotations := include "common.tplvalues.merge" (dict "values" (list $appValues.serviceAccount.annotations $.Values.commonAnnotations) "context" $) }}
- annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $ ) | nindent 4 }}
- {{- end }}
- automountServiceAccountToken: {{ $appValues.serviceAccount.automountServiceAccountToken }}
- {{- include "shuffle.app.serviceAccount.imagePullSecrets" $ | nindent 0 }}
- {{- if $appValues.rbac.create }}
- ---
- kind: RoleBinding
- apiVersion: {{ include "common.capabilities.rbac.apiVersion" $ }}
- metadata:
- name: {{ $app.serviceAccount.name | trunc 63 | trimSuffix "-" }}
- namespace: {{ include "common.names.namespace" $ | quote }}
- labels: {{- include "shuffle.app.labels" ( dict "customLabels" $.Values.commonLabels "context" $ ) | nindent 4 }}
- {{- if $.Values.commonAnnotations }}
- annotations: {{- include "common.tplvalues.render" ( dict "value" $.Values.commonAnnotations "context" $ ) | nindent 4 }}
- {{- end }}
- subjects:
- - kind: ServiceAccount
- name: {{ $app.serviceAccount.name | trunc 63 | trimSuffix "-" }}
- roleRef:
- apiGroup: rbac.authorization.k8s.io
- kind: Role
- name: {{ template "shuffle.app.name" $ }}
- {{- end }}
- {{- end }}
- ---
- apiVersion: v1
- kind: Service
- metadata:
- name: {{ include "shuffle.appInstance.fullname" $app }}
- namespace: {{ include "common.names.namespace" $ | quote }}
- {{- $serviceLabels := include "common.tplvalues.merge" (dict "values" (list $appValues.service.labels $.Values.commonLabels) "context" $) }}
- labels: {{- include "shuffle.appInstance.labels" ( dict "app" $app "customLabels" $serviceLabels "context" $ ) | nindent 4 }}
- {{- if $.Values.commonAnnotations }}
- annotations: {{- include "common.tplvalues.render" (dict "value" $.Values.commonAnnotations "context" $) | nindent 4 }}
- {{- end }}
- spec:
- type: ClusterIP
- ports:
- - name: http
- port: 80
- targetPort: {{ $appValues.exposedContainerPort }}
- protocol: TCP
- appProtocol: http
- {{- $podLabels := include "common.tplvalues.merge" (dict "values" (list $appValues.podLabels $.Values.commonLabels) "context" $) }}
- selector: {{- include "shuffle.appInstance.matchLabels" ( dict "app" $app "customLabels" $podLabels "context" $ ) | nindent 6 }}
- ---
- apiVersion: {{ include "common.capabilities.deployment.apiVersion" $ }}
- kind: Deployment
- metadata:
- name: {{ include "shuffle.appInstance.fullname" $app }}
- namespace: {{ include "common.names.namespace" $ | quote }}
- labels: {{- include "shuffle.appInstance.labels" ( dict "app" $app "customLabels" $.Values.commonLabels "context" $ ) | nindent 4 }}
- {{- if or $appValues.deploymentAnnotations $.Values.commonAnnotations }}
- {{- $annotations := include "common.tplvalues.merge" (dict "values" (list $appValues.deploymentAnnotations $.Values.commonAnnotations) "context" $) }}
- annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $ ) | nindent 4 }}
- {{- end }}
- spec:
- {{- if not $appValues.autoscaling.hpa.enabled }}
- replicas: {{ $appValues.replicaCount }}
- {{- end }}
- {{- if $appValues.updateStrategy }}
- strategy: {{- toYaml $appValues.updateStrategy | nindent 4 }}
- {{- end }}
- selector:
- matchLabels: {{- include "shuffle.appInstance.matchLabels" ( dict "app" $app "customLabels" $podLabels "context" $ ) | nindent 6 }}
- template:
- metadata:
- {{- if $appValues.podAnnotations }}
- annotations: {{- include "common.tplvalues.render" (dict "value" $appValues.podAnnotations "context" $) | nindent 8 }}
- {{- end }}
- labels: {{- include "shuffle.appInstance.labels" ( dict "app" $app "customLabels" $podLabels "context" $ ) | nindent 8 }}
- spec:
- {{- include "common.images.renderPullSecrets" (dict "images" (list $appValues.image) "context" $) | nindent 6 }}
- {{- if $appValues.serviceAccount.create }}
- serviceAccountName: {{ default (include "shuffle.app.name" $) $appValues.serviceAccount.name | trunc 63 | trimSuffix "-" }}
- {{- else }}
- serviceAccountName: {{ default "default" $appValues.serviceAccount.name }}
- {{- end }}
- automountServiceAccountToken: {{ $appValues.automountServiceAccountToken }}
- {{- if $appValues.hostAliases }}
- hostAliases: {{- include "common.tplvalues.render" (dict "value" $appValues.hostAliases "context" $) | nindent 8 }}
- {{- end }}
- {{- if $appValues.affinity }}
- affinity: {{- include "common.tplvalues.render" ( dict "value" $appValues.affinity "context" $) | nindent 8 }}
- {{- else }}
- affinity:
- podAffinity: {{- include "shuffle.appInstance.affinities.pods" (dict "app" $app "type" $appValues.podAffinityPreset "customLabels" $podLabels "context" $) | nindent 10 }}
- podAntiAffinity: {{- include "shuffle.appInstance.affinities.pods" (dict "app" $app "type" $appValues.podAntiAffinityPreset "customLabels" $podLabels "context" $) | nindent 10 }}
- nodeAffinity: {{- include "common.affinities.nodes" (dict "type" $appValues.nodeAffinityPreset.type "key" $appValues.nodeAffinityPreset.key "values" $appValues.nodeAffinityPreset.values) | nindent 10 }}
- {{- end }}
- {{- if $appValues.nodeSelector }}
- nodeSelector: {{- include "common.tplvalues.render" ( dict "value" $appValues.nodeSelector "context" $) | nindent 8 }}
- {{- end }}
- {{- if $appValues.tolerations }}
- tolerations: {{- include "common.tplvalues.render" (dict "value" $appValues.tolerations "context" $) | nindent 8 }}
- {{- end }}
- {{- if $appValues.priorityClassName }}
- priorityClassName: {{ $appValues.priorityClassName | quote }}
- {{- end }}
- {{- if $appValues.schedulerName }}
- schedulerName: {{ $appValues.schedulerName | quote }}
- {{- end }}
- {{- if $appValues.topologySpreadConstraints }}
- topologySpreadConstraints: {{- include "common.tplvalues.render" (dict "value" $appValues.topologySpreadConstraints "context" $) | nindent 8 }}
- {{- end }}
- {{- if $appValues.podSecurityContext.enabled }}
- securityContext: {{- omit $appValues.podSecurityContext "enabled" | toYaml | nindent 8 }}
- {{- end }}
- {{- if $appValues.terminationGracePeriodSeconds }}
- terminationGracePeriodSeconds: {{ $appValues.terminationGracePeriodSeconds }}
- {{- end }}
- initContainers:
- {{- if $appValues.initContainers }}
- {{- include "common.tplvalues.render" (dict "value" $appValues.initContainers "context" $) | nindent 8 }}
- {{- end }}
- containers:
- - name: {{ include "shuffle.appInstance.fullname" $app }}
- image: {{ include "common.images.image" ( dict "imageRoot" $appValues.image "global" $.Values.global "chart" $.Chart ) }}
- imagePullPolicy: {{ $appValues.image.pullPolicy }}
- {{- if $appValues.containerSecurityContext.enabled }}
- securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" $appValues.containerSecurityContext "context" $) | nindent 12 }}
- {{- end }}
- {{- if $.Values.diagnosticMode.enabled }}
- command: {{- include "common.tplvalues.render" (dict "value" $.Values.diagnosticMode.command "context" $) | nindent 12 }}
- {{- else if $appValues.command }}
- command: {{- include "common.tplvalues.render" (dict "value" $appValues.command "context" $) | nindent 12 }}
- {{- end }}
- {{- if $.Values.diagnosticMode.enabled }}
- args: {{- include "common.tplvalues.render" (dict "value" $.Values.diagnosticMode.args "context" $) | nindent 12 }}
- {{- else if $appValues.args }}
- args: {{- include "common.tplvalues.render" (dict "value" $appValues.args "context" $) | nindent 12 }}
- {{- end }}
- env:
- - name: AUTHORIZATION
- value: ""
- - name: EXECUTIONID
- value: ""
- - name: BASE_URL
- value: {{ include "shuffle.worker.baseUrl" $ | quote }}
- - name: CALLBACK_URL
- value: {{ include "shuffle.backend.baseUrl" $ | quote }}
- - name: SHUFFLE_SWARM_CONFIG
- value: run # Shuffle Worker requires this to be set even when using K8s instead of swarm
- {{- $env := include "shuffle.appInstance.env" $ | fromYaml }}
- {{- range $key, $val := $env }}
- - name: {{ $key | quote }}
- value: {{ $val | quote }}
- {{- end }}
- {{- if $appValues.extraEnvVars }}
- {{- include "common.tplvalues.render" (dict "value" $appValues.extraEnvVars "context" $) | nindent 12 }}
- {{- end }}
- envFrom:
- {{- if $appValues.extraEnvVarsCM }}
- - configMapRef:
- name: {{ include "common.tplvalues.render" (dict "value" $appValues.extraEnvVarsCM "context" $) }}
- {{- end }}
- {{- if $appValues.extraEnvVarsSecret }}
- - secretRef:
- name: {{ include "common.tplvalues.render" (dict "value" $appValues.extraEnvVarsSecret "context" $) }}
- {{- end }}
- {{- if $appValues.resources }}
- resources: {{- toYaml $appValues.resources | nindent 12 }}
- {{- else if ne $appValues.resourcesPreset "none" }}
- resources: {{- include "common.resources.preset" (dict "type" $appValues.resourcesPreset) | nindent 12 }}
- {{- end }}
- ports:
- - name: http
- containerPort: {{ $appValues.exposedContainerPort }}
- {{- if $appValues.extraContainerPorts }}
- {{- include "common.tplvalues.render" (dict "value" $appValues.extraContainerPorts "context" $) | nindent 12 }}
- {{- end }}
- {{- if not $.Values.diagnosticMode.enabled }}
- {{- if $appValues.customLivenessProbe }}
- livenessProbe: {{- include "common.tplvalues.render" (dict "value" $appValues.customLivenessProbe "context" $) | nindent 12 }}
- {{- else if $appValues.livenessProbe.enabled }}
- livenessProbe: {{- include "common.tplvalues.render" (dict "value" (omit $appValues.livenessProbe "enabled") "context" $) | nindent 12 }}
- httpGet:
- path: /api/v1/health
- port: {{ $appValues.containerPorts.http }}
- {{- end }}
- {{- if $appValues.customReadinessProbe }}
- readinessProbe: {{- include "common.tplvalues.render" (dict "value" $appValues.customReadinessProbe "context" $) | nindent 12 }}
- {{- else if $appValues.readinessProbe.enabled }}
- readinessProbe: {{- include "common.tplvalues.render" (dict "value" (omit $appValues.readinessProbe "enabled") "context" $) | nindent 12 }}
- httpGet:
- path: /api/v1/health
- port: {{ $appValues.containerPorts.http }}
- {{- end }}
- {{- if $appValues.customStartupProbe }}
- startupProbe: {{- include "common.tplvalues.render" (dict "value" $appValues.customStartupProbe "context" $) | nindent 12 }}
- {{- else if $appValues.startupProbe.enabled }}
- startupProbe: {{- include "common.tplvalues.render" (dict "value" (omit $appValues.startupProbe "enabled") "context" $) | nindent 12 }}
- httpGet:
- path: /api/v1/health
- port: {{ $appValues.containerPorts.http }}
- {{- end }}
- {{- end }}
- {{- if $appValues.lifecycleHooks }}
- lifecycle: {{- include "common.tplvalues.render" (dict "value" $appValues.lifecycleHooks "context" $) | nindent 12 }}
- {{- end }}
- volumeMounts:
- {{- if $appValues.mountTmpVolume }}
- - name: empty-dir
- mountPath: /tmp
- subPath: tmp-dir
- {{- end }}
- {{- if $appValues.extraVolumeMounts }}
- {{- include "common.tplvalues.render" (dict "value" $appValues.extraVolumeMounts "context" $) | nindent 12 }}
- {{- end }}
- {{- if $appValues.sidecars }}
- {{- include "common.tplvalues.render" ( dict "value" $appValues.sidecars "context" $) | nindent 8 }}
- {{- end }}
- volumes:
- - name: empty-dir
- emptyDir: {}
- {{- if $appValues.extraVolumes }}
- {{- include "common.tplvalues.render" (dict "value" $appValues.extraVolumes "context" $) | nindent 8 }}
- {{- end }}
- ---
- {{- if $appValues.pdb.create }}
- apiVersion: {{ include "common.capabilities.policy.apiVersion" $ }}
- kind: PodDisruptionBudget
- metadata:
- name: {{ include "shuffle.appInstance.fullname" $app }}
- namespace: {{ include "common.names.namespace" $ | quote }}
- labels: {{- include "shuffle.appInstance.labels" ( dict "app" $app "customLabels" $.Values.commonLabels "context" $ ) | nindent 4 }}
- {{- if $.Values.commonAnnotations }}
- annotations: {{- include "common.tplvalues.render" ( dict "value" $.Values.commonAnnotations "context" $ ) | nindent 4 }}
- {{- end }}
- spec:
- {{- if $appValues.pdb.minAvailable }}
- minAvailable: {{ $appValues.pdb.minAvailable }}
- {{- end }}
- {{- if or $appValues.pdb.maxUnavailable ( not $appValues.pdb.minAvailable ) }}
- maxUnavailable: {{ $appValues.pdb.maxUnavailable | default 1 }}
- {{- end }}
- selector:
- matchLabels: {{- include "shuffle.appInstance.matchLabels" ( dict "app" $app "customLabels" $podLabels "context" $ ) | nindent 6 }}
- {{- end }}
- ---
- {{- if $appValues.autoscaling.hpa.enabled }}
- apiVersion: {{ include "common.capabilities.hpa.apiVersion" $ }}
- kind: HorizontalPodAutoscaler
- metadata:
- name: {{ include "shuffle.appInstance.fullname" $app }}
- namespace: {{ include "common.names.namespace" $ | quote }}
- labels: {{- include "shuffle.appInstance.labels" ( dict "app" $app "customLabels" $.Values.commonLabels "context" $ ) | nindent 4 }}
- {{- if $.Values.commonAnnotations }}
- annotations: {{- include "common.tplvalues.render" ( dict "value" $.Values.commonAnnotations "context" $ ) | nindent 4 }}
- {{- end }}
- spec:
- scaleTargetRef:
- apiVersion: {{ include "common.capabilities.deployment.apiVersion" $ }}
- kind: Deployment
- name: {{ include "shuffle.appInstance.fullname" $app }}
- minReplicas: {{ $appValues.autoscaling.hpa.minReplicas }}
- maxReplicas: {{ $appValues.autoscaling.hpa.maxReplicas }}
- metrics:
- {{- if $appValues.autoscaling.hpa.targetMemory }}
- - type: Resource
- resource:
- name: memory
- {{- if semverCompare "<1.23-0" (include "common.capabilities.kubeVersion" $) }}
- targetAverageUtilization: {{ $appValues.autoscaling.hpa.targetMemory }}
- {{- else }}
- target:
- type: Utilization
- averageUtilization: {{ $appValues.autoscaling.hpa.targetMemory }}
- {{- end }}
- {{- end }}
- {{- if $appValues.autoscaling.hpa.targetCPU }}
- - type: Resource
- resource:
- name: cpu
- {{- if semverCompare "<1.23-0" (include "common.capabilities.kubeVersion" $) }}
- targetAverageUtilization: {{ $appValues.autoscaling.hpa.targetCPU }}
- {{- else }}
- target:
- type: Utilization
- averageUtilization: {{ $appValues.autoscaling.hpa.targetCPU }}
- {{- end }}
- {{- end }}
- {{- end }}
- ---
- {{- if and ($.Capabilities.APIVersions.Has "autoscaling.k8s.io/v1/VerticalPodAutoscaler") $appValues.autoscaling.vpa.enabled }}
- apiVersion: autoscaling.k8s.io/v1
- kind: VerticalPodAutoscaler
- metadata:
- name: {{ include "shuffle.appInstance.fullname" $app }}
- namespace: {{ include "common.names.namespace" $ | quote }}
- labels: {{- include "shuffle.appInstance.labels" ( dict "app" $app "customLabels" $.Values.commonLabels "context" $ ) | nindent 4 }}
- {{- if or $appValues.autoscaling.vpa.annotations $.Values.commonAnnotations }}
- {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list $appValues.autoscaling.vpa.annotations $.Values.commonAnnotations ) "context" $ ) }}
- annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }}
- {{- end }}
- spec:
- resourcePolicy:
- containerPolicies:
- - containerName: app
- {{- with $appValues.autoscaling.vpa.controlledResources }}
- controlledResources:
- {{- toYaml . | nindent 8 }}
- {{- end }}
- {{- with $appValues.autoscaling.vpa.maxAllowed }}
- maxAllowed:
- {{- toYaml . | nindent 8 }}
- {{- end }}
- {{- with $appValues.autoscaling.vpa.minAllowed }}
- minAllowed:
- {{- toYaml . | nindent 8 }}
- {{- end }}
- targetRef:
- apiVersion: {{ include "common.capabilities.deployment.apiVersion" $ }}
- kind: Deployment
- name: {{ include "shuffle.appInstance.fullname" $app }}
- {{- if $appValues.autoscaling.vpa.updatePolicy }}
- updatePolicy:
- {{- with $appValues.autoscaling.vpa.updatePolicy.updateMode }}
- updateMode: {{ . }}
- {{- end }}
- {{- end }}
- {{- end }}
- {{- end }}
- {{- end }}
- {{- end }}
|