Skip to content

Commit

Permalink
Make KPO tolerant of hooks that don't have xcom methods
Browse files Browse the repository at this point in the history
We probably should not be configuring xcom settings from the hook in this way but for better or worse we've done it, first in apache#26766 and again in apache#28125.

The problem is that other operators derived from KPO, e.g. GKEStartPodOperator, may use a different hook that doesn't have this xcom-specific methods.  So KPO needs to tolerate that.
  • Loading branch information
dstandish committed May 12, 2023
1 parent 0d962c2 commit 0f5c17b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions airflow/providers/cncf/kubernetes/operators/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,10 +861,16 @@ def build_pod_request_obj(self, context: Context | None = None) -> k8s.V1Pod:
pod = secret.attach_to_pod(pod)
if self.do_xcom_push:
self.log.debug("Adding xcom sidecar to task %s", self.task_id)
sidecar_container_image = None
sidecar_container_resources = None
if hasattr(self.hook, "get_xcom_sidecar_container_image"):
sidecar_container_image = self.hook.get_xcom_sidecar_container_image()
if hasattr(self.hook, "get_xcom_sidecar_container_resources"):
sidecar_container_resources = self.hook.get_xcom_sidecar_container_resources()
pod = xcom_sidecar.add_xcom_sidecar(
pod,
sidecar_container_image=self.hook.get_xcom_sidecar_container_image(),
sidecar_container_resources=self.hook.get_xcom_sidecar_container_resources(),
sidecar_container_image=sidecar_container_image,
sidecar_container_resources=sidecar_container_resources,
)

labels = self._get_ti_pod_labels(context)
Expand Down

0 comments on commit 0f5c17b

Please sign in to comment.