Skip to content

Commit

Permalink
Added to the rendering of KubernetesOperator V1VolumeMount, sub_path (#…
Browse files Browse the repository at this point in the history
…35129)

* Added to the rendering of KubernetesOperator V1VolumeMount, sub_path
  • Loading branch information
mescanne committed Oct 27, 2023
1 parent 64a64ab commit 85f0ef3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion airflow/providers/cncf/kubernetes/operators/pod.py
Expand Up @@ -459,7 +459,7 @@ def _render_nested_template_fields(
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:
Expand Down
9 changes: 9 additions & 0 deletions tests/providers/cncf/kubernetes/operators/test_pod.py
Expand Up @@ -132,6 +132,13 @@ def test_templates(self, create_task_instance_of_operator):
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 }}",
Expand All @@ -147,6 +154,8 @@ def test_templates(self, create_task_instance_of_operator):
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
Expand Down

0 comments on commit 85f0ef3

Please sign in to comment.