Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
2a17603
Update default_airflow.cfg
bdsoha Sep 29, 2022
d67caff
Update xcom_sidecar.py
bdsoha Sep 29, 2022
ce01a96
Update xcom_sidecar.py
bdsoha Sep 29, 2022
c501a6c
Merge branch 'main' into feature/sidecar_container
bdsoha Sep 29, 2022
24d037c
Merge branch 'main' into feature/sidecar_container
bdsoha Sep 29, 2022
0f06b13
Added SIDECAR_CONTAINER config to deprecated code
bdsoha Sep 29, 2022
13b92cb
Reverted to mistaken image name
bdsoha Sep 29, 2022
b324533
fixed static styling and config.yml
bdsoha Sep 29, 2022
713f825
Merge branch 'main' into feature/sidecar_container
bdsoha Sep 29, 2022
fcc9a79
added unit tests
bdsoha Sep 29, 2022
a8f6f1e
Update default_airflow.cfg
bdsoha Sep 29, 2022
092cd4f
Update xcom_sidecar.py
bdsoha Sep 29, 2022
f43fc3c
Update xcom_sidecar.py
bdsoha Sep 29, 2022
23b0ab8
Added SIDECAR_CONTAINER config to deprecated code
bdsoha Sep 29, 2022
7cbda77
Reverted to mistaken image name
bdsoha Sep 29, 2022
a435fce
fixed static styling and config.yml
bdsoha Sep 29, 2022
cf0c9a6
added unit tests
bdsoha Sep 29, 2022
a77924a
added connection options to control xcom sidecar image
bdsoha Sep 30, 2022
6429038
added connection options to control xcom sidecar image
bdsoha Sep 30, 2022
d99d23d
added docs and removed old changes
bdsoha Sep 30, 2022
3912c77
updated docs to include default
bdsoha Sep 30, 2022
770da40
fixed static styling
bdsoha Sep 30, 2022
4635277
fixed k8s hook mock
bdsoha Sep 30, 2022
c7d4828
Merge branch 'main' into feature/sidecar_container
bdsoha Sep 30, 2022
101084b
changed xcom_sidecar_container_image to get_xcom_sidecar_container_image
bdsoha Oct 1, 2022
a90d05c
Merge branch 'feature/sidecar_container' of github.com:bdsoha/airflow…
bdsoha Oct 1, 2022
2cf5f39
Merge branch 'main' into feature/sidecar_container
bdsoha Oct 1, 2022
06e253f
Merge branch 'main' into feature/sidecar_container
bdsoha Oct 2, 2022
71c6b05
make xcom image optional
bdsoha Oct 2, 2022
cc84458
removed duplicate image name
bdsoha Oct 2, 2022
fe21f08
fixed error on empty string:
bdsoha Oct 3, 2022
e13a0d0
Merge branch 'main' into feature/sidecar_container
bdsoha Oct 3, 2022
64a9f66
Merge branch 'main' into feature/sidecar_container
bdsoha Oct 4, 2022
193757a
using option kwargs
bdsoha Oct 5, 2022
72aac6a
Merge branch 'feature/sidecar_container' of github.com:bdsoha/airflow…
bdsoha Oct 5, 2022
dc9214d
Merge branch 'main' into feature/sidecar_container
bdsoha Oct 5, 2022
03cb874
added KPO tests
bdsoha Oct 6, 2022
26ac87e
Merge branch 'feature/sidecar_container' of github.com:bdsoha/airflow…
bdsoha Oct 6, 2022
7355345
Merge branch 'main' into feature/sidecar_container
bdsoha Oct 6, 2022
d3cba11
changing image value to None
bdsoha Oct 6, 2022
b1ddc6f
Merge branch 'main' into feature/sidecar_container
bdsoha Oct 6, 2022
af6bdca
Merge branch 'main' into feature/sidecar_container
bdsoha Oct 6, 2022
40646a0
Merge branch 'main' into feature/sidecar_container
bdsoha Oct 6, 2022
151a171
Merge branch 'main' into feature/sidecar_container
bdsoha Oct 14, 2022
ea055c3
Merge branch 'main' into feature/sidecar_container
bdsoha Oct 14, 2022
6e7e037
Merge branch 'main' into feature/sidecar_container
bdsoha Oct 15, 2022
b4bd0fb
Merge branch 'main' into feature/sidecar_container
bdsoha Oct 17, 2022
2093f35
Merge branch 'main' into feature/sidecar_container
bdsoha Oct 18, 2022
93735a7
fixed kubernetes_tests
bdsoha Oct 19, 2022
99314fa
Merge branch 'main' into feature/sidecar_container
bdsoha Oct 19, 2022
4bde352
Merge branch 'main' into feature/sidecar_container
bdsoha Oct 19, 2022
9e055d4
removed extra prefix
bdsoha Oct 23, 2022
5504929
Merge branch 'main' into feature/sidecar_container
bdsoha Oct 23, 2022
b44d81c
Merge branch 'main' into feature/sidecar_container
bdsoha Oct 24, 2022
bc77a52
Using double quotes instead of single
bdsoha Oct 24, 2022
73dab21
Merge branch 'main' into feature/sidecar_container
bdsoha Oct 24, 2022
ad28a80
Merge branch 'apache:main' into feature/sidecar_container
bdsoha Oct 27, 2022
42e7137
Merge branch 'main' into feature/sidecar_container
bdsoha Oct 27, 2022
1afda3e
Merge branch 'main' into feature/sidecar_container
bdsoha Oct 27, 2022
443c822
Update airflow/providers/cncf/kubernetes/hooks/kubernetes.py
bdsoha Nov 8, 2022
540c2d2
Update airflow/providers/cncf/kubernetes/hooks/kubernetes.py
bdsoha Nov 8, 2022
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
7 changes: 7 additions & 0 deletions airflow/providers/cncf/kubernetes/hooks/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def get_connection_form_widgets() -> dict[str, Any]:
"cluster_context": StringField(lazy_gettext("Cluster context"), widget=BS3TextFieldWidget()),
"disable_verify_ssl": BooleanField(lazy_gettext("Disable SSL")),
"disable_tcp_keepalive": BooleanField(lazy_gettext("Disable TCP keepalive")),
"xcom_sidecar_container_image": StringField(
lazy_gettext("XCom sidecar image"), widget=BS3TextFieldWidget()
),
}

