This is an automated email from the ASF dual-hosted git repository.
eladkal 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 a84d07768f ADD git-sync container lifecycle hooks (#40369)
a84d07768f is described below
commit a84d07768f742bd639abec709442fc2e0aad048b
Author: Namgung Chan <[email protected]>
AuthorDate: Sun Jun 30 04:09:55 2024 +0900
ADD git-sync container lifecycle hooks (#40369)
* ADD git-sync container lifecycle hooks
* disable on git-sync-init container
* add unit test
* add unit test
* add global lifecycle hook condition
* make test pass
* disable .Values.containerLifecycleHooks
* pass static checks
---
chart/templates/_helpers.yaml | 3 +++
chart/values.yaml | 2 +-
helm_tests/other/test_git_sync_worker.py | 34 ++++++++++++++++++++++++++++++++
3 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/chart/templates/_helpers.yaml b/chart/templates/_helpers.yaml
index 641c0f77b6..7606e75084 100644
--- a/chart/templates/_helpers.yaml
+++ b/chart/templates/_helpers.yaml
@@ -309,6 +309,9 @@ If release name contains chart name it will be used as a
full name.
{{- if .Values.dags.gitSync.extraVolumeMounts }}
{{- tpl (toYaml .Values.dags.gitSync.extraVolumeMounts) . | nindent 2 }}
{{- end }}
+ {{- if and .Values.dags.gitSync.containerLifecycleHooks (not .is_init) }}
+ lifecycle: {{- tpl (toYaml .Values.dags.gitSync.containerLifecycleHooks) . |
nindent 4 }}
+ {{- end }}
{{- end }}
{{/* This helper will change when customers deploy a new image */}}
diff --git a/chart/values.yaml b/chart/values.yaml
index d59a79d1d7..e780032a89 100644
--- a/chart/values.yaml
+++ b/chart/values.yaml
@@ -57,7 +57,7 @@ securityContexts:
pod: {}
containers: {}
-# Default container lifecycle hooks for every service except for redis, statsd
and pgbouncer.
+# Global container lifecycle hooks for airflow containers
containerLifecycleHooks: {}
# Airflow home directory
diff --git a/helm_tests/other/test_git_sync_worker.py
b/helm_tests/other/test_git_sync_worker.py
index 9d0007b759..44613f5e8e 100644
--- a/helm_tests/other/test_git_sync_worker.py
+++ b/helm_tests/other/test_git_sync_worker.py
@@ -168,3 +168,37 @@ class TestGitSyncWorker:
"name": "git-sync-ssh-key",
"secret": {"secretName": "release-name-ssh-secret", "defaultMode":
288},
} in jmespath.search("spec.template.spec.volumes", docs[0])
+
+ def test_container_lifecycle_hooks(self):
+ docs = render_chart(
+ values={
+ "dags": {
+ "gitSync": {
+ "enabled": True,
+ "containerLifecycleHooks": {
+ "postStart": {
+ "exec": {
+ "command": [
+ "/bin/sh",
+ "-c",
+ "echo postStart handler >
/git/message_start",
+ ]
+ }
+ },
+ "preStop": {
+ "exec": {
+ "command": ["/bin/sh", "-c", "echo preStop
handler > /git/message_start"]
+ }
+ },
+ },
+ },
+ },
+ },
+ show_only=["templates/workers/worker-deployment.yaml"],
+ )
+ assert {
+ "postStart": {
+ "exec": {"command": ["/bin/sh", "-c", "echo postStart handler
> /git/message_start"]}
+ },
+ "preStop": {"exec": {"command": ["/bin/sh", "-c", "echo preStop
handler > /git/message_start"]}},
+ } == jmespath.search("spec.template.spec.containers[1].lifecycle",
docs[0])