Skip to content

Commit 8188a2e

Browse files
committed
Add workers.celery.extraContainers & workers.kubernetes.extraContainers
1 parent e19eb20 commit 8188a2e

8 files changed

Lines changed: 123 additions & 25 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 }}

chart/templates/NOTES.txt

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

630630
{{- end }}
631631

632+
{{- if not (empty .Values.workers.extraContainers) }}
633+
634+
DEPRECATION WARNING:
635+
`workers.extraContainers` has been renamed to `workers.celery.extraContainers`/`workers.kubernetes.extraContainers`.
636+
Please change your values as support for the old name will be dropped in a future release.
637+
638+
{{- end }}
639+
632640
{{- if not (empty .Values.workers.runtimeClassName) }}
633641

634642
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": {
@@ -3294,6 +3294,14 @@
32943294
],
32953295
"default": null
32963296
},
3297+
"extraContainers": {
3298+
"description": "Launch additional containers into Airflow Celery worker (templated).",
3299+
"type": "array",
3300+
"default": [],
3301+
"items": {
3302+
"$ref": "#/definitions/io.k8s.api.core.v1.Container"
3303+
}
3304+
},
32973305
"extraPorts": {
32983306
"description": "Expose additional ports of Airflow Celery worker container.",
32993307
"type": "array",
@@ -3637,6 +3645,14 @@
36373645
],
36383646
"default": null
36393647
},
3648+
"extraContainers": {
3649+
"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!",
3650+
"type": "array",
3651+
"default": [],
3652+
"items": {
3653+
"$ref": "#/definitions/io.k8s.api.core.v1.Container"
3654+
}
3655+
},
36403656
"nodeSelector": {
36413657
"description": "Select certain nodes for pods created with pod-template-file.",
36423658
"type": "object",

chart/values.yaml

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

10201020
# Launch additional containers into Airflow Celery worker
10211021
# and pods created with pod-template-file (templated).
1022+
# (deprecated, use
1023+
# `workers.celery.extraContainers` and/or
1024+
# `workers.kubernetes.extraContainers`
1025+
# instead)
10221026
# Note: If used with KubernetesExecutor, you are responsible for signaling sidecars to exit when the main
10231027
# container finishes so Airflow can continue the worker shutdown process!
10241028
extraContainers: []
@@ -1379,6 +1383,9 @@ workers:
13791383
# This setting tells Kubernetes that its ok to evict when it wants to scale a node down
13801384
safeToEvict: ~
13811385

1386+
# Launch additional containers into Airflow Celery worker (templated)
1387+
extraContainers: []
1388+
13821389
# Expose additional ports of Airflow Celery workers. These can be used for additional metric collection.
13831390
extraPorts: []
13841391

@@ -1470,6 +1477,11 @@ workers:
14701477
# This setting tells Kubernetes that its ok to evict when it wants to scale a node down
14711478
safeToEvict: ~
14721479

1480+
# Launch additional containers into pods created with pod-template-file (templated).
1481+
# Note: You are responsible for signaling sidecars to exit when the main
1482+
# container finishes so Airflow can continue the worker shutdown process!
1483+
extraContainers: []
1484+
14731485
# Select certain nodes for pods created with pod-template-file
14741486
nodeSelector: {}
14751487

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

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,15 +1039,30 @@ def test_should_template_extra_init_containers(self):
10391039
"name": "release-name-test-init-container",
10401040
}
10411041

1042-
def test_should_add_extra_containers(self):
1043-
docs = render_chart(
1044-
values={
1045-
"workers": {
1042+
@pytest.mark.parametrize(
1043+
"workers_values",
1044+
[
1045+
{"extraContainers": [{"name": "test-container", "image": "test-registry/test-repo:test-tag"}]},
1046+
{
1047+
"kubernetes": {
10461048
"extraContainers": [
10471049
{"name": "test-container", "image": "test-registry/test-repo:test-tag"}
1048-
],
1050+
]
1051+
}
1052+
},
1053+
{
1054+
"extraContainers": [{"name": "container", "image": "repo:tag"}],
1055+
"kubernetes": {
1056+
"extraContainers": [
1057+
{"name": "test-container", "image": "test-registry/test-repo:test-tag"}
1058+
]
10491059
},
10501060
},
1061+
],
1062+
)
1063+
def test_should_add_extra_containers(self, workers_values):
1064+
docs = render_chart(
1065+
values={"workers": workers_values},
10511066
show_only=["templates/pod-template-file.yaml"],
10521067
chart_dir=self.temp_chart_dir,
10531068
)
@@ -1059,13 +1074,20 @@ def test_should_add_extra_containers(self):
10591074
}
10601075
]
10611076

1062-
def test_should_template_extra_containers(self):
1063-
docs = render_chart(
1064-
values={
1065-
"workers": {
1066-
"extraContainers": [{"name": "{{ .Release.Name }}-test-container"}],
1067-
},
1077+
@pytest.mark.parametrize(
1078+
"workers_values",
1079+
[
1080+
{"extraContainers": [{"name": "{{ .Release.Name }}-test-container"}]},
1081+
{"kubernetes": {"extraContainers": [{"name": "{{ .Release.Name }}-test-container"}]}},
1082+
{
1083+
"extraContainers": [{"name": "{{ .Release.Name }}-test"}],
1084+
"kubernetes": {"extraContainers": [{"name": "{{ .Release.Name }}-test-container"}]},
10681085
},
1086+
],
1087+
)
1088+
def test_should_template_extra_containers(self, workers_values):
1089+
docs = render_chart(
1090+
values={"workers": workers_values},
10691091
show_only=["templates/pod-template-file.yaml"],
10701092
chart_dir=self.temp_chart_dir,
10711093
)

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

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,27 @@ 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_with_template(self):
139-
docs = render_chart(
140-
values={
141-
"executor": "CeleryExecutor",
142-
"workers": {
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": {
143159
"extraContainers": [
144160
{
145161
"name": "{{ .Chart.Name }}-test-container",
@@ -148,6 +164,14 @@ def test_should_add_extra_containers_with_template(self):
148164
]
149165
},
150166
},
167+
],
168+
)
169+
def test_should_add_extra_containers_with_template(self, workers_values):
170+
docs = render_chart(
171+
values={
172+
"executor": "CeleryExecutor",
173+
"workers": workers_values,
174+
},
151175
show_only=["templates/workers/worker-deployment.yaml"],
152176
)
153177

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
@@ -2292,6 +2292,20 @@ def test_overwrite_safe_to_evict_disable(self, workers_values):
22922292
],
22932293
},
22942294
},
2295+
{
2296+
"celery": {
2297+
"enableDefault": False,
2298+
"extraContainers": [{"name": "test", "image": "test"}],
2299+
"sets": [
2300+
{
2301+
"name": "set1",
2302+
"extraContainers": [
2303+
{"name": "{{ .Chart.Name }}", "image": "test-registry/test-repo:test-tag"}
2304+
],
2305+
}
2306+
],
2307+
},
2308+
},
22952309
],
22962310
)
22972311
def test_overwrite_extra_containers(self, workers_values):

0 commit comments

Comments
 (0)