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 3314d54c359 Chart: add custom envs to database cleanup (#59804)
3314d54c359 is described below
commit 3314d54c3595f410a147790b7119392a0922268c
Author: Aakcht <[email protected]>
AuthorDate: Thu Dec 25 23:05:45 2025 +0500
Chart: add custom envs to database cleanup (#59804)
---
.../database-cleanup/database-cleanup-cronjob.yaml | 9 +++++++--
chart/values.schema.json | 5 +++++
chart/values.yaml | 1 +
.../helm_tests/airflow_aux/test_database_cleanup.py | 21 +++++++++++++++------
.../airflow_aux/test_extra_env_env_from.py | 7 +++++++
5 files changed, 35 insertions(+), 8 deletions(-)
diff --git a/chart/templates/database-cleanup/database-cleanup-cronjob.yaml
b/chart/templates/database-cleanup/database-cleanup-cronjob.yaml
index 78e4e61abd7..e6c94300197 100644
--- a/chart/templates/database-cleanup/database-cleanup-cronjob.yaml
+++ b/chart/templates/database-cleanup/database-cleanup-cronjob.yaml
@@ -98,9 +98,14 @@ spec:
{{- if .Values.databaseCleanup.args }}
args: {{ tpl (toYaml .Values.databaseCleanup.args) . | nindent
16 }}
{{- end }}
+ {{- if .Values.databaseCleanup.applyCustomEnv }}
+ envFrom: {{- include "custom_airflow_environment_from" . |
default "\n []" | indent 14 }}
+ env: {{- include "custom_airflow_environment" . | indent 14 }}
+ {{- else }}
env:
- {{- include "standard_airflow_environment" . | indent 12 }}
- {{- include "container_extra_envs" (list .
.Values.databaseCleanup.env) | indent 12 }}
+ {{- end }}
+ {{- include "standard_airflow_environment" . | indent 14 }}
+ {{- include "container_extra_envs" (list .
.Values.databaseCleanup.env) | indent 14 }}
volumeMounts:
{{- include "airflow_config_mount" . | nindent 16 }}
{{- if .Values.volumeMounts }}
diff --git a/chart/values.schema.json b/chart/values.schema.json
index 241efae75e0..1b33cc1e74a 100644
--- a/chart/values.schema.json
+++ b/chart/values.schema.json
@@ -9084,6 +9084,11 @@
"type": "boolean",
"default": false
},
+ "applyCustomEnv": {
+ "description": "Specify if you want additional configured
env vars applied to database cleanup job",
+ "type": "boolean",
+ "default": true
+ },
"schedule": {
"description": "Database cleanup schedule (templated).",
"type": "string",
diff --git a/chart/values.yaml b/chart/values.yaml
index 711fab53fad..d946a183443 100644
--- a/chart/values.yaml
+++ b/chart/values.yaml
@@ -2943,6 +2943,7 @@ cleanup:
# This runs as a CronJob to cleanup database for old entries.
databaseCleanup:
enabled: false
+ applyCustomEnv: true
# Run every week on Sunday at midnight (templated).
schedule: "0 0 * * 0"
# Command to use when running the database cleanup cronjob (templated).
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 2d449259461..315fd0db5ad 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
@@ -256,20 +256,29 @@ class TestDatabaseCleanup:
f'CLEAN_TS=$(date -d "-{retention} days" +"%Y-%m-%dT%H:%M:%S");
echo "Cleaning up metadata DB entries older than ${{CLEAN_TS}}"; exec airflow
db clean --clean-before-timestamp "${{CLEAN_TS}}" --yes{command_args}',
]
- def test_should_add_extraEnvs(self):
+ @pytest.mark.parametrize("cleanup_envs", [[], [{"name": "TEST_ENV_1",
"value": "test_env_1"}]])
+ @pytest.mark.parametrize("all_containers_envs", [[], [{"name":
"TEST_ENV_2", "value": "test_env_2"}]])
+ @pytest.mark.parametrize("custom_envs_enabled", [False, True])
+ def test_should_add_extraEnvs(self, cleanup_envs, all_containers_envs,
custom_envs_enabled):
docs = render_chart(
values={
+ "env": all_containers_envs,
+ "applyCustomEnv": custom_envs_enabled,
"databaseCleanup": {
"enabled": True,
- "env": [{"name": "TEST_ENV_1", "value": "test_env_1"}],
+ "env": cleanup_envs,
},
},
show_only=["templates/database-cleanup/database-cleanup-cronjob.yaml"],
)
-
- assert {"name": "TEST_ENV_1", "value": "test_env_1"} in
jmespath.search(
- "spec.jobTemplate.spec.template.spec.containers[0].env", docs[0]
- )
+ if cleanup_envs:
+ assert cleanup_envs[0] in jmespath.search(
+ "spec.jobTemplate.spec.template.spec.containers[0].env",
docs[0]
+ )
+ if all_containers_envs:
+ assert all_containers_envs[0] in jmespath.search(
+ "spec.jobTemplate.spec.template.spec.containers[0].env",
docs[0]
+ )
@pytest.mark.parametrize("command", [None, ["custom", "command"]])
@pytest.mark.parametrize("args", [None, ["custom", "args"]])
diff --git a/helm-tests/tests/helm_tests/airflow_aux/test_extra_env_env_from.py
b/helm-tests/tests/helm_tests/airflow_aux/test_extra_env_env_from.py
index 2d2b2d2a9d9..9d1e475449b 100644
--- a/helm-tests/tests/helm_tests/airflow_aux/test_extra_env_env_from.py
+++ b/helm-tests/tests/helm_tests/airflow_aux/test_extra_env_env_from.py
@@ -36,6 +36,10 @@ PARAMS = [
("Job", f"{RELEASE_NAME}-run-airflow-migrations"),
("spec.template.spec.containers[0]",),
),
+ (
+ ("CronJob", f"{RELEASE_NAME}-database-cleanup"),
+ ("spec.jobTemplate.spec.template.spec.containers[0]",),
+ ),
(
("Deployment", f"{RELEASE_NAME}-scheduler"),
(
@@ -82,6 +86,9 @@ class TestExtraEnvEnvFrom:
values_str = textwrap.dedent(
"""
airflowVersion: "2.6.0"
+ databaseCleanup:
+ enabled: true
+ applyCustomEnv: true
flower:
enabled: true
extraEnvFrom: |