Skip to content

Fix XCom sidecar helper mutating the caller's pod volumes - #72522

Open
henry3260 wants to merge 1 commit into
apache:mainfrom
henry3260:fix-xcom-sidecar-input-pod-mutation
Open

Fix XCom sidecar helper mutating the caller's pod volumes#72522
henry3260 wants to merge 1 commit into
apache:mainfrom
henry3260:fix-xcom-sidecar-input-pod-mutation

Conversation

@henry3260

@henry3260 henry3260 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Why

add_xcom_sidecar deep-copies the input pod so the caller's object stays untouched, but it then re-pointed the copy's spec.volumes at the original pod's volume list before inserting the xcom volume. Any caller that reuses the same pod object (custom operators or subclasses calling build_pod_request_obj more than once, or direct users of the helper) accumulated one extra xcom volume per call. Kubernetes requires volume names to be unique, so the API rejects the second pod as a duplicate. KubernetesPodOperator itself was only shielded because reconcile_pods happens to deep-copy first.

The helper also inserted the module-level PodDefaults.VOLUME and PodDefaults.VOLUME_MOUNT instances directly, so mutating them on one pod silently changed every other pod built by the helper, as well as the defaults themselves.

What

  • providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/utils/xcom_sidecar.py: assign pod_cp.spec.volumes from the copy instead of the original pod, and insert deep copies of PodDefaults.VOLUME and PodDefaults.VOLUME_MOUNT.
  • providers/cncf/kubernetes/tests/unit/cncf/kubernetes/utils/test_xcom_sidecar.py: add two regression tests. One asserts the caller's pod keeps its original volume list while the returned copy gains the xcom volume. The other asserts the inserted volume and mount are not the shared default instances. Both fail on main and pass with this change.

Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Fable 5.1)

add_xcom_sidecar deep-copies the input pod so callers keep an untouched
object, but it then pointed the copy's volumes back at the original pod's
list before inserting the xcom volume. Any caller reusing the same pod
object accumulated one extra "xcom" volume per call, which the Kubernetes
API rejects as a duplicate. KubernetesPodOperator was only shielded
because reconcile_pods happens to deep-copy first.

The default V1Volume and V1VolumeMount were also inserted as the shared
module-level instances, so editing them on one pod silently changed every
other pod built by the helper and the defaults themselves.
@henry3260
henry3260 force-pushed the fix-xcom-sidecar-input-pod-mutation branch from 95135a8 to 4f432aa Compare September 4, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers provider:cncf-kubernetes Kubernetes (k8s) provider related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant