From 0e0f29ee4370cbe2a65c23dd345023eddf87511d Mon Sep 17 00:00:00 2001 From: David Frickert Date: Thu, 16 Nov 2023 15:39:13 +0100 Subject: [PATCH] CronJob - Allow file ConfigMap & disabling command override (#90) * allow file configmap on cron-job chart * Allow disabling the command override in cronjob container * Use name of volume instead of fileName for configmap naming * Add YAML separator to configmaps to allow multiple configmap volumes - before this change if you tried to use e.g. multiple file configmaps they would all be appended in one YAML file due to no usage of separators, which would lead to only one of the file confimaps actually be created. * Fix broken test due to file configmap naming change --- charts/common/templates/_configmap.yaml | 1 + charts/common/templates/_customFileConfigmap.yaml | 4 ++-- charts/common/templates/_volumesRef.yaml | 2 +- charts/cron-job/templates/cronJob.yaml | 2 ++ charts/cron-job/templates/custom-file-configmap.yaml | 1 + charts/cron-job/values.yaml | 1 + charts/onechart/tests/deployment_volumes_test.yaml | 2 +- 7 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 charts/cron-job/templates/custom-file-configmap.yaml diff --git a/charts/common/templates/_configmap.yaml b/charts/common/templates/_configmap.yaml index babfd71..6b06160 100644 --- a/charts/common/templates/_configmap.yaml +++ b/charts/common/templates/_configmap.yaml @@ -1,5 +1,6 @@ {{- define "common.configmap.tpl" -}} {{- if .Values.vars }} +--- apiVersion: v1 kind: ConfigMap metadata: diff --git a/charts/common/templates/_customFileConfigmap.yaml b/charts/common/templates/_customFileConfigmap.yaml index 00256de..2ca2369 100644 --- a/charts/common/templates/_customFileConfigmap.yaml +++ b/charts/common/templates/_customFileConfigmap.yaml @@ -1,11 +1,11 @@ {{- define "common.customFileConfigmap.tpl" -}} {{- range .Values.volumes }} {{- if .fileName }} - +--- apiVersion: v1 kind: ConfigMap metadata: - name: {{ template "common.robustName" .fileName }} + name: {{ template "common.robustName" (printf "%s-%s" $.Release.Name .name) }} namespace: {{ $.Release.Namespace }} data: {{ .fileName }}: | diff --git a/charts/common/templates/_volumesRef.yaml b/charts/common/templates/_volumesRef.yaml index a1b08aa..122cde5 100644 --- a/charts/common/templates/_volumesRef.yaml +++ b/charts/common/templates/_volumesRef.yaml @@ -10,7 +10,7 @@ volumes: name: {{ .existingConfigMap }} {{- else if .fileName }} configMap: - name: {{ template "common.robustName" .fileName }} + name: {{ template "common.robustName" (printf "%s-%s" $.Release.Name .name) }} {{- else if .hostPath }} hostPath: path: {{ .hostPath.path }} diff --git a/charts/cron-job/templates/cronJob.yaml b/charts/cron-job/templates/cronJob.yaml index 4916979..2e7357d 100644 --- a/charts/cron-job/templates/cronJob.yaml +++ b/charts/cron-job/templates/cronJob.yaml @@ -25,10 +25,12 @@ spec: {{- if .Values.vars }} imagePullPolicy: {{ .Values.image.pullPolicy }} {{- end }} + {{- if .Values.overrideCommand }} command: - {{ .Values.shell }} - -c - {{ .Values.command | quote }} + {{- end }} {{- include "common.envFromRef.tpl" . | nindent 14 }} {{- include "common.volumeMountsRef.tpl" . | nindent 14 }} resources: diff --git a/charts/cron-job/templates/custom-file-configmap.yaml b/charts/cron-job/templates/custom-file-configmap.yaml new file mode 100644 index 0000000..040eb27 --- /dev/null +++ b/charts/cron-job/templates/custom-file-configmap.yaml @@ -0,0 +1 @@ +{{- include "common.customFileConfigmap.tpl" . -}} diff --git a/charts/cron-job/values.yaml b/charts/cron-job/values.yaml index f0bca92..8c80992 100644 --- a/charts/cron-job/values.yaml +++ b/charts/cron-job/values.yaml @@ -5,6 +5,7 @@ image: schedule: "*/1 * * * *" command: | echo "I'm alive" +overrideCommand: true shell: "/bin/sh" nameOverride: "" diff --git a/charts/onechart/tests/deployment_volumes_test.yaml b/charts/onechart/tests/deployment_volumes_test.yaml index dd655b4..a6b63cc 100644 --- a/charts/onechart/tests/deployment_volumes_test.yaml +++ b/charts/onechart/tests/deployment_volumes_test.yaml @@ -169,7 +169,7 @@ tests: value: - name: volume-name configMap: - name: myfile-conf + name: release-name-volume-name - equal: path: spec.template.spec.containers[0].volumeMounts value: