diff --git a/chart/templates/cleanup/cleanup-cronjob.yaml b/chart/templates/cleanup/cleanup-cronjob.yaml index 5afab9462bea7..1e8da267e53f9 100644 --- a/chart/templates/cleanup/cleanup-cronjob.yaml +++ b/chart/templates/cleanup/cleanup-cronjob.yaml @@ -47,10 +47,10 @@ spec: schedule: "{{ tpl .Values.cleanup.schedule . }}" # The cron job does not allow concurrent runs; if it is time for a new job run and the previous job run hasn't finished yet, the cron job skips the new job run concurrencyPolicy: Forbid - {{- if .Values.cleanup.failedJobsHistoryLimit }} + {{- if not ( eq .Values.cleanup.failedJobsHistoryLimit nil) }} failedJobsHistoryLimit: {{ .Values.cleanup.failedJobsHistoryLimit }} {{- end }} - {{- if .Values.cleanup.successfulJobsHistoryLimit }} + {{- if not (eq .Values.cleanup.successfulJobsHistoryLimit nil) }} successfulJobsHistoryLimit: {{ .Values.cleanup.successfulJobsHistoryLimit }} {{- end }} jobTemplate: @@ -105,10 +105,17 @@ spec: env: {{- include "standard_airflow_environment" . | indent 12 }} {{- include "container_extra_envs" (list . .Values.cleanup.env) | indent 12 }} - volumeMounts: {{- include "airflow_config_mount" . | nindent 16 }} + volumeMounts: + {{- include "airflow_config_mount" . | nindent 16 }} + {{- if .Values.volumeMounts }} + {{- toYaml .Values.volumeMounts | nindent 16 }} + {{- end }} resources: {{- toYaml .Values.cleanup.resources | nindent 16 }} volumes: - name: config configMap: name: {{ template "airflow_config" . }} + {{- if .Values.volumes }} + {{- toYaml .Values.volumes | nindent 12 }} + {{- end }} {{- end }} diff --git a/helm_tests/airflow_aux/test_cleanup_pods.py b/helm_tests/airflow_aux/test_cleanup_pods.py index 4305531ec5f6e..d63132f50bd51 100644 --- a/helm_tests/airflow_aux/test_cleanup_pods.py +++ b/helm_tests/airflow_aux/test_cleanup_pods.py @@ -96,6 +96,8 @@ def test_should_create_cronjob_for_enabled_cleanup(self): "subPath": "airflow.cfg", "readOnly": True, } in jmespath.search("spec.jobTemplate.spec.template.spec.containers[0].volumeMounts", docs[0]) + assert "successfulJobsHistoryLimit" not in docs[0]["spec"] + assert "failedJobsHistoryLimit" not in docs[0]["spec"] def test_should_pass_validation_with_v1beta1_api(self): render_chart( @@ -327,6 +329,20 @@ def test_should_set_job_history_limits(self): assert 2 == jmespath.search("spec.failedJobsHistoryLimit", docs[0]) assert 4 == jmespath.search("spec.successfulJobsHistoryLimit", docs[0]) + def test_should_set_zero_job_history_limits(self): + docs = render_chart( + values={ + "cleanup": { + "enabled": True, + "failedJobsHistoryLimit": 0, + "successfulJobsHistoryLimit": 0, + }, + }, + show_only=["templates/cleanup/cleanup-cronjob.yaml"], + ) + assert 0 == jmespath.search("spec.failedJobsHistoryLimit", docs[0]) + assert 0 == jmespath.search("spec.successfulJobsHistoryLimit", docs[0]) + def test_no_airflow_local_settings(self): docs = render_chart( values={ @@ -355,6 +371,24 @@ def test_airflow_local_settings(self): "readOnly": True, } in jmespath.search("spec.jobTemplate.spec.template.spec.containers[0].volumeMounts", docs[0]) + def test_global_volumes_and_volume_mounts(self): + docs = render_chart( + values={ + "cleanup": {"enabled": True}, + "volumes": [{"name": "test-volume", "emptyDir": {}}], + "volumeMounts": [{"name": "test-volume", "mountPath": "/test"}], + }, + show_only=["templates/cleanup/cleanup-cronjob.yaml"], + ) + assert { + "name": "test-volume", + "mountPath": "/test", + } in jmespath.search("spec.jobTemplate.spec.template.spec.containers[0].volumeMounts", docs[0]) + assert { + "name": "test-volume", + "emptyDir": {}, + } in jmespath.search("spec.jobTemplate.spec.template.spec.volumes", docs[0]) + class TestCleanupServiceAccount: """Tests cleanup of service accounts."""