From dc4e83852ace1a30d732d342382a6172ff293fab Mon Sep 17 00:00:00 2001 From: Chiel Kooijman Date: Wed, 22 Jan 2025 22:03:18 +0100 Subject: [PATCH] feat: Add cronjob template (#25) * Add cronjob template * Add cronjob to _app.yaml * Update charts/helmet/templates/_cronjob.yaml * Increase chart version --------- Co-authored-by: Chiel Kooijman Co-authored-by: Mohammad Abdolirad --- charts/helmet/Chart.yaml | 4 +- charts/helmet/templates/_app.yaml | 1 + charts/helmet/templates/_cronjob.yaml | 47 ++++++++++++++++ charts/helmet/values.yaml | 81 +++++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 charts/helmet/templates/_cronjob.yaml diff --git a/charts/helmet/Chart.yaml b/charts/helmet/Chart.yaml index 7beb839..8b49f7d 100644 --- a/charts/helmet/Chart.yaml +++ b/charts/helmet/Chart.yaml @@ -3,8 +3,8 @@ name: helmet description: Helmet is a library Helm Chart for grouping common logics. This chart is not deployable by itself. home: https://github.com/companyinfo/helm-charts/blob/main/charts/helmet type: library -version: "0.12.1" -appVersion: "0.12.1" +version: "0.13.0" +appVersion: "0.13.0" keywords: - common - helper diff --git a/charts/helmet/templates/_app.yaml b/charts/helmet/templates/_app.yaml index fb6eaa2..b60ff84 100644 --- a/charts/helmet/templates/_app.yaml +++ b/charts/helmet/templates/_app.yaml @@ -25,5 +25,6 @@ {{ include "helmet.serviceaccount" . }} {{ include "helmet.servicemonitor" . }} +{{ include "helmet.cronjob" . }} {{ include "helmet.podmonitor" . }} {{- end }} diff --git a/charts/helmet/templates/_cronjob.yaml b/charts/helmet/templates/_cronjob.yaml new file mode 100644 index 0000000..8f3ef4f --- /dev/null +++ b/charts/helmet/templates/_cronjob.yaml @@ -0,0 +1,47 @@ +{{- define "helmet.cronjob" -}} +{{- if .Values.cronjob.enabled -}} +--- +apiVersion: {{ include "common.capabilities.cronjob.apiVersion" . }} +kind: CronJob +metadata: + name: {{ include "common.names.fullname" . }} + namespace: {{ include "common.names.namespace" . | quote }} + labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }} + {{- if .Values.commonAnnotations }} + annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }} + {{- end }} +spec: + concurrencyPolicy: {{ .Values.cronjob.concurrencyPolicy | quote }} + schedule: {{ .Values.cronjob.schedule | quote }} + successfulJobsHistoryLimit: {{ .Values.cronjob.successfulJobsHistoryLimit }} + jobTemplate: + spec: + template: + metadata: + labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 12 }} + {{- if .Values.cronjob.podAnnotations }} + annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.cronjob.podAnnotations "context" $) | nindent 12 }} + {{- end }} + spec: + {{- include "common.images.pullSecrets" (dict "images" (list .Values.image) "global" .Values.global) | indent 10 }} + {{- if and .Values.cronjob.nodeSelector .Values.nodeSelector }} + nodeSelector: {{- default (toYaml .Values.nodeSelector) (toYaml .Values.cronjob.nodeSelector) | nindent 12 }} + {{- end }} + {{- if and .Values.cronjob.tolerations .Values.tolerations }} + tolerations: {{- default (toYaml .Values.tolerations) (toYaml .Values.cronjob.tolerations) | nindent 12 }} + {{- end }} + restartPolicy: OnFailure + {{- if .Values.podSecurityContext.enabled }} + securityContext: {{- omit .Values.podSecurityContext "enabled" | toYaml | nindent 12 }} + {{- end }} + {{- if .Values.cronjob.initContainers }} + initContainers: {{- include "common.tplvalues.render" (dict "value" .Values.cronjob.initContainers "context" $) | nindent 12 }} + {{- end }} + {{- if .Values.cronjob.containers }} + containers: {{- include "common.tplvalues.render" (dict "value" .Values.cronjob.containers "context" $) | nindent 12 }} + {{- end }} + {{- if .Values.cronjob.volumes }} + volumes: {{- include "common.tplvalues.render" (dict "value" .Values.cronjob.volumes "context" $) | nindent 12 }} + {{- end }} +{{- end }} +{{- end }} diff --git a/charts/helmet/values.yaml b/charts/helmet/values.yaml index 50751c4..22d7a33 100644 --- a/charts/helmet/values.yaml +++ b/charts/helmet/values.yaml @@ -853,3 +853,84 @@ exports: ## @param serviceAccount.labels Additional custom labels for the ServiceAccount ## labels: {} + + ## Cronjob: create jobs on a repeated schedule + ## Ref: https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/ + ## + cronjob: + ## @param cronjob.enabled + ## + enabled: false + + ## @param cronjob.concurrencyPolicy Allow/Forbid/Replace concurrency + ## + concurrencyPolicy: Allow + + ## @param cronjob.schedule run schedule for the cronjob + ## Cron format: " " + ## + schedule: "" + + ## @param cronjob.successfulJobsHistoryLimit + ## + successfulJobsHistoryLimit: 3 + + ## @param nodeSelector Node labels for pod assignment. + ## Ref: https://kubernetes.io/docs/user-guide/node-selection/ + ## + nodeSelector: {} + + ## @param tolerations Tolerations for pod assignment. + ## Ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/ + ## + tolerations: [] + + ## @param restartPolicy Restart conditions + ## Ref: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy + ## + restartPolicy: OnFailure + + ## Configure APP pods Security Context + ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod + ## @param podSecurityContext.enabled Enabled APP pods' Security Context + ## @param podSecurityContext.fsGroup Set APP pod's Security Context fsGroup + ## + podSecurityContext: + enabled: false + fsGroup: 0 + + ## @param initContainers Add additional init containers to the APP pods + ## Example: + ## initContainers: + ## - name: your-image-name + ## image: your-image + ## imagePullPolicy: Always + ## ports: + ## - name: portname + ## containerPort: 1234 + ## + initContainers: [] + + ## @param containers Add additional containers to the APP pods + ## Example: + ## containers: + ## - name: your-image-name + ## image: your-image + ## imagePullPolicy: Always + ## ports: + ## - name: portname + ## containerPort: 1234 + ## + containers: [] + + ## @param volumes Array to add volumes (evaluated as a template) + ## Example: + ## volumes: + ## - name: vol-conf + ## configMap: + ## name: "configmap-name" + ## - name: vol-secret + ## secret: + ## secretName: "secret-name" + ## + volumes: []