Skip to content

Commit

Permalink
Add ttlSecondsAfterFinished to migrateDatabaseJob and createUserJob (#…
Browse files Browse the repository at this point in the history
…29314)

* add ttlSecondsAfterFinished parameter to migrate-database-job and create-user-job

* fixed ttlSecondsAfterFinished tests

* fix ttlSecondsAfterFinished population when value is zero

* fixed createUserJob helm tests

* add default value of 300 to ttlSecondsAfterFinished

---------

Co-authored-by: Oleksandr Malyga <[email protected]>
  • Loading branch information
alexandermalyga and Oleksandr Malyga authored Feb 20, 2023
1 parent 1677d80 commit cd01650
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 0 deletions.
3 changes: 3 additions & 0 deletions chart/templates/jobs/create-user-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ metadata:
{{- $annotations | toYaml | nindent 4 }}
{{- end }}
spec:
{{- if not (kindIs "invalid" .Values.createUserJob.ttlSecondsAfterFinished) }}
ttlSecondsAfterFinished: {{ .Values.createUserJob.ttlSecondsAfterFinished }}
{{- end }}
template:
metadata:
labels:
Expand Down
3 changes: 3 additions & 0 deletions chart/templates/jobs/migrate-database-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ metadata:
{{- $annotations | toYaml | nindent 4 }}
{{- end }}
spec:
{{- if not (kindIs "invalid" .Values.migrateDatabaseJob.ttlSecondsAfterFinished) }}
ttlSecondsAfterFinished: {{ .Values.migrateDatabaseJob.ttlSecondsAfterFinished }}
{{- end }}
template:
metadata:
labels:
Expand Down
16 changes: 16 additions & 0 deletions chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2884,6 +2884,14 @@
"type": "boolean",
"default": true
},
"ttlSecondsAfterFinished": {
"description": "Limit the lifetime of the job object after it finished execution",
"type": [
"integer",
"null"
],
"default": 300
},
"env": {
"description": "Add additional env vars to the create user job pod.",
"type": "array",
Expand Down Expand Up @@ -3083,6 +3091,14 @@
"description": "Specify if you want additional configured env vars applied to this job",
"type": "boolean",
"default": true
},
"ttlSecondsAfterFinished": {
"description": "Limit the lifetime of the job object after it finished execution",
"type": [
"integer",
"null"
],
"default": 300
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,8 @@ scheduler:

# Airflow create user job settings
createUserJob:
# Limit the lifetime of the job object after it finished execution.
ttlSecondsAfterFinished: 300
# Command to use when running the create user job (templated).
command: ~
# Args to use when running the create user job (templated).
Expand Down Expand Up @@ -837,6 +839,8 @@ createUserJob:
# Airflow database migration job settings
migrateDatabaseJob:
enabled: true
# Limit the lifetime of the job object after it finished execution.
ttlSecondsAfterFinished: 300
# Command to use when running the migrate database job (templated).
command: ~
# Args to use when running the migrate database job (templated).
Expand Down
24 changes: 24 additions & 0 deletions tests/charts/test_create_user_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,30 @@ def test_should_disable_custom_env(self):
assert {"name": "foo", "value": "bar"} not in envs
assert {"name": "extraFoo", "value": "extraBar"} not in envs

def test_job_ttl_after_finished(self):
docs = render_chart(
values={"createUserJob": {"ttlSecondsAfterFinished": 1}},
show_only=["templates/jobs/create-user-job.yaml"],
)
ttl = jmespath.search("spec.ttlSecondsAfterFinished", docs[0])
assert ttl == 1

def test_job_ttl_after_finished_zero(self):
docs = render_chart(
values={"createUserJob": {"ttlSecondsAfterFinished": 0}},
show_only=["templates/jobs/create-user-job.yaml"],
)
ttl = jmespath.search("spec.ttlSecondsAfterFinished", docs[0])
assert ttl == 0

def test_job_ttl_after_finished_nil(self):
docs = render_chart(
values={"createUserJob": {"ttlSecondsAfterFinished": None}},
show_only=["templates/jobs/create-user-job.yaml"],
)
spec = jmespath.search("spec", docs[0])
assert "ttlSecondsAfterFinished" not in spec

@pytest.mark.parametrize(
"airflow_version, expected_arg",
[
Expand Down
24 changes: 24 additions & 0 deletions tests/charts/test_migrate_database_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,30 @@ def test_should_add_global_volume_and_global_volume_mount(self):
"spec.template.spec.containers[0].volumeMounts[-1]", docs[0]
)

def test_job_ttl_after_finished(self):
docs = render_chart(
values={"migrateDatabaseJob": {"ttlSecondsAfterFinished": 1}},
show_only=["templates/jobs/migrate-database-job.yaml"],
)
ttl = jmespath.search("spec.ttlSecondsAfterFinished", docs[0])
assert ttl == 1

def test_job_ttl_after_finished_zero(self):
docs = render_chart(
values={"migrateDatabaseJob": {"ttlSecondsAfterFinished": 0}},
show_only=["templates/jobs/migrate-database-job.yaml"],
)
ttl = jmespath.search("spec.ttlSecondsAfterFinished", docs[0])
assert ttl == 0

def test_job_ttl_after_finished_nil(self):
docs = render_chart(
values={"migrateDatabaseJob": {"ttlSecondsAfterFinished": None}},
show_only=["templates/jobs/migrate-database-job.yaml"],
)
spec = jmespath.search("spec", docs[0])
assert "ttlSecondsAfterFinished" not in spec

@pytest.mark.parametrize(
"airflow_version, expected_arg",
[
Expand Down

0 comments on commit cd01650

Please sign in to comment.