@staticmethod
Expand Down Expand Up @@ -347,6 +350,10 @@ def _get_namespace(self) -> str | None:
return self._get_field("namespace")
return None

def get_xcom_sidecar_container_image(self):
"""Returns the xcom sidecar image that defined in the connection"""
return self._get_field("xcom_sidecar_container_image")

def get_pod_log_stream(
self,
pod_name: str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,9 @@ 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)
pod = xcom_sidecar.add_xcom_sidecar(pod)
pod = xcom_sidecar.add_xcom_sidecar(
pod, sidecar_container_image=self.hook.get_xcom_sidecar_container_image()
)

labels = self._get_ti_pod_labels(context)
self.log.info("Building pod %s with labels: %s", pod.metadata.name, labels)
Expand Down
6 changes: 4 additions & 2 deletions airflow/providers/cncf/kubernetes/utils/xcom_sidecar.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ class PodDefaults:
)


def add_xcom_sidecar(pod: k8s.V1Pod) -> k8s.V1Pod:
def add_xcom_sidecar(pod: k8s.V1Pod, *, sidecar_container_image=None) -> k8s.V1Pod:
"""Adds 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.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)
sidecar = copy.deepcopy(PodDefaults.SIDECAR_CONTAINER)
sidecar.image = sidecar_container_image or PodDefaults.SIDECAR_CONTAINER.image
pod_cp.spec.containers.append(sidecar)

return pod_cp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ Disable TCP keepalive
TCP keepalive is a feature (enabled by default) that tries to keep long-running connections
alive. Set this parameter to True to disable this feature.

Xcom sidecar image
Define the ``image`` used by the ``PodDefaults.SIDECAR_CONTAINER`` (defaults to ``"alpine"``) to allow private
repositories, as well as custom image overrides.

Example storing connection in env var using URI format:

.. code-block:: bash
Expand Down
1 change: 1 addition & 0 deletions kubernetes_tests/test_kubernetes_pod_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,7 @@ def test_pod_template_file(
# todo: This isn't really a system test
await_xcom_sidecar_container_start_mock.return_value = None
hook_mock.return_value.is_in_cluster = False
hook_mock.return_value.get_xcom_sidecar_container_image.return_value = None
extract_xcom_mock.return_value = "{}"
path = sys.path[0] + "/tests/kubernetes/pod.yaml"
k = KubernetesPodOperator(
Expand Down
13 changes: 13 additions & 0 deletions tests/providers/cncf/kubernetes/hooks/test_kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def setup_class(cls) -> None:
("disable_verify_ssl_empty", {"disable_verify_ssl": ""}),
("disable_tcp_keepalive", {"disable_tcp_keepalive": True}),
("disable_tcp_keepalive_empty", {"disable_tcp_keepalive": ""}),
("sidecar_container_image", {"xcom_sidecar_container_image": "private.repo.com/alpine:3.16"}),
("sidecar_container_image_empty", {"xcom_sidecar_container_image": ""}),
]:
db.merge_conn(Connection(conn_type="kubernetes", conn_id=conn_id, extra=json.dumps(extra)))

Expand Down Expand Up @@ -316,6 +318,17 @@ def test_get_namespace(self, conn_id, expected):
"and rename _get_namespace to get_namespace."
)

@pytest.mark.parametrize(
"conn_id, expected",
(
pytest.param("sidecar_container_image", "private.repo.com/alpine:3.16", id="sidecar-with-image"),
pytest.param("sidecar_container_image_empty", None, id="sidecar-without-image"),
),
)
def test_get_xcom_sidecar_container_image(self, conn_id, expected):
hook = KubernetesHook(conn_id=conn_id)
assert hook.get_xcom_sidecar_container_image() == expected

@patch("kubernetes.config.kube_config.KubeConfigLoader")
@patch("kubernetes.config.kube_config.KubeConfigMerger")
def test_client_types(self, mock_kube_config_merger, mock_kube_config_loader):
Expand Down
22 changes: 22 additions & 0 deletions tests/providers/cncf/kubernetes/operators/test_kubernetes_pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,28 @@ def test_omitted_namespace_no_conn_not_in_k8s(self, mock_find, mock_path):
)
mock_find.assert_called_once_with("default", context=context)

@patch(HOOK_CLASS)
def test_xcom_sidecar_container_image_default(self, hook_mock):
hook_mock.return_value.get_xcom_sidecar_container_image.return_value = None
k = KubernetesPodOperator(
name="test",
task_id="task",
do_xcom_push=True,
)
pod = k.build_pod_request_obj(create_context(k))
assert pod.spec.containers[1].image == "alpine"

@patch(HOOK_CLASS)
def test_xcom_sidecar_container_image_custom(self, hook_mock):
hook_mock.return_value.get_xcom_sidecar_container_image.return_value = "private.repo/alpine:3.13"
k = KubernetesPodOperator(
name="test",
task_id="task",
do_xcom_push=True,
)
pod = k.build_pod_request_obj(create_context(k))
assert pod.spec.containers[1].image == "private.repo/alpine:3.13"

def test_image_pull_policy_correctly_set(self):
k = KubernetesPodOperator(
task_id="task",
Expand Down