Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ spec:
jobTemplate:
spec:
backoffLimit: 1
{{- if not (kindIs "invalid" .Values.databaseCleanup.ttlSecondsAfterFinished) }}
ttlSecondsAfterFinished: {{ .Values.databaseCleanup.ttlSecondsAfterFinished }}
{{- end }}
template:
metadata:
labels:
Expand Down
9 changes: 9 additions & 0 deletions chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -10890,6 +10890,15 @@
],
"default": 1,
"x-docsSection": "Kubernetes"
},
"ttlSecondsAfterFinished": {
"description": "The number of seconds after a finished Job is eligible to be automatically deleted.",
"type": [
"integer",
"null"
],
"default": null,
"x-docsSection": "Kubernetes"
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3944,6 +3944,9 @@ databaseCleanup:
failedJobsHistoryLimit: 1
successfulJobsHistoryLimit: 1

# Time to live (in seconds) for Jobs created by this CronJob after they finish.
ttlSecondsAfterFinished: ~

# Configuration for postgresql subchart
# Uses bitnamilegacy images to avoid Bitnami licensing restrictions
# Not recommended for production - use external database instead
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,32 @@ def test_should_work_with_custom_schedule_string(self, release_name, schedule_va
class TestDatabaseCleanup:
"""Tests database cleanup."""

def test_ttl_seconds_after_finished_default_behavior(self):
values = {"databaseCleanup": {"enabled": True}}
docs = render_chart(
values=values,
show_only=["templates/database-cleanup/database-cleanup-cronjob.yaml"],
)

assert "ttlSecondsAfterFinished" not in docs[0]["spec"]["jobTemplate"]["spec"]

@pytest.mark.parametrize(
("ttl_value", "expected_rendered"),
[
(300, 300),
(0, 0),
],
)
def test_ttl_seconds_after_finished_rendering(self, ttl_value, expected_rendered):
values = {"databaseCleanup": {"enabled": True, "ttlSecondsAfterFinished": ttl_value}}
docs = render_chart(
values=values,
show_only=["templates/database-cleanup/database-cleanup-cronjob.yaml"],
)

actual_ttl = jmespath.search("spec.jobTemplate.spec.ttlSecondsAfterFinished", docs[0])
assert actual_ttl == expected_rendered

def test_should_create_cronjob_for_enabled_cleanup(self):
docs = render_chart(
values={
Expand Down