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

Miretpl 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 1195d1b11cc Add terminationGracePeriodSeconds to the Celery worker 
liveness probe (#76749)
1195d1b11cc is described below

commit 1195d1b11ccd7178d09960a9ea47ab005983c540
Author: Sebastian Daberdaku <[email protected]>
AuthorDate: Sun Nov 15 12:30:22 2026 +0100

    Add terminationGracePeriodSeconds to the Celery worker liveness probe 
(#76749)
    
    Kubernetes applies a pod's terminationGracePeriodSeconds to every kill of
    the container, a liveness-probe restart included. Celery workers commonly
    set that period to hours so that a rolling update drains the tasks they
    are running, which turns a liveness restart into an hours-long wait on a
    worker that stopped answering pings: Celery goes into warm shutdown on
    the SIGTERM and waits for in-flight or hung tasks, and kubelet waits the
    full grace period before SIGKILL. Meanwhile nothing consumes the queue.
    
    Probes carry their own terminationGracePeriodSeconds since Kubernetes
    1.25, scoped to kills the probe triggers. Expose it as
    workers.celery.livenessProbe.terminationGracePeriodSeconds, unset by
    default so existing deployments render exactly as before. Kubernetes
    rejects a probe-level value below 1, so the schema rejects it at install
    time instead.
    
    Co-authored-by: Przemysław Mirowski 
<[email protected]>
---
 chart/templates/workers/worker-deployment.yaml     |  3 +++
 chart/tests/helm_tests/airflow_core/test_worker.py | 30 ++++++++++++++++++++++
 chart/values.schema.json                           |  9 +++++++
 chart/values.yaml                                  |  1 +
 4 files changed, 43 insertions(+)

diff --git a/chart/templates/workers/worker-deployment.yaml 
b/chart/templates/workers/worker-deployment.yaml
index 78a6fac473f..661a801862d 100644
--- a/chart/templates/workers/worker-deployment.yaml
+++ b/chart/templates/workers/worker-deployment.yaml
@@ -299,6 +299,9 @@ spec:
             timeoutSeconds: {{ 
.Values.workers.celery.livenessProbe.timeoutSeconds }}
             failureThreshold: {{ 
.Values.workers.celery.livenessProbe.failureThreshold }}
             periodSeconds: {{ 
.Values.workers.celery.livenessProbe.periodSeconds }}
+            {{- if 
.Values.workers.celery.livenessProbe.terminationGracePeriodSeconds }}
+            terminationGracePeriodSeconds: {{ 
.Values.workers.celery.livenessProbe.terminationGracePeriodSeconds }}
+            {{- end }}
             exec:
               command:
                 {{- if .Values.workers.celery.livenessProbe.command }}
diff --git a/chart/tests/helm_tests/airflow_core/test_worker.py 
b/chart/tests/helm_tests/airflow_core/test_worker.py
index e09e51dd19e..db3db65f2b2 100644
--- a/chart/tests/helm_tests/airflow_core/test_worker.py
+++ b/chart/tests/helm_tests/airflow_core/test_worker.py
@@ -730,6 +730,36 @@ class TestWorker:
         livenessprobe = 
jmespath.search("spec.template.spec.containers[0].livenessProbe", docs[0])
         assert livenessprobe is None
 
+    def test_livenessprobe_termination_grace_period_unset_by_default(self):
+        docs = 
render_chart(show_only=["templates/workers/worker-deployment.yaml"])
+
+        assert (
+            jmespath.search(
+                
"spec.template.spec.containers[0].livenessProbe.terminationGracePeriodSeconds", 
docs[0]
+            )
+            is None
+        )
+
+    def test_livenessprobe_termination_grace_period(self):
+        docs = render_chart(
+            values={"workers": {"celery": {"livenessProbe": 
{"terminationGracePeriodSeconds": 120}}}},
+            show_only=["templates/workers/worker-deployment.yaml"],
+        )
+
+        assert (
+            jmespath.search(
+                
"spec.template.spec.containers[0].livenessProbe.terminationGracePeriodSeconds", 
docs[0]
+            )
+            == 120
+        )
+
+    def test_livenessprobe_termination_grace_period_rejects_zero(self):
+        with pytest.raises(HelmFailedError):
+            render_chart(
+                values={"workers": {"celery": {"livenessProbe": 
{"terminationGracePeriodSeconds": 0}}}},
+                show_only=["templates/workers/worker-deployment.yaml"],
+            )
+
     def test_extra_init_container_restart_policy_is_configurable(self):
         docs = render_chart(
             values={
diff --git a/chart/values.schema.json b/chart/values.schema.json
index ab3ce8c0b3a..ad7fd9aebd6 100644
--- a/chart/values.schema.json
+++ b/chart/values.schema.json
@@ -1747,6 +1747,15 @@
                                     "items": {
                                         "type": "string"
                                     }
+                                },
+                                "terminationGracePeriodSeconds": {
+                                    "description": "Grace period, in seconds, 
for a kill triggered by this probe. Overrides the pod's 
`terminationGracePeriodSeconds` for liveness kills only. If set, minimum value 
is 1.",
+                                    "type": [
+                                        "integer",
+                                        "null"
+                                    ],
+                                    "default": null,
+                                    "minimum": 1
                                 }
                             }
                         },
diff --git a/chart/values.yaml b/chart/values.yaml
index 7895d99894a..dab6066525f 100644
--- a/chart/values.yaml
+++ b/chart/values.yaml
@@ -646,6 +646,7 @@ workers:
       failureThreshold: 5
       periodSeconds: 60
       command: ~
+      terminationGracePeriodSeconds: ~
 
     # Enable the default workers defined by the root `workers` and 
`workers.celery`
     # configurations to be created.

Reply via email to