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 2020/08/14 23:41:34 UTC

[airflow] 01/04: Allow `image` in `KubernetesPodOperator` to be templated (#10068)

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

kaxilnaik pushed a commit to branch v1-10-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit e97794cb6b87f258a0cf9a7facf98575cc825623
Author: Kaxil Naik <ka...@gmail.com>
AuthorDate: Fri Jul 31 14:25:08 2020 +0100

    Allow `image` in `KubernetesPodOperator` to be templated (#10068)
    
    fixes https://github.com/apache/airflow/issues/10063
    
    (cherry picked from commit 03c43517445019081c55b4ac5fad3b0debdee336)
---
 airflow/contrib/operators/kubernetes_pod_operator.py        |  2 +-
 .../cncf/kubernetes/operators/test_kubernetes_pod.py        | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/airflow/contrib/operators/kubernetes_pod_operator.py b/airflow/contrib/operators/kubernetes_pod_operator.py
index 98464b7..3c7c5a8 100644
--- a/airflow/contrib/operators/kubernetes_pod_operator.py
+++ b/airflow/contrib/operators/kubernetes_pod_operator.py
@@ -141,7 +141,7 @@ class KubernetesPodOperator(BaseOperator):  # pylint: disable=too-many-instance-
     :param pod_template_file: path to pod template file
     :type pod_template_file: str
     """
-    template_fields = ('cmds', 'arguments', 'env_vars', 'config_file', 'pod_template_file')
+    template_fields = ('image', 'cmds', 'arguments', 'env_vars', 'config_file', 'pod_template_file')
 
     @apply_defaults
     def __init__(self,  # pylint: disable=too-many-arguments,too-many-locals
diff --git a/tests/providers/cncf/kubernetes/operators/test_kubernetes_pod.py b/tests/providers/cncf/kubernetes/operators/test_kubernetes_pod.py
index f20ac2d..6b961e7 100644
--- a/tests/providers/cncf/kubernetes/operators/test_kubernetes_pod.py
+++ b/tests/providers/cncf/kubernetes/operators/test_kubernetes_pod.py
@@ -143,3 +143,16 @@ class TestKubernetesPodOperator(unittest.TestCase):
             context = self.create_context(k)
             k.execute(context=context)
         assert delete_pod_mock.called
+
+    def test_jinja_templated_fields(self):
+        task = KubernetesPodOperator(
+            namespace='default',
+            image="{{ image_jinja }}:16.04",
+            cmds=["bash", "-cx"],
+            name="test_pod",
+            task_id="task",
+        )
+
+        self.assertEqual(task.image, "{{ image_jinja }}:16.04")
+        task.render_template_fields(context={"image_jinja": "ubuntu"})
+        self.assertEqual(task.image, "ubuntu:16.04")