You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ka...@apache.org on 2021/06/03 13:54:42 UTC

[airflow] branch main updated: Bug Pod Template File Values Ignored (#16095)

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

kaxilnaik 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 2f16757  Bug Pod Template File Values Ignored (#16095)
2f16757 is described below

commit 2f16757e1a11ef42ac2b1a62622a5d34f8a1e996
Author: jpyen <29...@users.noreply.github.com>
AuthorDate: Thu Jun 3 06:54:16 2021 -0700

    Bug Pod Template File Values Ignored (#16095)
    
    These seem to be the remaining values which are forcefully ignored when set by a pod-template, due to their default values in the constructor. Furthermore I do not see the value of a "test_image_pull_policy_not_set" test or feature, since k8s already provides a default value for image_pull_policy.
---
 airflow/providers/cncf/kubernetes/CHANGELOG.rst      | 10 ++++++++++
 .../cncf/kubernetes/operators/kubernetes_pod.py      |  4 ++--
 kubernetes_tests/test_kubernetes_pod_operator.py     |  4 ----
 .../test_kubernetes_pod_operator_backcompat.py       |  2 --
 .../cncf/kubernetes/operators/test_kubernetes_pod.py | 20 ++++----------------
 5 files changed, 16 insertions(+), 24 deletions(-)

diff --git a/airflow/providers/cncf/kubernetes/CHANGELOG.rst b/airflow/providers/cncf/kubernetes/CHANGELOG.rst
index e1eed99..dffe255 100644
--- a/airflow/providers/cncf/kubernetes/CHANGELOG.rst
+++ b/airflow/providers/cncf/kubernetes/CHANGELOG.rst
@@ -19,6 +19,16 @@
 Changelog
 ---------
 
+
+1.2.1
+.....
+
+Bug Fixes
+~~~~~~~~~
+
+* ``Remove image_pull_policy 'IfNotPresent' default as k8s already defaults to 'Always' if :latest tag is specified, or 'IfNotPresent' otherwise (#15388)``
+* ``Remove service_account_name 'default' default as k8s already defaults to 'default' if not set (#15388)``
+
 1.2.0
 .....
 
diff --git a/airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py b/airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
index 463900d..06d54dc 100644
--- a/airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
+++ b/airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
@@ -196,7 +196,7 @@ class KubernetesPodOperator(BaseOperator):  # pylint: disable=too-many-instance-
         reattach_on_restart: bool = True,
         startup_timeout_seconds: int = 120,
         get_logs: bool = True,
-        image_pull_policy: str = 'IfNotPresent',
+        image_pull_policy: Optional[str] = None,
         annotations: Optional[Dict] = None,
         resources: Optional[k8s.V1ResourceRequirements] = None,
         affinity: Optional[k8s.V1Affinity] = None,
@@ -204,7 +204,7 @@ class KubernetesPodOperator(BaseOperator):  # pylint: disable=too-many-instance-
         node_selectors: Optional[dict] = None,
         node_selector: Optional[dict] = None,
         image_pull_secrets: Optional[List[k8s.V1LocalObjectReference]] = None,
-        service_account_name: str = 'default',
+        service_account_name: Optional[str] = None,
         is_delete_operator_pod: bool = False,
         hostnetwork: bool = False,
         tolerations: Optional[List[k8s.V1Toleration]] = None,
diff --git a/kubernetes_tests/test_kubernetes_pod_operator.py b/kubernetes_tests/test_kubernetes_pod_operator.py
index 9d9502a..a5ec7b8 100644
--- a/kubernetes_tests/test_kubernetes_pod_operator.py
+++ b/kubernetes_tests/test_kubernetes_pod_operator.py
@@ -95,7 +95,6 @@ class TestKubernetesPodOperatorSystem(unittest.TestCase):
                 'containers': [
                     {
                         'image': 'ubuntu:16.04',
-                        'imagePullPolicy': 'IfNotPresent',
                         'args': ["echo 10"],
                         'command': ["bash", "-cx"],
                         'env': [],
@@ -112,7 +111,6 @@ class TestKubernetesPodOperatorSystem(unittest.TestCase):
                 'nodeSelector': {},
                 'restartPolicy': 'Never',
                 'securityContext': {},
-                'serviceAccountName': 'default',
                 'tolerations': [],
                 'volumes': [],
             },
@@ -873,7 +871,6 @@ class TestKubernetesPodOperatorSystem(unittest.TestCase):
                         'env': [],
                         'envFrom': [],
                         'image': 'apache/airflow-ci:stress-2021.04.28-1.0.4',
-                        'imagePullPolicy': 'IfNotPresent',
                         'name': 'base',
                         'ports': [],
                         'resources': {'limits': {'memory': '200Mi'}, 'requests': {'memory': '100Mi'}},
@@ -893,7 +890,6 @@ class TestKubernetesPodOperatorSystem(unittest.TestCase):
                 'nodeSelector': {},
                 'restartPolicy': 'Never',
                 'securityContext': {},
-                'serviceAccountName': 'default',
                 'tolerations': [],
                 'volumes': [{'emptyDir': {}, 'name': 'xcom'}],
             },
diff --git a/kubernetes_tests/test_kubernetes_pod_operator_backcompat.py b/kubernetes_tests/test_kubernetes_pod_operator_backcompat.py
index 07cd167..0a88f41 100644
--- a/kubernetes_tests/test_kubernetes_pod_operator_backcompat.py
+++ b/kubernetes_tests/test_kubernetes_pod_operator_backcompat.py
@@ -94,7 +94,6 @@ class TestKubernetesPodOperatorSystem(unittest.TestCase):
                 'containers': [
                     {
                         'image': 'ubuntu:16.04',
-                        'imagePullPolicy': 'IfNotPresent',
                         'args': ["echo 10"],
                         'command': ["bash", "-cx"],
                         'env': [],
@@ -111,7 +110,6 @@ class TestKubernetesPodOperatorSystem(unittest.TestCase):
                 'nodeSelector': {},
                 'restartPolicy': 'Never',
                 'securityContext': {},
-                'serviceAccountName': 'default',
                 'tolerations': [],
                 'volumes': [],
             },
diff --git a/tests/providers/cncf/kubernetes/operators/test_kubernetes_pod.py b/tests/providers/cncf/kubernetes/operators/test_kubernetes_pod.py
index 2da7e8b..a2ee0e6 100644
--- a/tests/providers/cncf/kubernetes/operators/test_kubernetes_pod.py
+++ b/tests/providers/cncf/kubernetes/operators/test_kubernetes_pod.py
@@ -171,22 +171,6 @@ class TestKubernetesPodOperator(unittest.TestCase):
         pod = k.create_pod_request_obj()
         assert pod.spec.image_pull_secrets == [k8s.V1LocalObjectReference(name=fake_pull_secrets)]
 
-    def test_image_pull_policy_not_set(self):
-        k = KubernetesPodOperator(
-            namespace="default",
-            image="ubuntu:16.04",
-            cmds=["bash", "-cx"],
-            arguments=["echo 10"],
-            labels={"foo": "bar"},
-            name="test",
-            task_id="task",
-            in_cluster=False,
-            do_xcom_push=False,
-            cluster_context="default",
-        )
-        pod = k.create_pod_request_obj()
-        assert pod.spec.containers[0].image_pull_policy == "IfNotPresent"
-
     def test_image_pull_policy_correctly_set(self):
         k = KubernetesPodOperator(
             namespace="default",
@@ -334,6 +318,7 @@ class TestKubernetesPodOperator(unittest.TestCase):
               labels:
                 foo: bar
             spec:
+              serviceAccountName: foo
               affinity:
                 nodeAffinity:
                   requiredDuringSchedulingIgnoredDuringExecution:
@@ -356,6 +341,7 @@ class TestKubernetesPodOperator(unittest.TestCase):
               containers:
                 - name: base
                   image: ubuntu:16.04
+                  imagePullPolicy: Always
                   command:
                     - something
         """
@@ -384,7 +370,9 @@ class TestKubernetesPodOperator(unittest.TestCase):
             }
             assert pod.metadata.namespace == "mynamespace"
             assert pod.spec.containers[0].image == "ubuntu:16.04"
+            assert pod.spec.containers[0].image_pull_policy == "Always"
             assert pod.spec.containers[0].command == ["something"]
+            assert pod.spec.service_account_name == "foo"
             affinity = {
                 'node_affinity': {
                     'preferred_during_scheduling_ignored_during_execution': [