Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions airflow/kubernetes/pod_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,23 @@ def construct_pod(
- airflow.cfg
- executor_config
- dynamic arguments

If a user provides a `pod_override_object`, that pod should only be able to
override the image and namespace, and not arbitrary labels / annotations of
the dynamic_pod.
"""
try:
image = pod_override_object.spec.containers[0].image # type: ignore
if not image:
image = kube_image
except Exception:
image = kube_image
try:
final_namespace = pod_override_object.metadata.namespace # type: ignore
if not final_namespace:
final_namespace = namespace
except Exception:
final_namespace = namespace

annotations = {
'dag_id': dag_id,
Expand All @@ -368,7 +378,7 @@ def construct_pod(

dynamic_pod = k8s.V1Pod(
metadata=k8s.V1ObjectMeta(
namespace=namespace,
namespace=final_namespace,
annotations=annotations,
name=PodGenerator.make_unique_pod_id(pod_id),
labels=labels,
Expand All @@ -386,7 +396,7 @@ def construct_pod(
)

# Reconcile the pods starting with the first chronologically,
# Pod from the pod_template_File -> Pod from executor_config arg -> Pod from the K8s executor
# Pod from the pod_template_file -> Pod from executor_config arg -> Pod from dynamic arguments
pod_list = [base_worker_pod, pod_override_object, dynamic_pod]

try:
Expand Down
5 changes: 3 additions & 2 deletions tests/kubernetes/test_pod_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ def test_construct_pod(self, mock_uuid, config_image, expected_image):
name='', resources=k8s.V1ResourceRequirements(limits={'cpu': '1m', 'memory': '1G'})
)
]
)
),
metadata=k8s.V1ObjectMeta(namespace='overridden_namespace'),
)

result = PodGenerator.construct_pod(
Expand All @@ -435,7 +436,7 @@ def test_construct_pod(self, mock_uuid, config_image, expected_image):
expected.metadata.labels['app'] = 'myapp'
expected.metadata.annotations = self.annotations
expected.metadata.name = 'pod_id-' + self.static_uuid.hex
expected.metadata.namespace = 'test_namespace'
expected.metadata.namespace = 'overridden_namespace'
expected.spec.containers[0].args = ['command']
expected.spec.containers[0].image = expected_image
expected.spec.containers[0].resources = {'limits': {'cpu': '1m', 'memory': '1G'}}
Expand Down