softplayer-helm-lib/charts/workload/templates/deployment/_containers.tpl

140 lines
5.7 KiB
Smarty
Raw Normal View History

2024-05-19 16:56:41 +00:00
{{- define "helper.deployment.containers" -}} {{- /* (define) */ -}}
{{- if not .Values.workload.containers -}} {{- /* (1) */ -}}
{{ fail ".Values.workload.containers can not be empty (heler.deployment.containers)" }}
{{- end -}} {{- /* /(1) */ -}}
containers:
2024-05-26 11:02:04 +00:00
{{- range $k, $v := .Values.workload.containers }} {{- /* (1) */}}
{{ include "helper.deployment.container" (dict "Context" $ "ContainerName" $k "ContainerData" $v) | indent 2}}
2024-05-19 16:56:41 +00:00
{{- end }} {{- /* /(1) */}}
{{- end -}} {{- /* /(define) */ -}}
{{- define "helper.deployment.initContainers" -}} {{- /* (define) */ -}}
{{- if .Values.workload.initContainers -}} {{- /* (1) */ -}}
initContainers:
{{- range $k,$v := .Values.workload.initContainers }} {{- /* (2) */}}
2024-05-26 11:02:04 +00:00
{{ include "helper.deployment.container" (dict "Context" $ "ContainerName" $k "ContainerData" $v) | indent 2}}
2024-05-19 16:56:41 +00:00
{{- end }} {{- /* /(1) */}}
{{- end -}} {{- /* /(2) */ -}}
{{- end -}} {{- /* /(define) */ -}}
{{- define "helper.deployment.container" -}} {{- /* (define) */ -}}
2024-05-26 11:02:04 +00:00
- name: {{ .ContainerName }}
{{- include "helper.workload.containerSecurityContext" .ContainerData | nindent 2 -}}
{{- include "helper.workload.image" (dict "Chart" .Context.Chart "Image" .ContainerData.image) | indent 2 -}}
{{- include "helper.container.command" .ContainerData | nindent 2 -}}
{{- include "helper.container.args" .ContainerData | nindent 2 -}}
{{- include "helper.container.ports" (dict "Context" .Context "Container" .ContainerData) | nindent 2 -}}
{{- include "helper.container.volumeMounts" .ContainerData | nindent 2 -}}
{{- include "helper.container.envFrom" (dict "Context" .Context "Container" .ContainerData) | nindent 2 -}}
{{- include "helper.container.livenessProbe" .ContainerData | nindent 2 -}}
{{- include "helper.container.readinessProbe" .ContainerData | nindent 2 -}}
{{- include "helper.container.startupProbe" .ContainerData | nindent 2 -}}
2024-05-19 16:56:41 +00:00
{{- end -}} {{- /* /(define) */ -}}
{{- define "helper.container.command" -}} {{- /* (define) */ -}}
{{- with .command }} {{- /* (1) */ -}}
command:
{{ . | toYaml | indent 2 }}
{{- end -}} {{- /* /(1) */ -}}
{{- end -}} {{- /* /(define) */ -}}
{{- define "helper.container.args" -}} {{- /* (define) */ -}}
{{- with .args }} {{- /* (1) */ -}}
args:
{{ . | toYaml | indent 2 }}
{{- end -}} {{- /* /(1) */ -}}
{{- end -}} {{- /* /(define) */ -}}
{{- define "helper.container.ports" -}} {{- /* (define) */ -}}
{{- if .Container.ports -}} {{- /* (1) */ -}}
ports:
{{- range $p := .Container.ports -}} {{- /* (2) */ -}}
{{- if kindIs "string" $p }} {{- /* (3) */}}
- containerPort: {{ index (index $.Context.Values.service.ports $p) "targetPort" }}
protocol: {{ index (index $.Context.Values.service.ports $p) "protocol" }}
{{- else }}
{{ print "-" | indent 2 | -}}
{{ $p | toYaml | nindent 4 -}}
{{- end -}} {{- /* /(3) */ -}}
{{- end -}} {{- /* /(2) */ -}}
{{- end -}} {{- /* /(1) */ -}}
{{- end -}} {{- /* /(define) */ -}}
{{- define "helper.container.volumeMounts" -}} {{- /* (define) */ -}}
{{- if .mounts -}} {{- /* (1) */ -}}
volumeMounts:
{{- range $mountKind, $mountData := .mounts }} {{- /* (2) */}}
{{- if eq $mountKind "storage" }} {{- /* (3) */}}
{{- range $mountName, $mountEntry := $mountData }} {{- /* (4) */}}
- name: {{ printf "%s-storage" $mountName }}
mountPath: {{ $mountEntry.path }}
{{- end }} {{- /* /(4) */}}
{{- end }} {{- /* /(3) */}}
{{- if eq $mountKind "files" }} {{- /* (3) */}}
{{- range $mountName, $mountEntry := $mountData }} {{- /* (4) */}}
- name: {{ printf "%s-file" $mountName }}
mountPath: {{ $mountEntry.path }}
2024-05-21 08:05:36 +00:00
{{- if $mountEntry.subPath }} {{- /* (5) */}}
2024-05-21 08:09:11 +00:00
subPath: {{ $mountEntry.subPath }}
2024-05-21 08:05:36 +00:00
{{- end }} {{- /* /(5) */}}
2024-05-19 16:56:41 +00:00
{{- end }} {{- /* /(4) */}}
{{- end }} {{- /* /(3) */}}
{{- if eq $mountKind "extraVolumes" }} {{- /* (3) */}}
{{- range $mountName, $mountEntry := $mountData }} {{- /* (4) */}}
- name: {{ printf "%s-extra" $mountName }}
mountPath: {{ $mountEntry.path }}
{{- end }} {{- /* /(4) */}}
{{- end }} {{- /* /(3) */}}
{{- end }} {{- /* /(2) */}}
{{- end }} {{- /* /(1) */}}
{{- end -}} {{- /* /(define) */ -}}
{{- define "helper.container.envFrom" -}} {{- /* (define) */ -}}
{{/* If env should be set from a Configmap/Secret */}}
{{- if .Container.envFrom }} {{- /* (1) */}}
envFrom:
{{- range $k := .Container.envFrom -}} {{- /* (2) */ -}}
{{/* If envFrom entry is a string, then refer to the env created by the library */}}
{{- if kindIs "string" $k -}} {{- /* (3) */ -}}
{{- if (index $.Context.Values.env $k) -}} {{- /* (4) */ -}}
{{- if (index $.Context.Values.env $k).sensitive }} {{- /* (5) */}}
- secretRef:
{{- else }}
- configMapRef:
{{- end }} {{- /* /(5) */}}
2024-05-21 07:39:06 +00:00
name: {{- printf " %s-%s" (include "chart.fullname" $.Context) $k -}}
2024-05-19 16:56:41 +00:00
{{- end -}} {{- /* /(4) */}}
{{- /* Otherwise try to add references directly (if Secrets/ConfigMaps are not managed by the chart) */ -}}
{{- else -}}
{{- range $k, $v := $k }} {{- /* (5) */}}
- {{ $k }}:
{{ toYaml $v | indent 14 }}
{{- end -}} {{- /* /(4) */ -}}
{{- end -}} {{- /* /(3) */ -}}
{{- end -}} {{- /* /(2) */ -}}
{{- end -}} {{- /* /(1) */ -}}
{{- end -}} {{- /* /(define) */ -}}
2024-05-26 11:02:04 +00:00
{{- /* Probes */ -}}
{{- define "helper.container.readinessProbe" -}} {{- /* (define) */ -}}
{{- if .readinessProbe }} {{- /* (1) */}}
readinessProbe:
{{ .readinessProbe | toYaml | indent 2 }}
{{- end }} {{- /* /(0) */}}
{{- end -}} {{- /* /(define) */ -}}
{{- define "helper.container.livenessProbe" -}} {{- /* (define) */ -}}
{{- if .livenessProbe }} {{- /* (1) */}}
livenessProbe:
{{ .livenessProbe | toYaml | indent 2 }}
{{- end }} {{- /* /(0) */}}
{{- end -}} {{- /* /(define) */ -}}
{{- define "helper.container.startupProbe" -}} {{- /* (define) */ -}}
{{- if .startupProbe }} {{- /* (1) */}}
startupProbe:
{{ .startupProbe | toYaml | indent 2 }}
{{- end }} {{- /* /(0) */}}
{{- end -}} {{- /* /(define) */ -}}