You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by js...@apache.org on 2026/04/24 20:27:22 UTC
(airflow) branch main updated: Fix cleanup pod lifecycle hooks not being applied (#65764)
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 294dd5e7663 Fix cleanup pod lifecycle hooks not being applied (#65764)
294dd5e7663 is described below
commit 294dd5e7663687c796e245924a4a213ab7cf1849
Author: Henry Chen <he...@gmail.com>
AuthorDate: Sat Apr 25 04:27:15 2026 +0800
Fix cleanup pod lifecycle hooks not being applied (#65764)
---
chart/templates/cleanup/cleanup-cronjob.yaml | 4 ++
.../helm_tests/airflow_aux/test_cleanup_pods.py | 44 ++++++++++++++++++++++
2 files changed, 48 insertions(+)
diff --git a/chart/templates/cleanup/cleanup-cronjob.yaml b/chart/templates/cleanup/cleanup-cronjob.yaml
index ae202fddde5..70cb53862d1 100644
--- a/chart/templates/cleanup/cleanup-cronjob.yaml
+++ b/chart/templates/cleanup/cleanup-cronjob.yaml
@@ -27,6 +27,7 @@
{{- $topologySpreadConstraints := or .Values.cleanup.topologySpreadConstraints .Values.topologySpreadConstraints }}
{{- $securityContext := include "airflowPodSecurityContext" (list .Values.cleanup .Values) }}
{{- $containerSecurityContext := include "containerSecurityContext" (list .Values.cleanup .Values) }}
+{{- $containerLifecycleHooks := or .Values.cleanup.containerLifecycleHooks .Values.containerLifecycleHooks }}
apiVersion: batch/v1
kind: CronJob
metadata:
@@ -92,6 +93,9 @@ spec:
image: {{ template "airflow_image" . }}
imagePullPolicy: {{ .Values.images.airflow.pullPolicy }}
securityContext: {{ $containerSecurityContext | nindent 16 }}
+ {{- if $containerLifecycleHooks }}
+ lifecycle: {{- tpl (toYaml $containerLifecycleHooks) . | nindent 16 }}
+ {{- end }}
{{- if .Values.cleanup.command }}
command: {{ tpl (toYaml .Values.cleanup.command) . | nindent 16 }}
{{- end }}
diff --git a/helm-tests/tests/helm_tests/airflow_aux/test_cleanup_pods.py b/helm-tests/tests/helm_tests/airflow_aux/test_cleanup_pods.py
index 31006e52625..11c42d54202 100644
--- a/helm-tests/tests/helm_tests/airflow_aux/test_cleanup_pods.py
+++ b/helm-tests/tests/helm_tests/airflow_aux/test_cleanup_pods.py
@@ -228,6 +228,50 @@ class TestCleanupPods:
"exec airflow kubernetes cleanup-pods --namespace=default",
]
+ @pytest.mark.parametrize(
+ "values",
+ [
+ pytest.param(
+ {
+ "cleanup": {
+ "enabled": True,
+ "containerLifecycleHooks": {"preStop": {"exec": {"command": ["echo", "cleanup"]}}},
+ },
+ },
+ id="component",
+ ),
+ pytest.param(
+ {
+ "cleanup": {"enabled": True},
+ "containerLifecycleHooks": {"preStop": {"exec": {"command": ["echo", "cleanup"]}}},
+ },
+ id="global-fallback",
+ ),
+ pytest.param(
+ {
+ "cleanup": {
+ "enabled": True,
+ "containerLifecycleHooks": {"preStop": {"exec": {"command": ["echo", "cleanup"]}}},
+ },
+ "containerLifecycleHooks": {"postStart": {"exec": {"command": ["echo", "global"]}}},
+ },
+ id="component-overrides-global",
+ ),
+ ],
+ )
+ def test_should_render_container_lifecycle_hooks(self, values):
+ docs = render_chart(
+ values={
+ "executor": "KubernetesExecutor",
+ **values,
+ },
+ show_only=["templates/cleanup/cleanup-cronjob.yaml"],
+ )
+
+ assert jmespath.search("spec.jobTemplate.spec.template.spec.containers[0].lifecycle", docs[0]) == {
+ "preStop": {"exec": {"command": ["echo", "cleanup"]}}
+ }
+
def test_should_add_extraEnvs(self):
docs = render_chart(
values={