Skip to content

Commit

Permalink
Merge pull request #173 from MediaMarktSaturn/knabben-applicationcronjob
Browse files Browse the repository at this point in the history
feat(application) add CronJob capability
  • Loading branch information
heubeck authored Dec 10, 2024
2 parents bf04705 + ef47bb3 commit 5569e12
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 6 deletions.
16 changes: 16 additions & 0 deletions chart-tests/application/ci/test-cronjob-values.yaml
Original file line number Diff line number Diff line change
@@ -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"]
1 change: 0 additions & 1 deletion chart-tests/application/ci/test-init-container-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ initContainers:
tag: 9.3
command: ['ls', '-lah', '/']
env: {}
restartPolicy: Never


initDefaults:
Expand Down
2 changes: 1 addition & 1 deletion charts/application/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ maintainers:
- name: MediaMarktSaturn
url: https://github.com/MediaMarktSaturn
appVersion: 1.0.0
version: 1.30.0
version: 1.31.0
6 changes: 6 additions & 0 deletions charts/application/templates/_podTemplate.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
Expand Down Expand Up @@ -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 }}
Expand Down
24 changes: 24 additions & 0 deletions charts/application/templates/k8s-cron-job.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
2 changes: 1 addition & 1 deletion charts/application/templates/k8s-deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if not .Values.statefulSet.enabled }}
{{- if not (or .Values.statefulSet.enabled .Values.cronJob.enabled)}}
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion charts/application/templates/k8s-service.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
15 changes: 14 additions & 1 deletion charts/application/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5569e12

Please sign in to comment.