Skip to content

Commit 80d25f0

Browse files
committed
Add workers.celery.terminationGracePeriodSeconds & workers.kubernetes.terminationGracePeriodSeconds
1 parent 1520bde commit 80d25f0

6 files changed

Lines changed: 77 additions & 21 deletions

File tree

chart/files/pod-template-file.kubernetes-helm-yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ spec:
233233
{{- if $schedulerName }}
234234
schedulerName: {{ $schedulerName }}
235235
{{- end }}
236-
terminationGracePeriodSeconds: {{ .Values.workers.terminationGracePeriodSeconds }}
236+
terminationGracePeriodSeconds: {{ .Values.workers.kubernetes.terminationGracePeriodSeconds | default .Values.workers.terminationGracePeriodSeconds }}
237237
tolerations: {{- toYaml $tolerations | nindent 4 }}
238238
topologySpreadConstraints: {{- toYaml $topologySpreadConstraints | nindent 4 }}
239239
serviceAccountName: {{ include "worker.serviceAccountName" . }}

chart/values.schema.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2282,7 +2282,7 @@
22822282
"$ref": "#/definitions/io.k8s.api.core.v1.ResourceRequirements"
22832283
},
22842284
"terminationGracePeriodSeconds": {
2285-
"description": "Grace period for tasks to finish after SIGTERM is sent from Kubernetes. It is used by Airflow Celery workers and pod-template-file.",
2285+
"description": "Grace period for tasks to finish after SIGTERM is sent from Kubernetes. It is used by Airflow Celery workers and pod-template-file. Use ``workers.celery.terminationGracePeriodSeconds`` and/or ``workers.kubernetes.terminationGracePeriodSeconds`` to separate value between Celery workers and pod-template-file",
22862286
"type": "integer",
22872287
"default": 600
22882288
},
@@ -3275,6 +3275,14 @@
32753275
}
32763276
],
32773277
"$ref": "#/definitions/io.k8s.api.core.v1.ResourceRequirements"
3278+
},
3279+
"terminationGracePeriodSeconds": {
3280+
"description": "Grace period for tasks to finish after SIGTERM is sent from Kubernetes.",
3281+
"type": [
3282+
"integer",
3283+
"null"
3284+
],
3285+
"default": null
32783286
}
32793287
}
32803288
},
@@ -3548,6 +3556,14 @@
35483556
}
35493557
],
35503558
"$ref": "#/definitions/io.k8s.api.core.v1.ResourceRequirements"
3559+
},
3560+
"terminationGracePeriodSeconds": {
3561+
"description": "Grace period for tasks to finish after SIGTERM is sent from Kubernetes.",
3562+
"type": [
3563+
"integer",
3564+
"null"
3565+
],
3566+
"default": null
35513567
}
35523568
}
35533569
}

chart/values.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,8 @@ workers:
909909

910910
# Grace period for tasks to finish after SIGTERM is sent from kubernetes.
911911
# It is used by Airflow Celery workers and pod-template-file.
912+
# Use workers.celery.terminationGracePeriodSeconds and/or workers.kubernetes.terminationGracePeriodSeconds
913+
# to separate value between Celery workers and pod-template-file
912914
terminationGracePeriodSeconds: 600
913915

914916
# This setting tells kubernetes that its ok to evict when it wants to scale a node down.
@@ -1262,6 +1264,9 @@ workers:
12621264
# cpu: 100m
12631265
# memory: 128Mi
12641266

1267+
# Grace period for tasks to finish after SIGTERM is sent from kubernetes
1268+
terminationGracePeriodSeconds: ~
1269+
12651270
kubernetes:
12661271
# Command to use in pod-template-file (templated)
12671272
command: ~
@@ -1326,6 +1331,9 @@ workers:
13261331
# cpu: 100m
13271332
# memory: 128Mi
13281333

1334+
# Grace period for tasks to finish after SIGTERM is sent from kubernetes
1335+
terminationGracePeriodSeconds: ~
1336+
13291337
# Airflow scheduler settings
13301338
scheduler:
13311339
enabled: true

