Skip to content

Commit

Permalink
KPO xcom sidecar PodDefault usage (apache#38951)
Browse files Browse the repository at this point in the history
We should use the same, non deprecated, version of PodDefaults for the
xcom sidecar when creating and reading xcom.
  • Loading branch information
jedcunningham authored and RodrigoGanancia committed May 10, 2024
1 parent 50b145b commit 1bab77a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions airflow/providers/cncf/kubernetes/pod_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
rand_str,
)
from airflow.providers.cncf.kubernetes.pod_generator_deprecated import (
PodDefaults,
PodDefaults as PodDefaultsDeprecated,
PodGenerator as PodGeneratorDeprecated,
)
from airflow.utils import yaml
Expand Down Expand Up @@ -180,10 +180,10 @@ def add_xcom_sidecar(pod: k8s.V1Pod) -> k8s.V1Pod:
"""Add sidecar."""
pod_cp = copy.deepcopy(pod)
pod_cp.spec.volumes = pod.spec.volumes or []
pod_cp.spec.volumes.insert(0, PodDefaults.VOLUME)
pod_cp.spec.volumes.insert(0, PodDefaultsDeprecated.VOLUME)
pod_cp.spec.containers[0].volume_mounts = pod_cp.spec.containers[0].volume_mounts or []
pod_cp.spec.containers[0].volume_mounts.insert(0, PodDefaults.VOLUME_MOUNT)
pod_cp.spec.containers.append(PodDefaults.SIDECAR_CONTAINER)
pod_cp.spec.containers[0].volume_mounts.insert(0, PodDefaultsDeprecated.VOLUME_MOUNT)
pod_cp.spec.containers.append(PodDefaultsDeprecated.SIDECAR_CONTAINER)

return pod_cp

Expand Down
6 changes: 3 additions & 3 deletions airflow/providers/cncf/kubernetes/pod_launcher_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

from airflow.exceptions import AirflowException, RemovedInAirflow3Warning
from airflow.providers.cncf.kubernetes.kube_client import get_kube_client
from airflow.providers.cncf.kubernetes.pod_generator import PodDefaults
from airflow.providers.cncf.kubernetes.pod_generator import PodDefaultsDeprecated
from airflow.settings import pod_mutation_hook
from airflow.utils.log.logging_mixin import LoggingMixin
from airflow.utils.state import State
Expand Down Expand Up @@ -272,7 +272,7 @@ def _extract_xcom(self, pod: V1Pod):
self._client.connect_get_namespaced_pod_exec,
pod.metadata.name,
pod.metadata.namespace,
container=PodDefaults.SIDECAR_CONTAINER_NAME,
container=PodDefaultsDeprecated.SIDECAR_CONTAINER_NAME,
command=["/bin/sh"],
stdin=True,
stdout=True,
Expand All @@ -281,7 +281,7 @@ def _extract_xcom(self, pod: V1Pod):
_preload_content=False,
)
try:
result = self._exec_pod_command(resp, f"cat {PodDefaults.XCOM_MOUNT_PATH}/return.json")
result = self._exec_pod_command(resp, f"cat {PodDefaultsDeprecated.XCOM_MOUNT_PATH}/return.json")
self._exec_pod_command(resp, "kill -s SIGINT 1")
finally:
resp.close()
Expand Down
2 changes: 1 addition & 1 deletion airflow/providers/cncf/kubernetes/utils/pod_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning
from airflow.providers.cncf.kubernetes.callbacks import ExecutionMode, KubernetesPodOperatorCallback
from airflow.providers.cncf.kubernetes.pod_generator import PodDefaults
from airflow.providers.cncf.kubernetes.utils.xcom_sidecar import PodDefaults
from airflow.utils.log.logging_mixin import LoggingMixin
from airflow.utils.timezone import utcnow

Expand Down
4 changes: 2 additions & 2 deletions tests/providers/cncf/kubernetes/test_pod_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from airflow.exceptions import AirflowConfigException
from airflow.providers.cncf.kubernetes.executors.kubernetes_executor import PodReconciliationError
from airflow.providers.cncf.kubernetes.pod_generator import (
PodDefaults,
PodDefaultsDeprecated,
PodGenerator,
datetime_to_label_safe_datestring,
extend_object_field,
Expand Down Expand Up @@ -174,7 +174,7 @@ def test_gen_pod_extract_xcom(self, mock_rand_str, data_file):
container_two = {
"name": "airflow-xcom-sidecar",
"image": "alpine",
"command": ["sh", "-c", PodDefaults.XCOM_CMD],
"command": ["sh", "-c", PodDefaultsDeprecated.XCOM_CMD],
"volumeMounts": [{"name": "xcom", "mountPath": "/airflow/xcom"}],
"resources": {"requests": {"cpu": "1m"}},
}
Expand Down

0 comments on commit 1bab77a

Please sign in to comment.