Skip to content

Commit c8c39f2

Browse files
committed
Add workers.celery.extraInitContainers & workers.kubernetes.extraInitContainers
1 parent 910db93 commit c8c39f2

8 files changed

Lines changed: 135 additions & 33 deletions

File tree

chart/docs/using-additional-containers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Init Containers
5252
---------------
5353

5454
You can also deploy extra init containers through the ``extraInitContainers`` parameter.
55-
You can define different containers for the scheduler, webserver, api server, worker, triggerer, dag processor, create user job and migrate database job pods.
55+
You can define different containers for the scheduler, webserver/api-server, Celery/Kubernetes workers, triggerer, dag processor, create user job and migrate database job pods.
5656

5757
For example, an init container that just says hello:
5858

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ spec:
5252
{{- if and .Values.dags.gitSync.enabled (not .Values.dags.persistence.enabled) }}
5353
{{- include "git_sync_container" (dict "Values" .Values "is_init" "true" "Template" .Template) | nindent 4 }}
5454
{{- end }}
55-
{{- if .Values.workers.extraInitContainers }}
56-
{{- tpl (toYaml .Values.workers.extraInitContainers) . | nindent 4 }}
55+
{{- if or .Values.workers.kubernetes.extraInitContainers .Values.workers.extraInitContainers }}
56+
{{- tpl (toYaml (.Values.workers.kubernetes.extraInitContainers | default .Values.workers.extraInitContainers)) . | nindent 4 }}
5757
{{- end }}
5858
{{- if or .Values.workers.kubernetes.kerberosInitContainer.enabled .Values.workers.kerberosInitContainer.enabled }}
5959
- name: kerberos-init

chart/templates/NOTES.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,14 @@ DEPRECATION WARNING:
709709

710710
{{- end }}
711711

712+
{{- if not (empty .Values.workers.extraInitContainers) }}
713+
714+
DEPRECATION WARNING:
715+
`workers.extraInitContainers` has been renamed to `workers.celery.extraInitContainers`/`workers.kubernetes.extraInitContainers`.
716+
Please change your values as support for the old name will be dropped in a future release.
717+
718+
{{- end }}
719+
712720
{{- if not (empty .Values.workers.runtimeClassName) }}
713721

714722
DEPRECATION WARNING:

