diff --git a/chart-tests/application/ci/test-cronjob-values.yaml b/chart-tests/application/ci/test-cronjob-values.yaml new file mode 100644 index 0000000..25e2dc4 --- /dev/null +++ b/chart-tests/application/ci/test-cronjob-values.yaml @@ -0,0 +1,16 @@ +cronJob: + enabled: true + schedule: "* * * * *" + successfulJobsHistoryLimit: 3 + failedJobsHistoryLimit: 1 + concurrencyPolicy: Forbid + activeDeadlineSeconds: 60 + ttlSecondsAfterFinished: 86400 + startingDeadlineSeconds: 200 + +image: + repository: busybox + tag: stable + +container: + command: ["ls"] diff --git a/chart-tests/application/ci/test-init-container-values.yaml b/chart-tests/application/ci/test-init-container-values.yaml index 8c56cd3..66fd930 100644 --- a/chart-tests/application/ci/test-init-container-values.yaml +++ b/chart-tests/application/ci/test-init-container-values.yaml @@ -31,7 +31,6 @@ initContainers: tag: 9.3 command: ['ls', '-lah', '/'] env: {} - restartPolicy: Never initDefaults: diff --git a/charts/application/Chart.yaml b/charts/application/Chart.yaml index 0c5de96..0854028 100644 --- a/charts/application/Chart.yaml +++ b/charts/application/Chart.yaml @@ -7,4 +7,4 @@ maintainers: - name: MediaMarktSaturn url: https://github.com/MediaMarktSaturn appVersion: 1.0.0 -version: 1.30.0 +version: 1.31.0 diff --git a/charts/application/templates/_podTemplate.tpl b/charts/application/templates/_podTemplate.tpl index e268f62..0d13c12 100644 --- a/charts/application/templates/_podTemplate.tpl +++ b/charts/application/templates/_podTemplate.tpl @@ -87,6 +87,9 @@ spec: name: {{ $ie }} {{- end }} {{- end }} + {{- if $i.restartPolicy }} + restartPolicy: {{ $i.restartPolicy }} + {{- end }} {{ $hasInitVolumeMount := 0 }} {{ range $.Values.volumeMounts }}{{ if (has .name $i.volumeMountNames) }}{{ $hasInitVolumeMount = 1 }}{{ end }}{{ end }} volumeMounts: {{ if not (or $i.secretVolumes (and $.Values.volumeMounts $hasInitVolumeMount)) -}}[]{{- end -}} @@ -445,6 +448,9 @@ spec: {{- end }} {{- end }} {{- end }} + {{- if or .Values.podRestartPolicy .Values.cronJob.enabled }} + restartPolicy: {{ default "OnFailure" .Values.podRestartPolicy }} + {{- end }} {{- if .Values.tolerations }} tolerations: {{- toYaml .Values.tolerations | nindent 4 }} diff --git a/charts/application/templates/k8s-cron-job.yaml b/charts/application/templates/k8s-cron-job.yaml new file mode 100644 index 0000000..283cc52 --- /dev/null +++ b/charts/application/templates/k8s-cron-job.yaml @@ -0,0 +1,24 @@ +{{- if .Values.cronJob.enabled }} +apiVersion: batch/v1 +kind: CronJob +metadata: + name: {{ .Release.Name }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "labels" . | nindent 4 }} + annotations: + release/time: {{ date "2006-01-02T15:04:05Z07:00" now }} + release/revision: {{ .Release.Revision | quote }} +spec: + schedule: {{ .Values.cronJob.schedule | quote }} + concurrencyPolicy: {{ .Values.cronJob.concurrencyPolicy }} + startingDeadlineSeconds: {{ .Values.cronJob.startingDeadlineSeconds }} + successfulJobsHistoryLimit: {{ .Values.cronJob.successfulJobsHistoryLimit }} + failedJobsHistoryLimit: {{ .Values.cronJob.failedJobsHistoryLimit }} + jobTemplate: + spec: + ttlSecondsAfterFinished: {{ .Values.cronJob.ttlSecondsAfterFinished }} + activeDeadlineSeconds: {{ .Values.cronJob.activeDeadlineSeconds }} + template: + {{- include "podTemplate" . | nindent 8 }} +{{- end }} diff --git a/charts/application/templates/k8s-deployment.yaml b/charts/application/templates/k8s-deployment.yaml index f9deed3..0631421 100644 --- a/charts/application/templates/k8s-deployment.yaml +++ b/charts/application/templates/k8s-deployment.yaml @@ -1,4 +1,4 @@ -{{- if not .Values.statefulSet.enabled }} +{{- if not (or .Values.statefulSet.enabled .Values.cronJob.enabled)}} apiVersion: apps/v1 kind: Deployment metadata: diff --git a/charts/application/templates/k8s-pod-disruption-budget.yaml b/charts/application/templates/k8s-pod-disruption-budget.yaml index 850ce3d..3e407e4 100644 --- a/charts/application/templates/k8s-pod-disruption-budget.yaml +++ b/charts/application/templates/k8s-pod-disruption-budget.yaml @@ -1,4 +1,4 @@ -{{- if or .Values.disruptionBudget.minAvailable .Values.disruptionBudget.maxUnavailable }} +{{- if and (or .Values.disruptionBudget.minAvailable .Values.disruptionBudget.maxUnavailable) (not .Values.cronJob.enabled) }} apiVersion: policy/v1 kind: PodDisruptionBudget metadata: diff --git a/charts/application/templates/k8s-service.yaml b/charts/application/templates/k8s-service.yaml index 6178b80..3e2a23b 100644 --- a/charts/application/templates/k8s-service.yaml +++ b/charts/application/templates/k8s-service.yaml @@ -1,4 +1,4 @@ -{{- if and .Values.service.enabled (not (and .Values.canary.enabled .Values.istio.enabled)) }} +{{- if and .Values.service.enabled (not (and .Values.canary.enabled .Values.istio.enabled)) (not .Values.cronJob.enabled) }} apiVersion: v1 kind: Service metadata: diff --git a/charts/application/values.yaml b/charts/application/values.yaml index 6040c76..c7c344b 100644 --- a/charts/application/values.yaml +++ b/charts/application/values.yaml @@ -5,6 +5,19 @@ statefulSet: # The policy for how pods inside the statefulSet are handled: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#pod-management-policies podManagementPolicy: OrderedReady +cronJob: + enabled: false + schedule: "" + successfulJobsHistoryLimit: 3 + failedJobsHistoryLimit: 1 + concurrencyPolicy: Forbid + activeDeadlineSeconds: 60 + ttlSecondsAfterFinished: 86400 + startingDeadlineSeconds: 200 + +# Defaulting to onFailure for cronJobs only: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy +podRestartPolicy: + container: port: 8080 securityContext: @@ -412,6 +425,7 @@ initContainers: [] # # see initDefaults # resources: {} # securityContext: {} +# restartPolicy: # # 'volumeMounts' names to be mounted in init container as well (under the same path); default: none # volumeMountNames: [] # # - data @@ -427,7 +441,6 @@ initDefaults: limits: cpu: 500m memory: 100Mi - restartPolicy: Always # securityContext: {} # List of tolerations, will be taken over like-for-like to pod-spec