Skip to content

Commit 8d89f2e

Browse files
jschefflMiretpl
andauthored
[chart/v1-2x-test] Add workers.celery.extraInitContainers & workers.kubernetes.extraInitContainers (#64741) (#64979)
* Refactor workers extraInitContainers-related tests * Add workers.celery.extraInitContainers & workers.kubernetes.extraInitContainers * Add newsfragment (cherry picked from commit 52c4d32) Co-authored-by: Przemysław Mirowski <17602603+Miretpl@users.noreply.github.com>
1 parent c2610fb commit 8d89f2e

File tree

9 files changed

+162
-48
lines changed

9 files changed

+162
-48
lines changed

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
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``workers.extraInitContainers`` field is now deprecated in favor of ``workers.celery.extraInitContainers`` and ``workers.kubernetes.extraInitContainers``. Please update your configuration accordingly.

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: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,38 +1067,68 @@ 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
)
10821101

1083-
assert jmespath.search("spec.initContainers[-1]", docs[0]) == {
1084-
"name": "test-init-container",
1085-
"image": "test-registry/test-repo:test-tag",
1086-
}
1102+
assert jmespath.search("spec.initContainers", docs[0]) == [
1103+
{
1104+
"name": "test-init-container",
1105+
"image": "test-registry/test-repo:test-tag",
1106+
}
1107+
]
10871108

1088-
def test_should_template_extra_init_containers(self):
1089-
docs = render_chart(
1090-
values={
1091-
"workers": {
1092-
"extraInitContainers": [{"name": "{{ .Release.Name }}-test-init-container"}],
1093-
},
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"}]},
10941117
},
1118+
],
1119+
)
1120+
def test_should_template_extra_init_containers(self, workers_values):
1121+
docs = render_chart(
1122+
values={"workers": workers_values},
10951123
show_only=["templates/pod-template-file.yaml"],
10961124
chart_dir=self.temp_chart_dir,
10971125
)
10981126

1099-
assert jmespath.search("spec.initContainers[-1]", docs[0]) == {
1100-
"name": "release-name-test-init-container",
1101-
}
1127+
assert jmespath.search("spec.initContainers", docs[0]) == [
1128+
{
1129+
"name": "release-name-test-init-container",
1130+
}
1131+
]
11021132

11031133
@pytest.mark.parametrize(
11041134
"workers_values",

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

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -279,36 +279,66 @@ 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

294-
assert jmespath.search("spec.template.spec.initContainers[-1]", docs[0]) == {
295-
"name": "test-init-container",
296-
"image": "test-registry/test-repo:test-tag",
297-
}
313+
# [1:] -> Skipping wait-for-airflow-migrations init container
314+
assert jmespath.search("spec.template.spec.initContainers[1:]", docs[0]) == [
315+
{
316+
"name": "test-init-container",
317+
"image": "test-registry/test-repo:test-tag",
318+
}
319+
]
298320

299-
def test_should_template_extra_init_containers(self):
300-
docs = render_chart(
301-
values={
302-
"workers": {
303-
"extraInitContainers": [{"name": "{{ .Release.Name }}-test-init-container"}],
304-
},
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"}]},
305329
},
330+
],
331+
)
332+
def test_should_template_extra_init_containers(self, workers_values):
333+
docs = render_chart(
334+
values={"workers": workers_values},
306335
show_only=["templates/workers/worker-deployment.yaml"],
307336
)
308337

309-
assert jmespath.search("spec.template.spec.initContainers[-1]", docs[0]) == {
310-
"name": "release-name-test-init-container"
311-
}
338+
# [1:] -> Skipping wait-for-airflow-migrations init container
339+
assert jmespath.search("spec.template.spec.initContainers[1:]", docs[0]) == [
340+
{"name": "release-name-test-init-container"}
341+
]
312342

313343
def test_should_add_extra_volume_and_extra_volume_mount(self):
314344
docs = render_chart(
@@ -940,19 +970,24 @@ def test_extra_init_container_restart_policy_is_configurable(self):
940970
docs = render_chart(
941971
values={
942972
"workers": {
943-
"extraInitContainers": [
944-
{
945-
"name": "test-init-container",
946-
"image": "test-registry/test-repo:test-tag",
947-
"restartPolicy": "Always",
948-
}
949-
]
973+
"celery": {
974+
"extraInitContainers": [
975+
{
976+
"name": "test-init-container",
977+
"image": "test-registry/test-repo:test-tag",
978+
"restartPolicy": "Always",
979+
}
980+
]
981+
}
950982
},
951983
},
952984
show_only=["templates/workers/worker-deployment.yaml"],
953985
)
954986

955-
assert jmespath.search("spec.template.spec.initContainers[1].restartPolicy", docs[0]) == "Always"
987+
# [1:] -> Skipping wait-for-airflow-migrations init container
988+
assert jmespath.search("spec.template.spec.initContainers[1:] | [*].restartPolicy", docs[0]) == [
989+
"Always"
990+
]
956991

957992
@pytest.mark.parametrize(
958993
("log_values", "expected_volume"),

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)