This is an automated email from the ASF dual-hosted git repository.
jedcunningham 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 dbc068c7f9 Properly implement termination grace period seconds (#41374)
dbc068c7f9 is described below
commit dbc068c7f9fe3326bcf8fb5c5b2ca236969e113d
Author: Ryan Eakman <[email protected]>
AuthorDate: Tue Aug 13 17:48:33 2024 -0700
Properly implement termination grace period seconds (#41374)
---
chart/templates/redis/redis-statefulset.yaml | 1 +
chart/templates/scheduler/scheduler-deployment.yaml | 2 +-
chart/templates/statsd/statsd-deployment.yaml | 1 +
chart/templates/webserver/webserver-deployment.yaml | 1 +
chart/values.schema.json | 15 +++++++++++++++
chart/values.yaml | 9 +++++++++
helm_tests/airflow_core/test_scheduler.py | 14 ++++++++++++++
helm_tests/other/test_redis.py | 14 ++++++++++++++
helm_tests/other/test_statsd.py | 14 ++++++++++++++
helm_tests/webserver/test_webserver.py | 14 ++++++++++++++
10 files changed, 84 insertions(+), 1 deletion(-)
diff --git a/chart/templates/redis/redis-statefulset.yaml
b/chart/templates/redis/redis-statefulset.yaml
index cbc504e0a5..db98f0bf4d 100644
--- a/chart/templates/redis/redis-statefulset.yaml
+++ b/chart/templates/redis/redis-statefulset.yaml
@@ -77,6 +77,7 @@ spec:
affinity: {{- toYaml $affinity | nindent 8 }}
tolerations: {{- toYaml $tolerations | nindent 8 }}
topologySpreadConstraints: {{- toYaml $topologySpreadConstraints |
nindent 8 }}
+ terminationGracePeriodSeconds: {{
.Values.redis.terminationGracePeriodSeconds }}
serviceAccountName: {{ include "redis.serviceAccountName" . }}
{{- if .Values.schedulerName }}
schedulerName: {{ .Values.schedulerName }}
diff --git a/chart/templates/scheduler/scheduler-deployment.yaml
b/chart/templates/scheduler/scheduler-deployment.yaml
index ac1e2a8240..634c3a41f7 100644
--- a/chart/templates/scheduler/scheduler-deployment.yaml
+++ b/chart/templates/scheduler/scheduler-deployment.yaml
@@ -131,7 +131,7 @@ spec:
tolerations: {{- toYaml $tolerations | nindent 8 }}
topologySpreadConstraints: {{- toYaml $topologySpreadConstraints |
nindent 8 }}
restartPolicy: Always
- terminationGracePeriodSeconds: 10
+ terminationGracePeriodSeconds: {{
.Values.scheduler.terminationGracePeriodSeconds }}
serviceAccountName: {{ include "scheduler.serviceAccountName" . }}
securityContext: {{ $securityContext | nindent 8 }}
{{- if or .Values.registry.secretName .Values.registry.connection }}
diff --git a/chart/templates/statsd/statsd-deployment.yaml
b/chart/templates/statsd/statsd-deployment.yaml
index dd7723f302..b97c98d2af 100644
--- a/chart/templates/statsd/statsd-deployment.yaml
+++ b/chart/templates/statsd/statsd-deployment.yaml
@@ -82,6 +82,7 @@ spec:
schedulerName: {{ .Values.schedulerName }}
{{- end }}
topologySpreadConstraints: {{- toYaml $topologySpreadConstraints |
nindent 8 }}
+ terminationGracePeriodSeconds: {{
.Values.statsd.terminationGracePeriodSeconds }}
serviceAccountName: {{ include "statsd.serviceAccountName" . }}
securityContext: {{ $securityContext | nindent 8 }}
restartPolicy: Always
diff --git a/chart/templates/webserver/webserver-deployment.yaml
b/chart/templates/webserver/webserver-deployment.yaml
index 45095a28e6..5e1af94012 100644
--- a/chart/templates/webserver/webserver-deployment.yaml
+++ b/chart/templates/webserver/webserver-deployment.yaml
@@ -127,6 +127,7 @@ spec:
tolerations: {{- toYaml $tolerations | nindent 8 }}
topologySpreadConstraints: {{- toYaml $topologySpreadConstraints |
nindent 8 }}
restartPolicy: Always
+ terminationGracePeriodSeconds: {{
.Values.webserver.terminationGracePeriodSeconds }}
securityContext: {{ $securityContext | nindent 8 }}
{{- if or .Values.registry.secretName .Values.registry.connection }}
imagePullSecrets:
diff --git a/chart/values.schema.json b/chart/values.schema.json
index bec09a84bf..67192925d0 100644
--- a/chart/values.schema.json
+++ b/chart/values.schema.json
@@ -2404,6 +2404,11 @@
],
"default": null
},
+ "terminationGracePeriodSeconds": {
+ "description": "Grace period for scheduler to finish after
SIGTERM is sent from Kubernetes.",
+ "type": "integer",
+ "default": 10
+ },
"serviceAccount": {
"description": "Create ServiceAccount.",
"type": "object",
@@ -5363,6 +5368,11 @@
],
"default": null
},
+ "terminationGracePeriodSeconds": {
+ "description": "Grace period for webserver to finish after
SIGTERM is sent from Kubernetes.",
+ "type": "integer",
+ "default": 30
+ },
"serviceAccount": {
"description": "Create ServiceAccount.",
"type": "object",
@@ -6546,6 +6556,11 @@
}
}
},
+ "terminationGracePeriodSeconds": {
+ "description": "Grace period for statsd to finish after
SIGTERM is sent from Kubernetes.",
+ "type": "integer",
+ "default": 30
+ },
"serviceAccount": {
"description": "Create ServiceAccount.",
"type": "object",
diff --git a/chart/values.yaml b/chart/values.yaml
index 9d8794f3db..1164d4d998 100644
--- a/chart/values.yaml
+++ b/chart/values.yaml
@@ -863,6 +863,9 @@ scheduler:
# container level lifecycle hooks
containerLifecycleHooks: {}
+ # Grace period for tasks to finish after SIGTERM is sent from kubernetes
+ terminationGracePeriodSeconds: 10
+
# Create ServiceAccount
serviceAccount:
# default value is true
@@ -1324,6 +1327,9 @@ webserver:
# Args to use when running the Airflow webserver (templated).
args: ["bash", "-c", "exec airflow webserver"]
+ # Grace period for webserver to finish after SIGTERM is sent from kubernetes
+ terminationGracePeriodSeconds: 30
+
# Create ServiceAccount
serviceAccount:
# default value is true
@@ -1992,6 +1998,9 @@ statsd:
# Annotations to add to the StatsD Deployment.
annotations: {}
+ # Grace period for statsd to finish after SIGTERM is sent from kubernetes
+ terminationGracePeriodSeconds: 30
+
# Create ServiceAccount
serviceAccount:
# default value is true
diff --git a/helm_tests/airflow_core/test_scheduler.py
b/helm_tests/airflow_core/test_scheduler.py
index a329b833a4..8968cd7c2c 100644
--- a/helm_tests/airflow_core/test_scheduler.py
+++ b/helm_tests/airflow_core/test_scheduler.py
@@ -857,6 +857,20 @@ class TestScheduler:
"whenDeleted": "Delete",
} == jmespath.search("spec.persistentVolumeClaimRetentionPolicy",
docs[0])
+ @pytest.mark.parametrize(
+ "scheduler_values, expected",
+ [
+ ({}, 10),
+ ({"scheduler": {"terminationGracePeriodSeconds": 1200}}, 1200),
+ ],
+ )
+ def test_scheduler_termination_grace_period_seconds(self,
scheduler_values, expected):
+ docs = render_chart(
+ values=scheduler_values,
+ show_only=["templates/scheduler/scheduler-deployment.yaml"],
+ )
+ assert expected ==
jmespath.search("spec.template.spec.terminationGracePeriodSeconds", docs[0])
+
class TestSchedulerNetworkPolicy:
"""Tests scheduler network policy."""
diff --git a/helm_tests/other/test_redis.py b/helm_tests/other/test_redis.py
index d6b34d5ee2..b32dd71d11 100644
--- a/helm_tests/other/test_redis.py
+++ b/helm_tests/other/test_redis.py
@@ -403,6 +403,20 @@ class TestRedis:
"spec.volumeClaimTemplates[0].spec.storageClassName", docs[0]
)
+ @pytest.mark.parametrize(
+ "redis_values, expected",
+ [
+ ({}, 600),
+ ({"redis": {"terminationGracePeriodSeconds": 1200}}, 1200),
+ ],
+ )
+ def test_redis_termination_grace_period_seconds(self, redis_values,
expected):
+ docs = render_chart(
+ values=redis_values,
+ show_only=["templates/redis/redis-statefulset.yaml"],
+ )
+ assert expected ==
jmespath.search("spec.template.spec.terminationGracePeriodSeconds", docs[0])
+
class TestRedisServiceAccount:
"""Tests redis service account."""
diff --git a/helm_tests/other/test_statsd.py b/helm_tests/other/test_statsd.py
index a2f4b870bd..2d9e29bc40 100644
--- a/helm_tests/other/test_statsd.py
+++ b/helm_tests/other/test_statsd.py
@@ -337,6 +337,20 @@ class TestStatsd:
assert "annotations" in jmespath.search("metadata", docs)
assert jmespath.search("metadata.annotations",
docs)["test_annotation"] == "test_annotation_value"
+ @pytest.mark.parametrize(
+ "statsd_values, expected",
+ [
+ ({}, 30),
+ ({"statsd": {"terminationGracePeriodSeconds": 1200}}, 1200),
+ ],
+ )
+ def test_statsd_termination_grace_period_seconds(self, statsd_values,
expected):
+ docs = render_chart(
+ values=statsd_values,
+ show_only=["templates/statsd/statsd-deployment.yaml"],
+ )
+ assert expected ==
jmespath.search("spec.template.spec.terminationGracePeriodSeconds", docs[0])
+
class TestStatsdServiceAccount:
"""Tests statsd service account."""
diff --git a/helm_tests/webserver/test_webserver.py
b/helm_tests/webserver/test_webserver.py
index 3d34804211..5f7f0b4abb 100644
--- a/helm_tests/webserver/test_webserver.py
+++ b/helm_tests/webserver/test_webserver.py
@@ -864,6 +864,20 @@ class TestWebserverDeployment:
assert "annotations" in jmespath.search("metadata", docs[0])
assert jmespath.search("metadata.annotations",
docs[0])["test_annotation"] == "test_annotation_value"
+ @pytest.mark.parametrize(
+ "webserver_values, expected",
+ [
+ ({}, 30),
+ ({"webserver": {"terminationGracePeriodSeconds": 1200}}, 1200),
+ ],
+ )
+ def test_webserver_termination_grace_period_seconds(self,
webserver_values, expected):
+ docs = render_chart(
+ values=webserver_values,
+ show_only=["templates/webserver/webserver-deployment.yaml"],
+ )
+ assert expected ==
jmespath.search("spec.template.spec.terminationGracePeriodSeconds", docs[0])
+
class TestWebserverService:
"""Tests webserver service."""