Skip to content

Commit 5569e12

Browse files
authored
Merge pull request #173 from MediaMarktSaturn/knabben-applicationcronjob
feat(application) add CronJob capability
2 parents bf04705 + ef47bb3 commit 5569e12

9 files changed

+64
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cronJob:
2+
enabled: true
3+
schedule: "* * * * *"
4+
successfulJobsHistoryLimit: 3
5+
failedJobsHistoryLimit: 1
6+
concurrencyPolicy: Forbid
7+
activeDeadlineSeconds: 60
8+
ttlSecondsAfterFinished: 86400
9+
startingDeadlineSeconds: 200
10+
11+
image:
12+
repository: busybox
13+
tag: stable
14+
15+
container:
16+
command: ["ls"]

chart-tests/application/ci/test-init-container-values.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ initContainers:
3131
tag: 9.3
3232
command: ['ls', '-lah', '/']
3333
env: {}
34-
restartPolicy: Never
3534

3635

3736
initDefaults:

charts/application/Chart.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ maintainers:
77
- name: MediaMarktSaturn
88
url: https://github.com/MediaMarktSaturn
99
appVersion: 1.0.0
10-
version: 1.30.0
10+
version: 1.31.0

charts/application/templates/_podTemplate.tpl

+6
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ spec:
8787
name: {{ $ie }}
8888
{{- end }}
8989
{{- end }}
90+
{{- if $i.restartPolicy }}
91+
restartPolicy: {{ $i.restartPolicy }}
92+
{{- end }}
9093
{{ $hasInitVolumeMount := 0 }}
9194
{{ range $.Values.volumeMounts }}{{ if (has .name $i.volumeMountNames) }}{{ $hasInitVolumeMount = 1 }}{{ end }}{{ end }}
9295
volumeMounts: {{ if not (or $i.secretVolumes (and $.Values.volumeMounts $hasInitVolumeMount)) -}}[]{{- end -}}
@@ -445,6 +448,9 @@ spec:
445448
{{- end }}
446449
{{- end }}
447450
{{- end }}
451+
{{- if or .Values.podRestartPolicy .Values.cronJob.enabled }}
452+
restartPolicy: {{ default "OnFailure" .Values.podRestartPolicy }}
453+
{{- end }}
448454
{{- if .Values.tolerations }}
449455
tolerations:
450456
{{- toYaml .Values.tolerations | nindent 4 }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{{- if .Values.cronJob.enabled }}
2+
apiVersion: batch/v1
3+
kind: CronJob
4+
metadata:
5+
name: {{ .Release.Name }}
6+
namespace: {{ .Release.Namespace }}
7+
labels:
8+
{{- include "labels" . | nindent 4 }}
9+
annotations:
10+
release/time: {{ date "2006-01-02T15:04:05Z07:00" now }}
11+
release/revision: {{ .Release.Revision | quote }}
12+
spec:
13+
schedule: {{ .Values.cronJob.schedule | quote }}
14+
concurrencyPolicy: {{ .Values.cronJob.concurrencyPolicy }}
15+
startingDeadlineSeconds: {{ .Values.cronJob.startingDeadlineSeconds }}
16+
successfulJobsHistoryLimit: {{ .Values.cronJob.successfulJobsHistoryLimit }}
17+
failedJobsHistoryLimit: {{ .Values.cronJob.failedJobsHistoryLimit }}
18+
jobTemplate:
19+
spec:
20+
ttlSecondsAfterFinished: {{ .Values.cronJob.ttlSecondsAfterFinished }}
21+
activeDeadlineSeconds: {{ .Values.cronJob.activeDeadlineSeconds }}
22+
template:
23+
{{- include "podTemplate" . | nindent 8 }}
24+
{{- end }}

charts/application/templates/k8s-deployment.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if not .Values.statefulSet.enabled }}
1+
{{- if not (or .Values.statefulSet.enabled .Values.cronJob.enabled)}}
22
apiVersion: apps/v1
33
kind: Deployment
44
metadata:

charts/application/templates/k8s-pod-disruption-budget.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if or .Values.disruptionBudget.minAvailable .Values.disruptionBudget.maxUnavailable }}
1+
{{- if and (or .Values.disruptionBudget.minAvailable .Values.disruptionBudget.maxUnavailable) (not .Values.cronJob.enabled) }}
22
apiVersion: policy/v1
33
kind: PodDisruptionBudget
44
metadata:

charts/application/templates/k8s-service.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if and .Values.service.enabled (not (and .Values.canary.enabled .Values.istio.enabled)) }}
1+
{{- if and .Values.service.enabled (not (and .Values.canary.enabled .Values.istio.enabled)) (not .Values.cronJob.enabled) }}
22
apiVersion: v1
33
kind: Service
44
metadata:

charts/application/values.yaml

+14-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ statefulSet:
55
# The policy for how pods inside the statefulSet are handled: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#pod-management-policies
66
podManagementPolicy: OrderedReady
77

8+
cronJob:
9+
enabled: false
10+
schedule: ""
11+
successfulJobsHistoryLimit: 3
12+
failedJobsHistoryLimit: 1
13+
concurrencyPolicy: Forbid
14+
activeDeadlineSeconds: 60
15+
ttlSecondsAfterFinished: 86400
16+
startingDeadlineSeconds: 200
17+
18+
# Defaulting to onFailure for cronJobs only: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy
19+
podRestartPolicy:
20+
821
container:
922
port: 8080
1023
securityContext:
@@ -412,6 +425,7 @@ initContainers: []
412425
# # see initDefaults
413426
# resources: {}
414427
# securityContext: {}
428+
# restartPolicy:
415429
# # 'volumeMounts' names to be mounted in init container as well (under the same path); default: none
416430
# volumeMountNames: []
417431
# # - data
@@ -427,7 +441,6 @@ initDefaults:
427441
limits:
428442
cpu: 500m
429443
memory: 100Mi
430-
restartPolicy: Always
431444
# securityContext: {}
432445

433446
# List of tolerations, will be taken over like-for-like to pod-spec

0 commit comments

Comments
 (0)