helm-tests/tests/helm_tests/airflow_aux/test_pod_template_file.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,13 +1114,17 @@ def test_workers_container_lifecycle_webhooks_are_configurable(self, workers_val
11141114
"preStop": {"exec": {"command": ["echo", "preStop", "test-release"]}}
11151115
}
11161116

1117-
def test_termination_grace_period_seconds(self):
1117+
@pytest.mark.parametrize(
1118+
"workers_values",
1119+
[
1120+
{"terminationGracePeriodSeconds": 123},
1121+
{"kubernetes": {"terminationGracePeriodSeconds": 123}},
1122+
{"terminationGracePeriodSeconds": 1, "kubernetes": {"terminationGracePeriodSeconds": 123}},
1123+
],
1124+
)
1125+
def test_termination_grace_period_seconds(self, workers_values):
11181126
docs = render_chart(
1119-
values={
1120-
"workers": {
1121-
"terminationGracePeriodSeconds": 123,
1122-
},
1123-
},
1127+
values={"workers": workers_values},
11241128
show_only=["templates/pod-template-file.yaml"],
11251129
chart_dir=self.temp_chart_dir,
11261130
)

helm-tests/tests/helm_tests/airflow_core/test_worker.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,6 +1721,21 @@ def test_pod_management_policy_not_valid_value(self, workers_values):
17211721
values={"workers": workers_values}, show_only=["templates/workers/worker-deployment.yaml"]
17221722
)
17231723

1724+
@pytest.mark.parametrize(
1725+
"workers_values",
1726+
[
1727+
{"terminationGracePeriodSeconds": 5},
1728+
{"celery": {"terminationGracePeriodSeconds": 5}},
1729+
{"terminationGracePeriodSeconds": 10, "celery": {"terminationGracePeriodSeconds": 5}},
1730+
],
1731+
)
1732+
def test_termination_grace_period(self, workers_values):
1733+
docs = render_chart(
1734+
values={"workers": workers_values}, show_only=["templates/workers/worker-deployment.yaml"]
1735+
)
1736+
1737+
assert jmespath.search("spec.template.spec.terminationGracePeriodSeconds", docs[0]) == 5
1738+
17241739

17251740
class TestWorkerLogGroomer(LogGroomerTestBase):
17261741
"""Worker groomer."""

helm-tests/tests/helm_tests/airflow_core/test_worker_sets.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,21 +2177,34 @@ def test_overwrite_resources(self, values):
21772177
"limits": {"cpu": "3m", "memory": "4Mi"},
21782178
}
21792179

2180-
def test_overwrite_termination_grace_period_seconds(self):
2181-
docs = render_chart(
2182-
values={
2183-
"workers": {
2184-
"celery": {
2185-
"enableDefault": False,
2186-
"sets": [
2187-
{
2188-
"name": "test",
2189-
"terminationGracePeriodSeconds": 5,
2190-
}
2191-
],
2192-
},
2180+
@pytest.mark.parametrize(
2181+
"workers_values",
2182+
[
2183+
{
2184+
"celery": {
2185+
"enableDefault": False,
2186+
"sets": [{"name": "test", "terminationGracePeriodSeconds": 5}],
21932187
}
21942188
},
2189+
{
2190+
"terminationGracePeriodSeconds": 20,
2191+
"celery": {
2192+
"enableDefault": False,
2193+
"sets": [{"name": "test", "terminationGracePeriodSeconds": 5}],
2194+
},
2195+
},
2196+
{
2197+
"celery": {
2198+
"terminationGracePeriodSeconds": 20,
2199+
"enableDefault": False,
2200+
"sets": [{"name": "test", "terminationGracePeriodSeconds": 5}],
2201+
}
2202+
},
2203+
],
2204+
)
2205+
def test_overwrite_termination_grace_period_seconds(self, workers_values):
2206+
docs = render_chart(
2207+
values={"workers": workers_values},
21952208
show_only=["templates/workers/worker-deployment.yaml"],
21962209
)
21972210

0 commit comments

Comments
 (0)