diff --git a/application/templates/cronjob.yaml b/application/templates/cronjob.yaml index 58fc87df..97f47aec 100644 --- a/application/templates/cronjob.yaml +++ b/application/templates/cronjob.yaml @@ -96,9 +96,30 @@ spec: {{ include "application.tplvalues.render" ( dict "value" $value "context" $ ) | indent 14 }} {{- end }} {{- end }} - {{- with $job.envFrom }} envFrom: -{{ toYaml . | indent 12 }} + {{- range $value := $job.envFrom }} + {{- if (eq .type "configmap") }} + - configMapRef: + {{- if .name }} + name: {{ include "application.tplvalues.render" ( dict "value" $value.name "context" $ ) }} + {{- else if .nameSuffix }} + name: {{ template "application.name" $ }}-{{ include "application.tplvalues.render" ( dict "value" $value.nameSuffix "context" $ ) }} + {{- else }} + name: {{ template "application.name" $ }} + {{- end }} + optional: {{ default false $value.optional }} + {{- end }} + {{- if (eq .type "secret") }} + - secretRef: + {{- if .name }} + name: {{ include "application.tplvalues.render" ( dict "value" $value.name "context" $ ) }} + {{- else if .nameSuffix }} + name: {{ template "application.name" $ }}-{{ include "application.tplvalues.render" ( dict "value" $value.nameSuffix "context" $ ) }} + {{- else }} + name: {{ template "application.name" $ }} + {{- end }} + optional: {{ default false $value.optional }} + {{- end }} {{- end }} {{- if $job.command }} command: {{ $job.command }} diff --git a/application/templates/job.yaml b/application/templates/job.yaml index 4ec5b5df..03fde47e 100644 --- a/application/templates/job.yaml +++ b/application/templates/job.yaml @@ -76,9 +76,30 @@ spec: {{ include "application.tplvalues.render" ( dict "value" $value "context" $ ) | indent 10 }} {{- end }} {{- end }} - {{- with $job.envFrom }} envFrom: -{{ toYaml . | indent 8 }} + {{- range $value := $job.envFrom }} + {{- if (eq .type "configmap") }} + - configMapRef: + {{- if .name }} + name: {{ include "application.tplvalues.render" ( dict "value" $value.name "context" $ ) }} + {{- else if .nameSuffix }} + name: {{ template "application.name" $ }}-{{ include "application.tplvalues.render" ( dict "value" $value.nameSuffix "context" $ ) }} + {{- else }} + name: {{ template "application.name" $ }} + {{- end }} + optional: {{ default false $value.optional }} + {{- end }} + {{- if (eq .type "secret") }} + - secretRef: + {{- if .name }} + name: {{ include "application.tplvalues.render" ( dict "value" $value.name "context" $ ) }} + {{- else if .nameSuffix }} + name: {{ template "application.name" $ }}-{{ include "application.tplvalues.render" ( dict "value" $value.nameSuffix "context" $ ) }} + {{- else }} + name: {{ template "application.name" $ }} + {{- end }} + optional: {{ default false $value.optional }} + {{- end }} {{- end }} {{- if $job.command }} command: {{ $job.command }} diff --git a/application/tests/cronjob_test.yaml b/application/tests/cronjob_test.yaml index df170653..af5544ba 100644 --- a/application/tests/cronjob_test.yaml +++ b/application/tests/cronjob_test.yaml @@ -254,6 +254,92 @@ tests: path: spec.jobTemplate.spec.template.metadata.labels["application.stakater.com/workload-class"] value: scheduled + - it: configures envFrom as mandatory by default (as secret) + set: + cronJob: + enabled: true + jobs: + example: + image: + repository: example-image + tag: example-tag + envFrom: + foo-secret: + type: secret + name: foo + asserts: + - equal: + path: spec.jobTemplate.spec.template.spec.containers[0].envFrom[0].secretRef.name + value: foo + - equal: + path: spec.jobTemplate.spec.template.spec.containers[0].envFrom[0].secretRef.optional + value: false + + - it: configures envFrom as optional when configured (as secret) + set: + cronJob: + enabled: true + jobs: + example: + image: + repository: example-image + tag: example-tag + envFrom: + foo-secret: + type: secret + name: foo + optional: true + asserts: + - equal: + path: spec.jobTemplate.spec.template.spec.containers[0].envFrom[0].secretRef.name + value: foo + - equal: + path: spec.jobTemplate.spec.template.spec.containers[0].envFrom[0].secretRef.optional + value: true + + - it: configures envFrom as mandatory by default (as configmap) + set: + cronJob: + enabled: true + jobs: + example: + image: + repository: example-image + tag: example-tag + envFrom: + foo-configmap: + type: configmap + name: foo + asserts: + - equal: + path: spec.jobTemplate.spec.template.spec.containers[0].envFrom[0].configMapRef.name + value: foo + - equal: + path: spec.jobTemplate.spec.template.spec.containers[0].envFrom[0].configMapRef.optional + value: false + + - it: configures envFrom as optional when configured (as configmap) + set: + cronJob: + enabled: true + jobs: + example: + image: + repository: example-image + tag: example-tag + envFrom: + foo-configmap: + type: configmap + name: foo + optional: true + asserts: + - equal: + path: spec.jobTemplate.spec.template.spec.containers[0].envFrom[0].configMapRef.name + value: foo + - equal: + path: spec.jobTemplate.spec.template.spec.containers[0].envFrom[0].configMapRef.optional + value: true + - it: uses image templating set: custom: diff --git a/application/tests/deployment_test.yaml b/application/tests/deployment_test.yaml index 08f8ee97..57ba191d 100644 --- a/application/tests/deployment_test.yaml +++ b/application/tests/deployment_test.yaml @@ -134,7 +134,7 @@ tests: path: spec.template.spec.containers[0].livenessProbe.grpc.port value: 5000 - - it: configures envFrom as mandatory by default + - it: configures envFrom as mandatory by default (as secret) set: deployment.envFrom: foo-secret: @@ -148,7 +148,7 @@ tests: path: spec.template.spec.containers[0].envFrom[0].secretRef.optional value: false - - it: configures envFrom as optional when configured + - it: configures envFrom as optional when configured (as secret) set: deployment.envFrom: foo-secret: @@ -163,6 +163,35 @@ tests: path: spec.template.spec.containers[0].envFrom[0].secretRef.optional value: true + - it: configures envFrom as mandatory by default (as configmap) + set: + deployment.envFrom: + foo-configmap: + type: configmap + name: foo + asserts: + - equal: + path: spec.template.spec.containers[0].envFrom[0].configMapRef.name + value: foo + - equal: + path: spec.template.spec.containers[0].envFrom[0].configMapRef.optional + value: false + + - it: configures envFrom as optional when configured (as configmap) + set: + deployment.envFrom: + foo-configmap: + type: configmap + name: foo + optional: true + asserts: + - equal: + path: spec.template.spec.containers[0].envFrom[0].configMapRef.name + value: foo + - equal: + path: spec.template.spec.containers[0].envFrom[0].configMapRef.optional + value: true + - it: includes application.stakater.com/workload-class label in pod template for service selector set: deployment: diff --git a/application/tests/job_test.yaml b/application/tests/job_test.yaml index 52e1c61a..06c1a790 100644 --- a/application/tests/job_test.yaml +++ b/application/tests/job_test.yaml @@ -254,6 +254,92 @@ tests: path: spec.template.metadata.labels["application.stakater.com/workload-class"] value: batch + - it: configures envFrom as mandatory by default (as secret) + set: + job: + enabled: true + jobs: + example: + image: + repository: example-image + tag: example-tag + envFrom: + foo-secret: + type: secret + name: foo + asserts: + - equal: + path: spec.template.spec.containers[0].envFrom[0].secretRef.name + value: foo + - equal: + path: spec.template.spec.containers[0].envFrom[0].secretRef.optional + value: false + + - it: configures envFrom as optional when configured (as secret) + set: + job: + enabled: true + jobs: + example: + image: + repository: example-image + tag: example-tag + envFrom: + foo-secret: + type: secret + name: foo + optional: true + asserts: + - equal: + path: spec.template.spec.containers[0].envFrom[0].secretRef.name + value: foo + - equal: + path: spec.template.spec.containers[0].envFrom[0].secretRef.optional + value: true + + - it: configures envFrom as mandatory by default (as configmap) + set: + job: + enabled: true + jobs: + example: + image: + repository: example-image + tag: example-tag + envFrom: + foo-configmap: + type: configmap + name: foo + asserts: + - equal: + path: spec.template.spec.containers[0].envFrom[0].configMapRef.name + value: foo + - equal: + path: spec.template.spec.containers[0].envFrom[0].configMapRef.optional + value: false + + - it: configures envFrom as optional when configured (as configmap) + set: + job: + enabled: true + jobs: + example: + image: + repository: example-image + tag: example-tag + envFrom: + foo-configmap: + type: configmap + name: foo + optional: true + asserts: + - equal: + path: spec.template.spec.containers[0].envFrom[0].configMapRef.name + value: foo + - equal: + path: spec.template.spec.containers[0].envFrom[0].configMapRef.optional + value: true + - it: uses image templating set: custom: diff --git a/application/values-test.yaml b/application/values-test.yaml index 9f38a82a..44f0e301 100644 --- a/application/values-test.yaml +++ b/application/values-test.yaml @@ -1292,6 +1292,19 @@ cronJob: image: repository: docker.io/nginx tag: v1.0.0 + # If want to mount Envs from configmap or secret + envFrom: + production-cm: + type: configmap + nameSuffix: my-configmap + postgres-config: + type: secret + nameSuffix: postgres + optional: false + nonexisting-config: + type: secret + nameSuffix: nonexisting + optional: true env: KEY: value: VALUE @@ -1341,6 +1354,19 @@ job: image: repository: docker.io/nginx tag: v1.0.0 + # If want to mount Envs from configmap or secret + envFrom: + production-cm: + type: configmap + nameSuffix: my-configmap + postgres-config: + type: secret + nameSuffix: postgres + optional: false + nonexisting-config: + type: secret + nameSuffix: nonexisting + optional: true env: KEY: value: VALUE diff --git a/application/values.yaml b/application/values.yaml index 661e2e04..93b52079 100644 --- a/application/values.yaml +++ b/application/values.yaml @@ -37,6 +37,18 @@ cronJob: # priorityClassName: high-priority # startingDeadlineSeconds: 0 # activeDeadlineSeconds: 0 + # envFrom: + # production-cm: + # type: configmap + # nameSuffix: my-configmap + # postgres-config: + # type: secret + # nameSuffix: postgres + # optional: false + # optional-config: + # type: secret + # nameSuffix: extra + # optional: true # env: # KEY: # value: VALUE @@ -87,6 +99,18 @@ job: # helm.sh/hook-delete-policy: "before-hook-creation" # startingDeadlineSeconds: 0 # activeDeadlineSeconds: 0 + # envFrom: + # production-cm: + # type: configmap + # nameSuffix: my-configmap + # postgres-config: + # type: secret + # nameSuffix: postgres + # optional: false + # optional-config: + # type: secret + # nameSuffix: extra + # optional: true # env: # KEY: # value: VALUE