33{{- $chart_labels := include "cronjobs.labels" . }}
44{{- $chart_selector_labels := include "cronjobs.selectorLabels" . }}
55{{- $service_account_name := include "cronjobs.serviceAccountName" . }}
6- {{- $registry := .Values.image.registry }}
7- {{- $tag := .Values.image.tag | default .Chart.AppVersion }}
8- {{- $image_pull_secrets := .Values.imagePullSecrets }}
9-
106{{- range $job_name, $job := .Values.jobs }}
11- {{- $image := print $registry "/" $.Values.image.repository ":" $tag }}
12- {{- if .image }}
13- {{- $image = print (default $registry .image.registry) "/" .image.repository ":" (default $tag .image.tag) }}
14- {{- end }}
15- {{- $env := $.Values.env }}
16- {{- if .env }}
17- {{- $env = concat $env .env }}
18- {{- end }}
7+ {{- $JOB_NAME_SLUG := include "com.klicktipp.slugify-volume-name" $job_name }}
8+ {{- $env := mergeOverwrite dict $.Values.env ($job.env | default dict) }}
199{{- $checksum := toYaml . | sha256sum | trunc 20 | quote }}
2010---
2111apiVersion : {{ $api_version }}
2212kind : CronJob
2313metadata :
24- name : {{ $chart_name }}-{{ $job_name }}
14+ name : {{ $chart_name }}-{{ $JOB_NAME_SLUG }}
2515 labels :
2616 {{- $chart_labels | nindent 4 }}
2717 annotations :
3121 failedJobsHistoryLimit : {{ default 1 .failedJobsHistoryLimit }}
3222 successfulJobsHistoryLimit : {{ default 1 .successfulJobsHistoryLimit }}
3323 schedule : {{ .schedule | quote }}
34- {{- if .suspend }}
35- suspend : {{ .suspend }}
36- {{- end }}
24+ suspend : {{ .suspend | default false }}
3725 {{- if .startingDeadlineSeconds }}
3826 startingDeadlineSeconds : {{ .startingDeadlineSeconds }}
3927 {{- end }}
@@ -66,23 +54,23 @@ spec:
6654 spec :
6755 restartPolicy : {{ default "Never" .restartPolicy }}
6856 imagePullSecrets :
69- {{- with default $image_pull_secrets . imagePullSecrets }}
57+ {{- with ($job.imagePullSecrets | default $.Values. imagePullSecrets) }}
7058 {{- toYaml . | nindent 12 }}
7159 {{- end }}
72- {{- if $.Values.dockerConfigJson }}
60+ {{- if $job.dockerConfigJson | default $ .Values.dockerConfigJson }}
7361 - name : {{ $chart_name }}-registry
7462 {{- end }}
7563 {{- if or $.Values.serviceAccount.create $.Values.serviceAccount.name }}
7664 serviceAccountName : {{ $service_account_name }}
7765 {{- end }}
7866 securityContext :
79- {{- toYaml $. Values.podSecurityContext | nindent 12 }}
67+ {{- toYaml ($job.podSecurityContext | default $. Values.podSecurityContext) | nindent 12 }}
8068 containers :
81- - name : {{ $job_name }}
69+ - name : job
8270 securityContext :
83- {{- toYaml $. Values.securityContext | nindent 16 }}
84- image : {{ $image }}
85- imagePullPolicy : {{ $.Values. image.pullPolicy }}
71+ {{- toYaml ($job.securityContext | default $. Values.securityContext) | nindent 16 }}
72+ image : " {{ $job. image.repository }}:{{ $job.image.tag | default $.Chart.AppVersion }} "
73+ imagePullPolicy : {{ $job. image.pullPolicy | default "IfNotPresent" }}
8674 {{- if .command }}
8775 command :
8876 {{- toYaml .command | nindent 16 }}
@@ -92,15 +80,33 @@ spec:
9280 {{- toYaml . | nindent 16 }}
9381 {{- end }}
9482 env :
95- {{- toYaml $env | nindent 16 }}
83+ {{- range $key, $value := $env}}
84+ - name : {{ $key }}
85+ value : {{ $value | quote }}
86+ {{- end }}
9687 resources :
97- {{- toYaml $.Values .resources | nindent 16 }}
88+ {{- toYaml $job .resources | nindent 16 }}
9889 volumeMounts :
99- {{- range .volumeMounts }}
100- {{- $PVC_NAME := include "kt.slugify-volume-name" (list $.Release.Name (coalesce .claimName .name)) }}
90+ {{- if and $job.storage (hasKey $job.storage "efs") (hasKey $job.storage.efs "mounts") }}
91+ {{- range $efs_mount := $job.storage.efs.mounts }}
92+ {{- range $efs_ap := $efs_mount.access_points }}
93+ {{- $EFS_AP_ID_TRIMMED := trimPrefix "fsap-" $efs_ap.id }}
94+ {{- $PVC_NAME := include "com.klicktipp.slugify-volume-name" (list $.Release.Name $JOB_NAME_SLUG (coalesce $efs_ap.name $efs_ap.path) $EFS_AP_ID_TRIMMED) }}
10195 - name : {{ $PVC_NAME }}
102- mountPath : {{ .mountPath }}
96+ mountPath : {{ required "ERROR: the EFS mount point requires a mount_dest." $efs_ap.mount_dest }}
97+ {{- end }} {{/* # end range $efs_ap */}}
98+ {{- end }} {{/* # end range $efs_mount */}}
99+ {{- end }} {{/* # end if storage.efs */}}
100+ {{- if and (hasKey $job "extraFiles") $job.extraFiles }}
101+ {{- range $filename, $file := $job.extraFiles }}
102+ {{- if $file.enabled }}
103+ - name : cronjob-files
104+ mountPath : ' {{ $file.mountPath }}'
105+ subPath : ' {{ $filename }}'
106+ readOnly : true
103107 {{- end }}
108+ {{- end }} {{/* # end range extraFiles */}}
109+ {{- end }} {{/* # end exists extraFiles */}}
104110 {{- if $.Values.customConfigMap }}
105111 - mountPath : /configMaps/{{ $.Values.customConfigMap }}
106112 name : {{ $.Values.customConfigMap }}
@@ -113,25 +119,43 @@ spec:
113119 - mountPath : /secrets/{{ $job_name }}
114120 name : {{ $job_name }}
115121 {{- end }}
116- {{- with $.Values.nodeSelector }}
122+ {{- with $job.nodeSelector | default $ .Values.nodeSelector }}
117123 nodeSelector :
118124 {{- toYaml . | nindent 12 }}
119125 {{- end }}
120- {{- with $.Values.affinity }}
126+ {{- with $job.affinity | default $ .Values.affinity }}
121127 affinity :
122128 {{- toYaml . | nindent 12 }}
123129 {{- end }}
124- {{- with $.Values.tolerations }}
130+ {{- with $job.tolerations | default $ .Values.tolerations }}
125131 tolerations :
126132 {{- toYaml . | nindent 12 }}
127133 {{- end }}
128134 volumes :
129- {{- range .volumes }}
130- {{- $PVC_NAME := include "kt.slugify-volume-name" (list $.Release.Name (coalesce .claimName .name)) }}
135+ {{- if and $job.storage (hasKey $job.storage "efs") (hasKey $job.storage.efs "mounts") }}
136+ {{- range $efs_mount := $job.storage.efs.mounts }}
137+ {{- range $efs_ap := $efs_mount.access_points }}
138+ {{- $EFS_AP_ID_TRIMMED := trimPrefix "fsap-" $efs_ap.id }}
139+ {{- $PVC_NAME := include "com.klicktipp.slugify-volume-name" (list $.Release.Name $JOB_NAME_SLUG (coalesce $efs_ap.name $efs_ap.path) $EFS_AP_ID_TRIMMED) }}
131140 - name : {{ $PVC_NAME }}
132141 persistentVolumeClaim :
133142 claimName : {{ $PVC_NAME }}
134- {{- end }}
143+ {{- end }} {{/* # end range $efs_ap */}}
144+ {{- end }} {{/* # end range $efs_mount */}}
145+ {{- end }} {{/* # end if storage.efs */}}
146+ {{- if and (hasKey $job "extraFiles") $job.extraFiles }}
147+ - name : cronjob-files
148+ configMap :
149+ name : {{ include "com.klicktipp.slugify-volume-name" (list $chart_name "files" $JOB_NAME_SLUG) }}
150+ items :
151+ {{- range $filename, $file := $job.extraFiles }}
152+ {{- if $file.enabled }}
153+ - key : ' {{ $filename }}'
154+ path : ' {{ $filename }}'
155+ mode : {{ ($file.mode | default "0644") | toDecimal }}
156+ {{- end }}
157+ {{- end }} {{/* # end range extraFiles */}}
158+ {{- end }} {{/* # end exists extraFiles */}}
135159 {{- if $.Values.customConfigMap }}
136160 - name : {{ $.Values.customConfigMap }}
137161 configMap :
@@ -142,7 +166,7 @@ spec:
142166 configMap :
143167 name : {{ print $chart_name "-" $job_name }}
144168 {{- end }}
145- {{- range $job_name, $secret := $.Values.secrets }}
169+ {{- range $job_name, $secret := $job.secrets | default $ .Values.secrets }}
146170 - name : {{ $job_name }}
147171 secret :
148172 secretName : {{ print $chart_name "-" $job_name }}
0 commit comments