This is an automated email from the ASF dual-hosted git repository.

taragolis pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 4767f48a3b feat: add hostAliases to pod spec in KubernetesPodOperator 
(#35063)
4767f48a3b is described below

commit 4767f48a3b4537092e62fc2f91ec832dd560db72
Author: Isaac A. Murchie <isaac.app...@gmail.com>
AuthorDate: Tue Oct 24 19:08:49 2023 -0400

    feat: add hostAliases to pod spec in KubernetesPodOperator (#35063)
    
    * feat: add hostAliases to pod spec in KubernetesPodOperator
    
    * chore: remove extra whitespace
    
    ---------
    
    Co-authored-by: Isaac Murchie <isaac.murc...@benevolent.ai>
---
 airflow/providers/cncf/kubernetes/operators/pod.py    | 4 ++++
 tests/providers/cncf/kubernetes/operators/test_pod.py | 9 +++++++++
 2 files changed, 13 insertions(+)

diff --git a/airflow/providers/cncf/kubernetes/operators/pod.py 
b/airflow/providers/cncf/kubernetes/operators/pod.py
index d8b01b155b..ff3e32e8c7 100644
--- a/airflow/providers/cncf/kubernetes/operators/pod.py
+++ b/airflow/providers/cncf/kubernetes/operators/pod.py
@@ -200,6 +200,7 @@ class KubernetesPodOperator(BaseOperator):
         comma separated list: secret_a,secret_b
     :param service_account_name: Name of the service account
     :param hostnetwork: If True enable host networking on the pod.
+    :param host_aliases: A list of host aliases to apply to the containers in 
the pod.
     :param tolerations: A list of kubernetes tolerations.
     :param security_context: security options the pod should run with 
(PodSecurityContext).
     :param container_security_context: security options the container should 
run with.
@@ -303,6 +304,7 @@ class KubernetesPodOperator(BaseOperator):
         image_pull_secrets: list[k8s.V1LocalObjectReference] | None = None,
         service_account_name: str | None = None,
         hostnetwork: bool = False,
+        host_aliases: list[k8s.V1HostAlias] | None = None,
         tolerations: list[k8s.V1Toleration] | None = None,
         security_context: k8s.V1PodSecurityContext | dict | None = None,
         container_security_context: k8s.V1SecurityContext | dict | None = None,
@@ -381,6 +383,7 @@ class KubernetesPodOperator(BaseOperator):
         self.image_pull_secrets = 
convert_image_pull_secrets(image_pull_secrets) if image_pull_secrets else []
         self.service_account_name = service_account_name
         self.hostnetwork = hostnetwork
+        self.host_aliases = host_aliases
         self.tolerations = (
             [convert_toleration(toleration) for toleration in tolerations] if 
tolerations else []
         )
@@ -897,6 +900,7 @@ class KubernetesPodOperator(BaseOperator):
                 affinity=self.affinity,
                 tolerations=self.tolerations,
                 init_containers=self.init_containers,
+                host_aliases=self.host_aliases,
                 containers=[
                     k8s.V1Container(
                         image=self.image,
diff --git a/tests/providers/cncf/kubernetes/operators/test_pod.py 
b/tests/providers/cncf/kubernetes/operators/test_pod.py
index 42fd7ecfe4..8a4927a65c 100644
--- a/tests/providers/cncf/kubernetes/operators/test_pod.py
+++ b/tests/providers/cncf/kubernetes/operators/test_pod.py
@@ -226,6 +226,15 @@ class TestKubernetesPodOperator:
         pod = k.build_pod_request_obj(create_context(k))
         assert pod.spec.security_context == security_context
 
+    def test_host_aliases(self):
+        host_aliases = [k8s.V1HostAlias(ip="192.0.2.1", 
hostnames=["my.service.com"])]
+        k = KubernetesPodOperator(
+            host_aliases=host_aliases,
+            task_id="task",
+        )
+        pod = k.build_pod_request_obj(create_context(k))
+        assert pod.spec.host_aliases == host_aliases
+
     def test_container_security_context(self):
         container_security_context = {"allowPrivilegeEscalation": False}
         k = KubernetesPodOperator(

Reply via email to