diff --git a/chart/templates/jobs/create-user-job.yaml b/chart/templates/jobs/create-user-job.yaml index f0bde008cc1b8..85d43a1ff3758 100644 --- a/chart/templates/jobs/create-user-job.yaml +++ b/chart/templates/jobs/create-user-job.yaml @@ -20,7 +20,7 @@ ################################ ## Airflow Create User Job ################################# -{{- if .Values.webserver.defaultUser.enabled }} +{{- if and .Values.webserver.defaultUser.enabled .Values.createUserJob.enabled }} {{- $nodeSelector := or .Values.createUserJob.nodeSelector .Values.nodeSelector }} {{- $affinity := or .Values.createUserJob.affinity .Values.affinity }} {{- $tolerations := or .Values.createUserJob.tolerations .Values.tolerations }} diff --git a/chart/values.schema.json b/chart/values.schema.json index 852fb9a1bd622..916250c282159 100644 --- a/chart/values.schema.json +++ b/chart/values.schema.json @@ -4282,6 +4282,11 @@ "x-docsSection": "Jobs", "additionalProperties": false, "properties": { + "enabled": { + "description": "Whether the create user job should be created.", + "type": "boolean", + "default": true + }, "command": { "description": "Command to use when running create user job (templated).", "type": [ diff --git a/chart/values.yaml b/chart/values.yaml index 8d5e2361e86c9..5ea76eb65efcc 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -1212,6 +1212,8 @@ scheduler: # Airflow create user job settings createUserJob: + # Whether the create user job should be created + enabled: true # Limit the lifetime of the job object after it finished execution. ttlSecondsAfterFinished: 300 # Command to use when running the create user job (templated). diff --git a/helm-tests/tests/helm_tests/airflow_aux/test_create_user_job.py b/helm-tests/tests/helm_tests/airflow_aux/test_create_user_job.py index a952f60f1a77d..7290af3429009 100644 --- a/helm-tests/tests/helm_tests/airflow_aux/test_create_user_job.py +++ b/helm-tests/tests/helm_tests/airflow_aux/test_create_user_job.py @@ -469,6 +469,56 @@ def test_restart_policy(self, restart_policy): ) assert restart_policy == jmespath.search("spec.template.spec.restartPolicy", docs[0]) + def test_should_not_create_job_when_createuserjob_disabled(self): + """Test that job is not created when createUserJob.enabled is false.""" + docs = render_chart( + values={"createUserJob": {"enabled": False}}, + show_only=["templates/jobs/create-user-job.yaml"], + ) + assert len(docs) == 0 + + def test_should_not_create_job_when_webserver_defaultuser_disabled(self): + """Test that job is not created when webserver.defaultUser.enabled is false.""" + docs = render_chart( + values={"webserver": {"defaultUser": {"enabled": False}}}, + show_only=["templates/jobs/create-user-job.yaml"], + ) + assert len(docs) == 0 + + def test_should_not_create_job_when_both_disabled(self): + """Test that job is not created when both flags are disabled.""" + docs = render_chart( + values={ + "createUserJob": {"enabled": False}, + "webserver": {"defaultUser": {"enabled": False}}, + }, + show_only=["templates/jobs/create-user-job.yaml"], + ) + assert len(docs) == 0 + + def test_should_not_create_job_when_createuserjob_disabled_but_defaultuser_enabled(self): + """Test that job is not created when createUserJob.enabled is false even if defaultUser.enabled is true.""" + docs = render_chart( + values={ + "createUserJob": {"enabled": False}, + "webserver": {"defaultUser": {"enabled": True}}, + }, + show_only=["templates/jobs/create-user-job.yaml"], + ) + assert len(docs) == 0 + + def test_should_create_job_when_both_enabled(self): + """Test that job is created when both createUserJob.enabled and defaultUser.enabled are true.""" + docs = render_chart( + values={ + "createUserJob": {"enabled": True}, + "webserver": {"defaultUser": {"enabled": True}}, + }, + show_only=["templates/jobs/create-user-job.yaml"], + ) + assert len(docs) == 1 + assert docs[0]["kind"] == "Job" + class TestCreateUserJobServiceAccount: """Tests create user job service account."""