Skip to content

Commit 636213e

Browse files
authored
Add workers.celery.extraContainers & workers.kubernetes.extraContainers (#64739)
* Refactor extraContainers-related tests * Add workers.celery.extraContainers & workers.kubernetes.extraContainers * Add newsfragment
1 parent 27258d5 commit 636213e

9 files changed

Lines changed: 153 additions & 59 deletions

File tree

chart/docs/using-additional-containers.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Sidecar Containers
2222
------------------
2323

2424
If you want to deploy your own sidecar container, you can add it through the ``extraContainers`` parameter.
25-
You can define different containers for the scheduler, webserver, api server, worker, triggerer, dag processor, flower, create user job and migrate database job pods.
25+
You can define different containers for the scheduler, webserver/api-server, Kubernetes/Celery workers, triggerer, dag processor, flower, create user job and migrate database job pods.
2626

2727
For example, sidecars that sync Dags from object storage:
2828

@@ -34,15 +34,17 @@ For example, sidecars that sync Dags from object storage:
3434
- name: s3-sync
3535
image: my-company/s3-sync:latest
3636
imagePullPolicy: Always
37+
3738
workers:
38-
extraContainers:
39-
- name: s3-sync
40-
image: my-company/s3-sync:latest
41-
imagePullPolicy: Always
39+
kubernetes:
40+
extraContainers:
41+
- name: s3-sync
42+
image: my-company/s3-sync:latest
43+
imagePullPolicy: Always
4244
4345
.. note::
4446

45-
If you use ``workers.extraContainers`` with ``KubernetesExecutor``, you are responsible for signaling
47+
If you use ``workers.kubernetes.extraContainers`` (dedicated for ``KubernetesExecutor``), you are responsible for signaling
4648
sidecars to exit when the main container finishes so Airflow can continue the worker shutdown process.
4749

4850

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ spec:
213213
{{- include "custom_airflow_environment" . | indent 6 }}
214214
{{- include "standard_airflow_environment" . | indent 6 }}
215215
{{- end }}
216-
{{- if .Values.workers.extraContainers }}
217-
{{- tpl (toYaml .Values.workers.extraContainers) . | nindent 4 }}
216+
{{- if or .Values.workers.kubernetes.extraContainers .Values.workers.extraContainers }}
217+
{{- tpl (toYaml (.Values.workers.kubernetes.extraContainers | default .Values.workers.extraContainers)) . | nindent 4 }}
218218
{{- end }}
219219
{{- if or .Values.workers.kubernetes.priorityClassName .Values.workers.priorityClassName }}
220220
priorityClassName: {{ .Values.workers.kubernetes.priorityClassName | default .Values.workers.priorityClassName }}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``workers.extraContainers`` field is now deprecated in favor of ``workers.celery.extraContainers`` and ``workers.kubernetes.extraContainers``. Please update your configuration accordingly.

chart/templates/NOTES.txt

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

702702
{{- end }}
703703

704+
{{- if not (empty .Values.workers.extraContainers) }}
705+
706+
DEPRECATION WARNING:
707+
`workers.extraContainers` has been renamed to `workers.celery.extraContainers`/`workers.kubernetes.extraContainers`.
708+
Please change your values as support for the old name will be dropped in a future release.
709+
710+
{{- end }}
711+
704712
{{- if not (empty .Values.workers.runtimeClassName) }}
705713

706714
DEPRECATION WARNING:

chart/values.schema.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2293,7 +2293,7 @@
22932293
"default": false
22942294
},
22952295
"extraContainers": {
2296-
"description": "Launch additional containers into Airflow Celery workers and pods created with pod-template-file (templated). Note, if used with KubernetesExecutor, you are responsible for signaling sidecars to exit when the main container finishes so Airflow can continue the worker shutdown process!",
2296+
"description": "Launch additional containers into Airflow Celery workers and pods created with pod-template-file (templated) (deprecated, use ``workers.celery.extraContainers`` and/or ``workers.kubernetes.extraContainers`` instead). Note, if used with KubernetesExecutor, you are responsible for signaling sidecars to exit when the main container finishes so Airflow can continue the worker shutdown process!",
22972297
"type": "array",
22982298
"default": [],
22992299
"items": {
@@ -3380,6 +3380,14 @@
33803380
],
33813381
"default": null
33823382
},
3383+
"extraContainers": {
3384+
"description": "Launch additional containers into Airflow Celery worker (templated).",
3385+
"type": "array",
3386+
"default": [],
3387+
"items": {
3388+
"$ref": "#/definitions/io.k8s.api.core.v1.Container"
3389+
}
3390+
},
33833391
"extraPorts": {
33843392
"description": "Expose additional ports of Airflow Celery worker container.",
33853393
"type": "array",
@@ -3870,6 +3878,14 @@
38703878
],
38713879
"default": null
38723880
},
3881+
"extraContainers": {
3882+
"description": "Launch additional containers into pods created with pod-template-file (templated). Note, you are responsible for signaling sidecars to exit when the main container finishes so Airflow can continue the worker shutdown process!",
3883+
"type": "array",
3884+
"default": [],
3885+
"items": {
3886+
"$ref": "#/definitions/io.k8s.api.core.v1.Container"
3887+
}
3888+
},
38733889
"nodeSelector": {
38743890
"description": "Select certain nodes for pods created with pod-template-file.",
38753891
"type": "object",

chart/values.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,10 @@ workers:
10421042

10431043
# Launch additional containers into Airflow Celery worker
10441044
# and pods created with pod-template-file (templated).
1045+
# (deprecated, use
1046+
# `workers.celery.extraContainers` and/or
1047+
# `workers.kubernetes.extraContainers`
1048+
# instead)
10451049
# Note: If used with KubernetesExecutor, you are responsible for signaling sidecars to exit when the main
10461050
# container finishes so Airflow can continue the worker shutdown process!
10471051
extraContainers: []
@@ -1443,6 +1447,9 @@ workers:
14431447
# This setting tells Kubernetes that its ok to evict when it wants to scale a node down
14441448
safeToEvict: ~
14451449

1450+
# Launch additional containers into Airflow Celery worker (templated)
1451+
extraContainers: []
1452+
14461453
# Expose additional ports of Airflow Celery workers. These can be used for additional metric collection.
14471454
extraPorts: []
14481455

@@ -1605,6 +1612,11 @@ workers:
16051612
# This setting tells Kubernetes that its ok to evict when it wants to scale a node down
16061613
safeToEvict: ~
16071614

1615+
# Launch additional containers into pods created with pod-template-file (templated).
1616+
# Note: You are responsible for signaling sidecars to exit when the main
1617+
# container finishes so Airflow can continue the worker shutdown process!
1618+
extraContainers: []
1619+
16081620
# Select certain nodes for pods created with pod-template-file
16091621
nodeSelector: {}
16101622

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

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,38 +1100,64 @@ def test_should_template_extra_init_containers(self):
11001100
"name": "release-name-test-init-container",
11011101
}
11021102

