Skip to content

Commit 6cbf4c8

Browse files
authored
Add workers.celery.extraVolumes & workers.kubernetes.extraVolumes (#64746)
* Seperate extraVolumes & extraVolumeMounts in values.yaml * Refactor workers extraVolumes-related tests * Add workers.celery.extraVolumes & workers.kubernetes.extraVolumes * Add newsfragment
1 parent e55d90f commit 6cbf4c8

File tree

7 files changed

+106
-16
lines changed

7 files changed

+106
-16
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,6 @@ spec:
287287
- name: kerberos-ccache
288288
emptyDir: {}
289289
{{- end }}
290-
{{- if .Values.workers.extraVolumes }}
291-
{{- tpl (toYaml .Values.workers.extraVolumes) . | nindent 2 }}
290+
{{- if or .Values.workers.kubernetes.extraVolumes .Values.workers.extraVolumes }}
291+
{{- tpl (toYaml (.Values.workers.kubernetes.extraVolumes | default .Values.workers.extraVolumes)) . | nindent 2 }}
292292
{{- end }}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``workers.extraVolumes`` field is now deprecated in favor of ``workers.celery.extraVolumes`` and ``workers.kubernetes.extraVolumes``. Please update your configuration accordingly.

chart/values.schema.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2317,7 +2317,7 @@
23172317
}
23182318
},
23192319
"extraVolumes": {
2320-
"description": "Additional volumes attached to the Airflow Celery workers and pods created with pod-template-file.",
2320+
"description": "Additional volumes attached to the Airflow Celery workers and pods created with pod-template-file (deprecated, use ``workers.celery.extraVolumes`` and/or ``workers.kubernetes.extraVolumes`` instead).",
23212321
"type": "array",
23222322
"default": [],
23232323
"items": {
@@ -3396,6 +3396,14 @@
33963396
"$ref": "#/definitions/io.k8s.api.core.v1.Container"
33973397
}
33983398
},
3399+
"extraVolumes": {
3400+
"description": "Additional volumes attached to the Airflow Celery workers.",
3401+
"type": "array",
3402+
"default": [],
3403+
"items": {
3404+
"$ref": "#/definitions/io.k8s.api.core.v1.Volume"
3405+
}
3406+
},
33993407
"extraPorts": {
34003408
"description": "Expose additional ports of Airflow Celery worker container.",
34013409
"type": "array",
@@ -3902,6 +3910,14 @@
39023910
"$ref": "#/definitions/io.k8s.api.core.v1.Container"
39033911
}
39043912
},
3913+
"extraVolumes": {
3914+
"description": "Additional volumes attached to the pods created with pod-template-file.",
3915+
"type": "array",
3916+
"default": [],
3917+
"items": {
3918+
"$ref": "#/definitions/io.k8s.api.core.v1.Volume"
3919+
}
3920+
},
39053921
"nodeSelector": {
39063922
"description": "Select certain nodes for pods created with pod-template-file.",
39073923
"type": "object",

chart/values.yaml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,18 +1058,22 @@ workers:
10581058
# instead)
10591059
extraInitContainers: []
10601060

1061-
# Additional volumes and volume mounts attached to the
1062-
# Airflow Celery workers and pods created with pod-template-file
1061+
# Additional volumes attached to the Airflow Celery workers
1062+
# and pods created with pod-template-file
1063+
# (deprecated, use `workers.celery.extraVolumes` and/or `workers.kubernetes.extraVolumes` instead)
10631064
extraVolumes: []
1064-
extraVolumeMounts: []
10651065
# Mount additional volumes into workers pods. It can be templated like in the following example:
10661066
# extraVolumes:
10671067
# - name: my-templated-extra-volume
10681068
# secret:
10691069
# secretName: '{{ include "my_secret_template" . }}'
10701070
# defaultMode: 0640
10711071
# optional: true
1072-
#
1072+
1073+
# Additional volume mounts attached to the Airflow Celery workers
1074+
# and pods created with pod-template-file
1075+
extraVolumeMounts: []
1076+
# Mount additional volumes into workers pods. It can be templated like in the following example:
10731077
# extraVolumeMounts:
10741078
# - name: my-templated-extra-volume
10751079
# mountPath: "{{ .Values.my_custom_path }}"
@@ -1457,6 +1461,16 @@ workers:
14571461
# Add additional init containers into Airflow Celery workers (templated)
14581462
extraInitContainers: []
14591463

1464+
# Additional volumes attached to the Airflow Celery workers
1465+
extraVolumes: []
1466+
# Mount additional volumes into workers pods. It can be templated like in the following example:
1467+
# extraVolumes:
1468+
# - name: my-templated-extra-volume
1469+
# secret:
1470+
# secretName: '{{ include "my_secret_template" . }}'
1471+
# defaultMode: 0640
1472+
# optional: true
1473+
14601474
# Expose additional ports of Airflow Celery workers. These can be used for additional metric collection.
14611475
extraPorts: []
14621476

@@ -1627,6 +1641,16 @@ workers:
16271641
# Add additional init containers into pods created with pod-template-file (templated)
16281642
extraInitContainers: []
16291643

1644+
# Additional volumes attached to the pods created with pod-template-file
1645+
extraVolumes: []
1646+
# Mount additional volumes into workers pods. It can be templated like in the following example:
1647+
# extraVolumes:
1648+
# - name: my-templated-extra-volume
1649+
# secret:
1650+
# secretName: '{{ include "my_secret_template" . }}'
1651+
# defaultMode: 0640
1652+
# optional: true
1653+
16301654
# Select certain nodes for pods created with pod-template-file
16311655
nodeSelector: {}
16321656

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -924,11 +924,31 @@ def test_should_add_uid_to_the_pod_template(self):
924924

925925
assert jmespath.search("spec.securityContext.runAsUser", docs[0]) == 1
926926

927-
def test_should_create_valid_volume_mount_and_volume(self):
927+
@pytest.mark.parametrize(
928+
"workers_values",
929+
[
930+
{"extraVolumes": [{"name": "test-volume-{{ .Chart.Name }}", "emptyDir": {}}]},
931+
{"kubernetes": {"extraVolumes": [{"name": "test-volume-{{ .Chart.Name }}", "emptyDir": {}}]}},
932+
{
933+
"extraVolumes": [{"name": "test", "emptyDir": {}}],
934+
"kubernetes": {"extraVolumes": [{"name": "test-volume-{{ .Chart.Name }}", "emptyDir": {}}]},
935+
},
936+
],
937+
)
938+
def test_should_create_valid_volume(self, workers_values):
939+
docs = render_chart(
940+
values={"workers": workers_values},
941+
show_only=["templates/pod-template-file.yaml"],
942+
chart_dir=self.temp_chart_dir,
943+
)
944+
945+
# [2:] -> Skipping logs and config volumes
946+
assert jmespath.search("spec.volumes[2:].name", docs[0]) == ["test-volume-airflow"]
947+
948+
def test_should_create_valid_volume_mount(self):
928949
docs = render_chart(
929950
values={
930951
"workers": {
931-
"extraVolumes": [{"name": "test-volume-{{ .Chart.Name }}", "emptyDir": {}}],
932952
"extraVolumeMounts": [
933953
{"name": "test-volume-{{ .Chart.Name }}", "mountPath": "/opt/test"}
934954
],
@@ -938,10 +958,6 @@ def test_should_create_valid_volume_mount_and_volume(self):
938958
chart_dir=self.temp_chart_dir,
939959
)
940960

941-
assert "test-volume-airflow" in jmespath.search(
942-
"spec.volumes[*].name",
943-
docs[0],
944-
)
945961
assert "test-volume-airflow" in jmespath.search(
946962
"spec.containers[0].volumeMounts[*].name",
947963
docs[0],

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,34 @@ def test_should_template_extra_init_containers(self, workers_values):
340340
{"name": "release-name-test-init-container"}
341341
]
342342

343-
def test_should_add_extra_volume_and_extra_volume_mount(self):
343+
@pytest.mark.parametrize(
344+
"workers_values",
345+
[
346+
{"extraVolumes": [{"name": "test-volume-{{ .Chart.Name }}", "emptyDir": {}}]},
347+
{"celery": {"extraVolumes": [{"name": "test-volume-{{ .Chart.Name }}", "emptyDir": {}}]}},
348+
{
349+
"extraVolumes": [{"name": "test", "emptyDir": {}}],
350+
"celery": {"extraVolumes": [{"name": "test-volume-{{ .Chart.Name }}", "emptyDir": {}}]},
351+
},
352+
],
353+
)
354+
def test_should_add_extra_volume(self, workers_values):
355+
docs = render_chart(
356+
values={
357+
"executor": "CeleryExecutor",
358+
"workers": workers_values,
359+
},
360+
show_only=["templates/workers/worker-deployment.yaml"],
361+
)
362+
363+
# [:-1] -> Skipping config volume
364+
assert jmespath.search("spec.template.spec.volumes[:-1].name", docs[0]) == ["test-volume-airflow"]
365+
366+
def test_should_add_extra_volume_mount(self):
344367
docs = render_chart(
345368
values={
346369
"executor": "CeleryExecutor",
347370
"workers": {
348-
"extraVolumes": [{"name": "test-volume-{{ .Chart.Name }}", "emptyDir": {}}],
349371
"extraVolumeMounts": [
350372
{"name": "test-volume-{{ .Chart.Name }}", "mountPath": "/opt/test"}
351373
],
@@ -354,7 +376,6 @@ def test_should_add_extra_volume_and_extra_volume_mount(self):
354376
show_only=["templates/workers/worker-deployment.yaml"],
355377
)
356378

357-
assert jmespath.search("spec.template.spec.volumes[0].name", docs[0]) == "test-volume-airflow"
358379
assert (
359380
jmespath.search("spec.template.spec.containers[0].volumeMounts[0].name", docs[0])
360381
== "test-volume-airflow"

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2564,6 +2564,18 @@ def test_overwrite_extra_init_containers(self, workers_values):
25642564
],
25652565
},
25662566
},
2567+
{
2568+
"celery": {
2569+
"enableDefault": False,
2570+
"extraVolumes": [{"name": "test", "emptyDir": {}}],
2571+
"sets": [
2572+
{
2573+
"name": "set1",
2574+
"extraVolumes": [{"name": "test-volume-{{ .Chart.Name }}", "emptyDir": {}}],
2575+
}
2576+
],
2577+
},
2578+
},
25672579
],
25682580
)
25692581
def test_overwrite_extra_volumes(self, workers_values):

0 commit comments

Comments
 (0)