Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ttlSecondsAfterFinished to migrateDatabaseJob and createUserJob #29314

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking specifically for not nil because 0 is a valid value for this field and it would evaluate to false normally.

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 @@ -2945,6 +2945,14 @@
"type": "boolean",
"default": true
},
"ttlSecondsAfterFinished": {
"description": "Limit the lifetime of the job object after it finished execution",
"type": [
"integer",
"null"
],
"default": null
},
"env": {
"description": "Add additional env vars to the create user job pod.",
"type": "array",
Expand Down Expand Up @@ -3144,6 +3152,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": null
}
}
},
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: ~
alexandermalyga marked this conversation as resolved.
Show resolved Hide resolved
# 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: ~
# Command to use when running the migrate database job (templated).
command: ~
# Args to use when running the migrate database job (templated).
Expand Down
21 changes: 21 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,27 @@ 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(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
21 changes: 21 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,27 @@ 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(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