Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADD git-sync container lifecycle hooks #40369

Merged
merged 10 commits into from
Jun 29, 2024
3 changes: 3 additions & 0 deletions chart/templates/_helpers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 */}}
Expand Down
2 changes: 1 addition & 1 deletion chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions helm_tests/other/test_git_sync_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,40 @@ def test_validate_if_ssh_params_are_added_with_git_ssh_key(self):
"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])