chart/values.schema.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2301,7 +2301,7 @@
23012301
}
23022302
},
23032303
"extraInitContainers": {
2304-
"description": "Add additional init containers into Airflow Celery workers and pods created with pod-template-file (templated).",
2304+
"description": "Add additional init containers into Airflow Celery workers and pods created with pod-template-file (templated) (deprecated, use ``workers.celery.extraInitContainers`` and/or ``workers.kubernetes.extraInitContainers`` instead).",
23052305
"type": "array",
23062306
"default": [],
23072307
"items": {
@@ -3388,6 +3388,14 @@
33883388
"$ref": "#/definitions/io.k8s.api.core.v1.Container"
33893389
}
33903390
},
3391+
"extraInitContainers": {
3392+
"description": "Add additional init containers into Airflow Celery workers (templated).",
3393+
"type": "array",
3394+
"default": [],
3395+
"items": {
3396+
"$ref": "#/definitions/io.k8s.api.core.v1.Container"
3397+
}
3398+
},
33913399
"extraPorts": {
33923400
"description": "Expose additional ports of Airflow Celery worker container.",
33933401
"type": "array",
@@ -3886,6 +3894,14 @@
38863894
"$ref": "#/definitions/io.k8s.api.core.v1.Container"
38873895
}
38883896
},
3897+
"extraInitContainers": {
3898+
"description": "Add additional init containers into pods created with pod-template-file (templated).",
3899+
"type": "array",
3900+
"default": [],
3901+
"items": {
3902+
"$ref": "#/definitions/io.k8s.api.core.v1.Container"
3903+
}
3904+
},
38893905
"nodeSelector": {
38903906
"description": "Select certain nodes for pods created with pod-template-file.",
38913907
"type": "object",

chart/values.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,10 @@ workers:
10521052

10531053
# Add additional init containers into Airflow Celery workers
10541054
# and pods created with pod-template-file (templated).
1055+
# (deprecated, use
1056+
# `workers.celery.extraInitContainers` and/or
1057+
# `workers.kubernetes.extraInitContainers`
1058+
# instead)
10551059
extraInitContainers: []
10561060

10571061
# Additional volumes and volume mounts attached to the
@@ -1450,6 +1454,9 @@ workers:
14501454
# Launch additional containers into Airflow Celery worker (templated)
14511455
extraContainers: []
14521456

1457+
# Add additional init containers into Airflow Celery workers (templated)
1458+
extraInitContainers: []
1459+
14531460
# Expose additional ports of Airflow Celery workers. These can be used for additional metric collection.
14541461
extraPorts: []
14551462

@@ -1617,6 +1624,9 @@ workers:
16171624
# container finishes so Airflow can continue the worker shutdown process!
16181625
extraContainers: []
16191626

1627+
# Add additional init containers into pods created with pod-template-file (templated)
1628+
extraInitContainers: []
1629+
16201630
# Select certain nodes for pods created with pod-template-file
16211631
nodeSelector: {}
16221632

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

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,15 +1067,34 @@ def test_airflow_and_workers_pod_annotations(self):
10671067
assert "my_annotation" in annotations
10681068
assert "workerPodAnnotations" in annotations["my_annotation"]
10691069

1070-
def test_should_add_extra_init_containers(self):
1071-
docs = render_chart(
1072-
values={
1073-
"workers": {
1070+
@pytest.mark.parametrize(
1071+
"workers_values",
1072+
[
1073+
{
1074+
"extraInitContainers": [
1075+
{"name": "test-init-container", "image": "test-registry/test-repo:test-tag"}
1076+
]
1077+
},
1078+
{
1079+
"kubernetes": {
10741080
"extraInitContainers": [
10751081
{"name": "test-init-container", "image": "test-registry/test-repo:test-tag"}
1076-
],
1082+
]
1083+
}
1084+
},
1085+
{
1086+
"extraInitContainers": [{"name": "test", "image": "repo:tag"}],
1087+
"kubernetes": {
1088+
"extraInitContainers": [
1089+
{"name": "test-init-container", "image": "test-registry/test-repo:test-tag"}
1090+
]
10771091
},
10781092
},
1093+
],
1094+
)
1095+
def test_should_add_extra_init_containers(self, workers_values):
1096+
docs = render_chart(
1097+
values={"workers": workers_values},
10791098
show_only=["templates/pod-template-file.yaml"],
10801099
chart_dir=self.temp_chart_dir,
10811100
)
@@ -1087,13 +1106,20 @@ def test_should_add_extra_init_containers(self):
10871106
}
10881107
]
10891108

1090-
def test_should_template_extra_init_containers(self):
1091-
docs = render_chart(
1092-
values={
1093-
"workers": {
1094-
"extraInitContainers": [{"name": "{{ .Release.Name }}-test-init-container"}],
1095-
},
1109+
@pytest.mark.parametrize(
1110+
"workers_values",
1111+
[
1112+
{"extraInitContainers": [{"name": "{{ .Release.Name }}-test-init-container"}]},
1113+
{"kubernetes": {"extraInitContainers": [{"name": "{{ .Release.Name }}-test-init-container"}]}},
1114+
{
1115+
"extraInitContainers": [{"name": "container"}],
1116+
"kubernetes": {"extraInitContainers": [{"name": "{{ .Release.Name }}-test-init-container"}]},
10961117
},
1118+
],
1119+
)
1120+
def test_should_template_extra_init_containers(self, workers_values):
1121+
docs = render_chart(
1122+
values={"workers": workers_values},
10971123
show_only=["templates/pod-template-file.yaml"],
10981124
chart_dir=self.temp_chart_dir,
10991125
)

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

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,34 @@ def test_logs_mount_on_wait_for_migrations_initcontainer(self, logs_values, expe
279279
for m in mounts
280280
)
281281

282-
def test_should_add_extra_init_containers(self):
283-
docs = render_chart(
284-
values={
285-
"workers": {
282+
@pytest.mark.parametrize(
283+
"workers_values",
284+
[
285+
{
286+
"extraInitContainers": [
287+
{"name": "test-init-container", "image": "test-registry/test-repo:test-tag"}
288+
]
289+
},
290+
{
291+
"celery": {
286292
"extraInitContainers": [
287293
{"name": "test-init-container", "image": "test-registry/test-repo:test-tag"}
288-
],
294+
]
295+
}
296+
},
297+
{
298+
"extraInitContainers": [{"name": "container", "image": "repo:tag"}],
299+
"celery": {
300+
"extraInitContainers": [
301+
{"name": "test-init-container", "image": "test-registry/test-repo:test-tag"}
302+
]
289303
},
290304
},
305+
],
306+
)
307+
def test_should_add_extra_init_containers(self, workers_values):
308+
docs = render_chart(
309+
values={"workers": workers_values},
291310
show_only=["templates/workers/worker-deployment.yaml"],
292311
)
293312

@@ -299,13 +318,20 @@ def test_should_add_extra_init_containers(self):
299318
}
300319
]
301320

302-
def test_should_template_extra_init_containers(self):
303-
docs = render_chart(
304-
values={
305-
"workers": {
306-
"extraInitContainers": [{"name": "{{ .Release.Name }}-test-init-container"}],
307-
},
321+
@pytest.mark.parametrize(
322+
"workers_values",
323+
[
324+
{"extraInitContainers": [{"name": "{{ .Release.Name }}-test-init-container"}]},
325+
{"celery": {"extraInitContainers": [{"name": "{{ .Release.Name }}-test-init-container"}]}},
326+
{
327+
"extraInitContainers": [{"name": "container"}],
328+
"celery": {"extraInitContainers": [{"name": "{{ .Release.Name }}-test-init-container"}]},
308329
},
330+
],
331+
)
332+
def test_should_template_extra_init_containers(self, workers_values):
333+
docs = render_chart(
334+
values={"workers": workers_values},
309335
show_only=["templates/workers/worker-deployment.yaml"],
310336
)
311337

@@ -944,13 +970,15 @@ def test_extra_init_container_restart_policy_is_configurable(self):
944970
docs = render_chart(
945971
values={
946972
"workers": {
947-
"extraInitContainers": [
948-
{
949-
"name": "test-init-container",
950-
"image": "test-registry/test-repo:test-tag",
951-
"restartPolicy": "Always",
952-
}
953-
]
973+
"celery": {
974+
"extraInitContainers": [
975+
{
976+
"name": "test-init-container",
977+
"image": "test-registry/test-repo:test-tag",
978+
"restartPolicy": "Always",
979+
}
980+
]
981+
}
954982
},
955983
},
956984
show_only=["templates/workers/worker-deployment.yaml"],

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,6 +2513,20 @@ def test_overwrite_extra_containers(self, workers_values):
25132513
],
25142514
},
25152515
},
2516+
{
2517+
"celery": {
2518+
"enableDefault": False,
2519+
"extraInitContainers": [{"name": "test", "image": "test"}],
2520+
"sets": [
2521+
{
2522+
"name": "set1",
2523+
"extraInitContainers": [
2524+
{"name": "{{ .Chart.Name }}", "image": "test-registry/test-repo:test-tag"}
2525+
],
2526+
}
2527+
],
2528+
},
2529+
},
25162530
],
25172531
)
25182532
def test_overwrite_extra_init_containers(self, workers_values):

0 commit comments

Comments
 (0)