This is an automated email from the ASF dual-hosted git repository.

jscheffl pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 99e5127f6d5 add ttlSecondsAfterFinished to databaseCleanup job (#64164)
99e5127f6d5 is described below

commit 99e5127f6d5f4995704cda9388b350ad11628ada
Author: rjgoyln <[email protected]>
AuthorDate: Sat Apr 11 17:17:33 2026 +0800

    add ttlSecondsAfterFinished to databaseCleanup job (#64164)
    
    * fix test
    
    * simplify template logic and add edge case test
    
    * Update chart/values.yaml
    
    Co-authored-by: Copilot <[email protected]>
    
    * Update chart/values.schema.json
    
    Co-authored-by: Przemysław Mirowski 
<[email protected]>
    
    * seperate test case
    
    * Update chart/values.yaml
    
    Co-authored-by: Przemysław Mirowski 
<[email protected]>
    
    * Potential fix for pull request finding
    
    Co-authored-by: Copilot Autofix powered by AI 
<[email protected]>
    
    * move tests into the TestDatabaseCleanup
    
    ---------
    
    Co-authored-by: Copilot <[email protected]>
    Co-authored-by: Przemysław Mirowski 
<[email protected]>
---
 .../database-cleanup/database-cleanup-cronjob.yaml |  3 +++
 chart/values.schema.json                           |  9 ++++++++
 chart/values.yaml                                  |  3 +++
 .../airflow_aux/test_database_cleanup.py           | 26 ++++++++++++++++++++++
 4 files changed, 41 insertions(+)

diff --git a/chart/templates/database-cleanup/database-cleanup-cronjob.yaml 
b/chart/templates/database-cleanup/database-cleanup-cronjob.yaml
index f22db1fc47d..ae506f70800 100644
--- a/chart/templates/database-cleanup/database-cleanup-cronjob.yaml
+++ b/chart/templates/database-cleanup/database-cleanup-cronjob.yaml
@@ -56,6 +56,9 @@ spec:
   jobTemplate:
     spec:
       backoffLimit: 1
+      {{- if not (kindIs "invalid" 
.Values.databaseCleanup.ttlSecondsAfterFinished) }}
+      ttlSecondsAfterFinished: {{ 
.Values.databaseCleanup.ttlSecondsAfterFinished }}
+      {{- end }}
       template:
         metadata:
           labels:
diff --git a/chart/values.schema.json b/chart/values.schema.json
index 555dc09410e..c7a92ce959d 100644
--- a/chart/values.schema.json
+++ b/chart/values.schema.json
@@ -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"
                 }
             }
         },
diff --git a/chart/values.yaml b/chart/values.yaml
index 82550521314..5d20fa0bac1 100644
--- a/chart/values.yaml
+++ b/chart/values.yaml
@@ -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
diff --git a/helm-tests/tests/helm_tests/airflow_aux/test_database_cleanup.py 
b/helm-tests/tests/helm_tests/airflow_aux/test_database_cleanup.py
index 4ad2e990d6b..9c4db3a0dab 100644
--- a/helm-tests/tests/helm_tests/airflow_aux/test_database_cleanup.py
+++ b/helm-tests/tests/helm_tests/airflow_aux/test_database_cleanup.py
@@ -72,6 +72,32 @@ class TestDatabaseCleanupDeployment:
 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={

Reply via email to