1103-
def test_should_add_extra_containers(self):
1104-
docs = render_chart(
1105-
values={
1106-
"workers": {
1103+
@pytest.mark.parametrize(
1104+
"workers_values",
1105+
[
1106+
{"extraContainers": [{"name": "test-container", "image": "test-registry/test-repo:test-tag"}]},
1107+
{
1108+
"kubernetes": {
11071109
"extraContainers": [
11081110
{"name": "test-container", "image": "test-registry/test-repo:test-tag"}
1109-
],
1111+
]
1112+
}
1113+
},
1114+
{
1115+
"extraContainers": [{"name": "container", "image": "repo:tag"}],
1116+
"kubernetes": {
1117+
"extraContainers": [
1118+
{"name": "test-container", "image": "test-registry/test-repo:test-tag"}
1119+
]
11101120
},
11111121
},
1122+
],
1123+
)
1124+
def test_should_add_extra_containers(self, workers_values):
1125+
docs = render_chart(
1126+
values={"workers": workers_values},
11121127
show_only=["templates/pod-template-file.yaml"],
11131128
chart_dir=self.temp_chart_dir,
11141129
)
11151130

1116-
assert jmespath.search("spec.containers[-1]", docs[0]) == {
1117-
"name": "test-container",
1118-
"image": "test-registry/test-repo:test-tag",
1119-
}
1131+
assert jmespath.search("spec.containers[1:]", docs[0]) == [
1132+
{
1133+
"name": "test-container",
1134+
"image": "test-registry/test-repo:test-tag",
1135+
}
1136+
]
11201137

1121-
def test_should_template_extra_containers(self):
1122-
docs = render_chart(
1123-
values={
1124-
"workers": {
1125-
"extraContainers": [{"name": "{{ .Release.Name }}-test-container"}],
1126-
},
1138+
@pytest.mark.parametrize(
1139+
"workers_values",
1140+
[
1141+
{"extraContainers": [{"name": "{{ .Release.Name }}-test-container"}]},
1142+
{"kubernetes": {"extraContainers": [{"name": "{{ .Release.Name }}-test-container"}]}},
1143+
{
1144+
"extraContainers": [{"name": "{{ .Release.Name }}-test"}],
1145+
"kubernetes": {"extraContainers": [{"name": "{{ .Release.Name }}-test-container"}]},
11271146
},
1147+
],
1148+
)
1149+
def test_should_template_extra_containers(self, workers_values):
1150+
docs = render_chart(
1151+
values={"workers": workers_values},
11281152
show_only=["templates/pod-template-file.yaml"],
11291153
chart_dir=self.temp_chart_dir,
11301154
)
11311155

1132-
assert jmespath.search("spec.containers[-1]", docs[0]) == {
1133-
"name": "release-name-test-container",
1134-
}
1156+
assert jmespath.search("spec.containers[1:]", docs[0]) == [
1157+
{
1158+
"name": "release-name-test-container",
1159+
}
1160+
]
11351161

11361162
def test_should_add_pod_labels(self):
11371163
docs = render_chart(

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

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -135,23 +135,53 @@ def test_revision_history_limit_zero(self, worker_values, global_limit, expected
135135

136136
assert jmespath.search("spec.revisionHistoryLimit", docs[0]) == expected
137137

138-
def test_should_add_extra_containers(self):
138+
@pytest.mark.parametrize(
139+
"workers_values",
140+
[
141+
{
142+
"extraContainers": [
143+
{"name": "{{ .Chart.Name }}-test-container", "image": "test-registry/test-repo:test-tag"}
144+
]
145+
},
146+
{
147+
"celery": {
148+
"extraContainers": [
149+
{
150+
"name": "{{ .Chart.Name }}-test-container",
151+
"image": "test-registry/test-repo:test-tag",
152+
}
153+
]
154+
}
155+
},
156+
{
157+
"extraContainers": [{"name": "test", "image": "repo:test"}],
158+
"celery": {
159+
"extraContainers": [
160+
{
161+
"name": "{{ .Chart.Name }}-test-container",
162+
"image": "test-registry/test-repo:test-tag",
163+
}
164+
]
165+
},
166+
},
167+
],
168+
)
169+
def test_should_add_extra_containers_with_template(self, workers_values):
139170
docs = render_chart(
140171
values={
141172
"executor": "CeleryExecutor",
142-
"workers": {
143-
"extraContainers": [
144-
{"name": "{{ .Chart.Name }}", "image": "test-registry/test-repo:test-tag"}
145-
],
146-
},
173+
"workers": workers_values,
147174
},
148175
show_only=["templates/workers/worker-deployment.yaml"],
149176
)
150177

151-
assert jmespath.search("spec.template.spec.containers[-1]", docs[0]) == {
152-
"name": "airflow",
153-
"image": "test-registry/test-repo:test-tag",
154-
}
178+
# [2:] -> Skipping worker and worker-log-groomer containers
179+
assert jmespath.search("spec.template.spec.containers[2:]", docs[0]) == [
180+
{
181+
"name": "airflow-test-container",
182+
"image": "test-registry/test-repo:test-tag",
183+
}
184+
]
155185

156186
@pytest.mark.parametrize(
157187
"workers_values",
@@ -188,21 +218,6 @@ def test_persistent_volume_claim_retention_policy(self, workers_values):
188218
"whenDeleted": "Delete",
189219
}
190220

191-
def test_should_template_extra_containers(self):
192-
docs = render_chart(
193-
values={
194-
"executor": "CeleryExecutor",
195-
"workers": {
196-
"extraContainers": [{"name": "{{ .Release.Name }}-test-container"}],
197-
},
198-
},
199-
show_only=["templates/workers/worker-deployment.yaml"],
200-
)
201-
202-
assert jmespath.search("spec.template.spec.containers[-1]", docs[0]) == {
203-
"name": "release-name-test-container"
204-
}
205-
206221
@pytest.mark.parametrize(
207222
"workers_values",
208223
[

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2458,6 +2458,20 @@ def test_overwrite_safe_to_evict_disable(self, workers_values):
24582458
],
24592459
},
24602460
},
2461+
{
2462+
"celery": {
2463+
"enableDefault": False,
2464+
"extraContainers": [{"name": "test", "image": "test"}],
2465+
"sets": [
2466+
{
2467+
"name": "set1",
2468+
"extraContainers": [
2469+
{"name": "{{ .Chart.Name }}", "image": "test-registry/test-repo:test-tag"}
2470+
],
2471+
}
2472+
],
2473+
},
2474+
},
24612475
],
24622476
)
24632477
def test_overwrite_extra_containers(self, workers_values):
@@ -2468,13 +2482,13 @@ def test_overwrite_extra_containers(self, workers_values):
24682482
show_only=["templates/workers/worker-deployment.yaml"],
24692483
)
24702484

2471-
containers = jmespath.search("spec.template.spec.containers", docs[0])
2472-
2473-
assert len(containers) == 3 # worker, worker-log-groomer, extra
2474-
assert containers[-1] == {
2475-
"name": "airflow",
2476-
"image": "test-registry/test-repo:test-tag",
2477-
}
2485+
# [2:] -> Skipping worker and worker-log-groomer containers
2486+
assert jmespath.search("spec.template.spec.containers[2:]", docs[0]) == [
2487+
{
2488+
"name": "airflow",
2489+
"image": "test-registry/test-repo:test-tag",
2490+
}
2491+
]
24782492

24792493
@pytest.mark.parametrize(
24802494
"workers_values",

0 commit comments

Comments
 (0)