This is an automated email from the ASF dual-hosted git repository.
eladkal pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 85f0ef35b8 Added to the rendering of KubernetesOperator V1VolumeMount,
sub_path (#35129)
85f0ef35b8 is described below
commit 85f0ef35b831db61a4a6ac83f370cfff5323b842
Author: Mark Scannell <[email protected]>
AuthorDate: Fri Oct 27 15:28:18 2023 +0100
Added to the rendering of KubernetesOperator V1VolumeMount, sub_path
(#35129)
* Added to the rendering of KubernetesOperator V1VolumeMount, sub_path
---
airflow/providers/cncf/kubernetes/operators/pod.py | 2 +-
tests/providers/cncf/kubernetes/operators/test_pod.py | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/airflow/providers/cncf/kubernetes/operators/pod.py
b/airflow/providers/cncf/kubernetes/operators/pod.py
index ff3e32e8c7..d85257f4aa 100644
--- a/airflow/providers/cncf/kubernetes/operators/pod.py
+++ b/airflow/providers/cncf/kubernetes/operators/pod.py
@@ -459,7 +459,7 @@ class KubernetesPodOperator(BaseOperator):
elif isinstance(content, k8s.V1Volume):
template_fields = ("name", "persistent_volume_claim")
elif isinstance(content, k8s.V1VolumeMount):
- template_fields = ("name",)
+ template_fields = ("name", "sub_path")
elif isinstance(content, k8s.V1PersistentVolumeClaimVolumeSource):
template_fields = ("claim_name",)
else:
diff --git a/tests/providers/cncf/kubernetes/operators/test_pod.py
b/tests/providers/cncf/kubernetes/operators/test_pod.py
index 8a4927a65c..ee38c013b3 100644
--- a/tests/providers/cncf/kubernetes/operators/test_pod.py
+++ b/tests/providers/cncf/kubernetes/operators/test_pod.py
@@ -132,6 +132,13 @@ class TestKubernetesPodOperator:
requests={"memory": "{{ dag.dag_id }}", "cpu": "{{ dag.dag_id
}}"},
limits={"memory": "{{ dag.dag_id }}", "cpu": "{{ dag.dag_id
}}"},
),
+ volume_mounts=[
+ k8s.V1VolumeMount(
+ name="{{ dag.dag_id }}",
+ mount_path="mount_path",
+ sub_path="{{ dag.dag_id }}",
+ )
+ ],
pod_template_file="{{ dag.dag_id }}",
config_file="{{ dag.dag_id }}",
labels="{{ dag.dag_id }}",
@@ -147,6 +154,8 @@ class TestKubernetesPodOperator:
assert dag_id == rendered.container_resources.limits["cpu"]
assert dag_id == rendered.container_resources.requests["memory"]
assert dag_id == rendered.container_resources.requests["cpu"]
+ assert dag_id == rendered.volume_mounts[0].name
+ assert dag_id == rendered.volume_mounts[0].sub_path
assert dag_id == ti.task.image
assert dag_id == ti.task.cmds
assert dag_id == ti.task.namespace