Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow xcom sidecar container image to be configurable #26766

Merged
merged 61 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from 7 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
8 changes: 8 additions & 0 deletions airflow/config_templates/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2425,6 +2425,14 @@
type: string
example: '{"grace_period_seconds": 10}'
default: ""
- name: sidecar_container_image
description: |
Define the ``image`` used by the ``PodDefaults.SIDECAR_CONTAINER`` to allow private repositories,
as well as custom image overrides.
version_added: 2.4.1
type: string
example: ~
default: "alpine"
- name: enable_tcp_keepalive
description: |
Enables TCP keepalive mechanism. This prevents Kubernetes API requests to hang indefinitely
Expand Down
4 changes: 4 additions & 0 deletions airflow/config_templates/default_airflow.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,10 @@ kube_client_request_args =
# Example: delete_option_kwargs = {{"grace_period_seconds": 10}}
delete_option_kwargs =

# Define the ``image`` used by the ``PodDefaults.SIDECAR_CONTAINER`` to allow private repositories,
# as well as custom image overrides.
sidecar_container_image = alpine

# Enables TCP keepalive mechanism. This prevents Kubernetes API requests to hang indefinitely
# when idle connection is time-outed on services like cloud load balancers or firewalls.
enable_tcp_keepalive = True
Expand Down
6 changes: 5 additions & 1 deletion airflow/kubernetes/pod_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from kubernetes.client import models as k8s
from kubernetes.client.api_client import ApiClient

from airflow.configuration import conf
from airflow.exceptions import AirflowConfigException, PodReconciliationError, RemovedInAirflow3Warning
from airflow.kubernetes.pod_generator_deprecated import PodDefaults, PodGenerator as PodGeneratorDeprecated
from airflow.utils import yaml
Expand Down Expand Up @@ -146,7 +147,10 @@ def add_xcom_sidecar(pod: k8s.V1Pod) -> k8s.V1Pod:
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 = conf.get('kubernetes', 'sidecar_container_image', fallback=sidecar.image)
pod_cp.spec.containers.append(sidecar)

return pod_cp

Expand Down
7 changes: 6 additions & 1 deletion airflow/kubernetes/pod_generator_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

from kubernetes.client import models as k8s

from airflow.configuration import conf

MAX_POD_ID_LEN = 253

MAX_LABEL_LEN = 63
Expand Down Expand Up @@ -236,7 +238,10 @@ def add_sidecar(pod: k8s.V1Pod) -> k8s.V1Pod:
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 = conf.get('kubernetes', 'sidecar_container_image', fallback=sidecar.image)
pod_cp.spec.containers.append(sidecar)

return pod_cp

Expand Down
7 changes: 6 additions & 1 deletion airflow/providers/cncf/kubernetes/utils/xcom_sidecar.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

from kubernetes.client import models as k8s

from airflow.configuration import conf


class PodDefaults:
"""Static defaults for Pods"""
Expand Down Expand Up @@ -54,6 +56,9 @@ def add_xcom_sidecar(pod: k8s.V1Pod) -> k8s.V1Pod:
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 = conf.get('kubernetes', 'sidecar_container_image', fallback=sidecar.image)
pod_cp.spec.containers.append(sidecar)

return pod_cp
9 changes: 9 additions & 0 deletions tests/kubernetes/test_pod_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
merge_objects,
)
from airflow.kubernetes.secret import Secret
from tests.test_utils.config import conf_vars


class TestPodGenerator:
Expand Down Expand Up @@ -777,3 +778,11 @@ def test_validate_pod_generator(self):
PodGenerator()
PodGenerator(pod_template_file='tests/kubernetes/pod.yaml')
PodGenerator(pod=k8s.V1Pod())

@conf_vars({('kubernetes', 'sidecar_container_image'): 'private.repo.com/alpine:3.16.2'})
def test_customize_sidecar_container_image(self):
pod = PodGenerator.add_xcom_sidecar(
PodGenerator(pod_template_file='tests/kubernetes/pod.yaml').gen_pod()
)

assert pod.spec.containers[-1].image == 'private.repo.com/alpine:3.16.2'