You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/02/04 18:55:23 UTC

[GitHub] [airflow] dimberman opened a new pull request #14083: Allow users of the KPO to template environment variables

dimberman opened a new pull request #14083:
URL: https://github.com/apache/airflow/pull/14083


   Addresses https://github.com/apache/airflow/issues/13348
   
   Adds a "templated_fields" variable to k8s.V1EnvVar so jinja templating
   will work when passed by users``
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   ---
   **^ Add meaningful description above**
   
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/master/UPDATING.md).
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] kaxil commented on pull request #14083: Allow users of the KPO to template environment variables

Posted by GitBox <gi...@apache.org>.
kaxil commented on pull request #14083:
URL: https://github.com/apache/airflow/pull/14083#issuecomment-774516166


   @dimberman Master is failing after this PR was merged on k8s tests:
   
   https://github.com/apache/airflow/runs/1842606389#step:9:622
   
   ```
         def test_pod_template_file_with_overrides_system(self):
             fixture = sys.path[0] + '/tests/kubernetes/basic_pod.yaml'
             k = KubernetesPodOperator(
                 task_id="task" + self.get_current_task_name(),
                 labels={"foo": "bar", "fizz": "buzz"},
                 env_vars={"env_name": "value"},
                 in_cluster=False,
                 pod_template_file=fixture,
                 do_xcom_push=True,
             )
         
             context = create_context(k)
             result = k.execute(context)
             assert result is not None
             assert k.pod.metadata.labels == {'fizz': 'buzz', 'foo': 'bar'}
     >       assert k.pod.spec.containers[0].env == [k8s.V1EnvVar(name="env_name", value="value")]
     E       AssertionError: assert [{'name': 'en..._from': None}] == [{'name': 'en..._from': None}]
     E         At index 0 diff: {'name': 'env_name', 'value': 'value', 'value_from': None} != {'name': 'env_name', 'value': 'value', 'value_from': None}
     E         Full diff:
     E           [{'name': 'env_name', 'value': 'value', 'value_from': None}]
     
     kubernetes_tests/test_kubernetes_pod_operator_backcompat.py:587: AssertionError
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] kaxil commented on a change in pull request #14083: Allow users of the KPO to template environment variables

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #14083:
URL: https://github.com/apache/airflow/pull/14083#discussion_r570507670



##########
File path: airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
##########
@@ -271,6 +273,22 @@ def __init__(  # pylint: disable=too-many-arguments,too-many-locals
         self.client: CoreV1Api = None
         self.pod: k8s.V1Pod = None
 
+    def add_template_fields_to_env_vars(self, env_vars):
+        """
+        Adds the field `templated_fields` to V1EnvVar so that Airflow can apply jinja templating
+        to both the name and value of an environment variable.
+
+        Addresses https://github.com/apache/airflow/issues/13348
+        @param env_vars:
+        @return:

Review comment:
       This needs fixing




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] dimberman commented on a change in pull request #14083: Allow users of the KPO to template environment variables

Posted by GitBox <gi...@apache.org>.
dimberman commented on a change in pull request #14083:
URL: https://github.com/apache/airflow/pull/14083#discussion_r570473438



##########
File path: airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
##########
@@ -271,6 +273,22 @@ def __init__(  # pylint: disable=too-many-arguments,too-many-locals
         self.client: CoreV1Api = None
         self.pod: k8s.V1Pod = None
 
+    def add_template_fields_to_env_vars(self, env_vars):

Review comment:
       @kaxil this is specific to the KPO as the k8s.V1EnvVar object doesn't have a templated_fields option. This problem only applies to fields that take in k8s objects. Do you have thoughts on other things that are the same?
   
   The thing you are pointing out says that the FIELD is templatable, but if the object within that field is a class that doesn't have a templated_fields field, then the render template function doesn't know what to do. All other elements in that list are strings or dictionaries so they shouldn't be an issue.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] kaxil commented on a change in pull request #14083: Allow users of the KPO to template environment variables

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #14083:
URL: https://github.com/apache/airflow/pull/14083#discussion_r570507473



##########
File path: airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
##########
@@ -271,6 +273,22 @@ def __init__(  # pylint: disable=too-many-arguments,too-many-locals
         self.client: CoreV1Api = None
         self.pod: k8s.V1Pod = None
 
+    def add_template_fields_to_env_vars(self, env_vars):

Review comment:
       right that's correct




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] kaxil commented on a change in pull request #14083: Allow users of the KPO to template environment variables

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #14083:
URL: https://github.com/apache/airflow/pull/14083#discussion_r570471733



##########
File path: airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
##########
@@ -271,6 +273,22 @@ def __init__(  # pylint: disable=too-many-arguments,too-many-locals
         self.client: CoreV1Api = None
         self.pod: k8s.V1Pod = None
 
+    def add_template_fields_to_env_vars(self, env_vars):

Review comment:
       We should have something generic that applies to all of this in KPO




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] dimberman merged pull request #14083: Allow users of the KPO to template environment variables

Posted by GitBox <gi...@apache.org>.
dimberman merged pull request #14083:
URL: https://github.com/apache/airflow/pull/14083


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] kaxil commented on a change in pull request #14083: Allow users of the KPO to template environment variables

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #14083:
URL: https://github.com/apache/airflow/pull/14083#discussion_r570471504



##########
File path: airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
##########
@@ -271,6 +273,22 @@ def __init__(  # pylint: disable=too-many-arguments,too-many-locals
         self.client: CoreV1Api = None
         self.pod: k8s.V1Pod = None
 
+    def add_template_fields_to_env_vars(self, env_vars):

Review comment:
       https://github.com/apache/airflow/blob/3909232fafd09ac72b49010ecdfd6ea48f06d5cf/airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py#L158-L166




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] github-actions[bot] commented on pull request #14083: Allow users of the KPO to template environment variables

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #14083:
URL: https://github.com/apache/airflow/pull/14083#issuecomment-773740169


   [The Workflow run](https://github.com/apache/airflow/actions/runs/539034343) is cancelling this PR. It has some failed jobs matching ^Pylint$,^Static checks,^Build docs$,^Spell check docs$,^Backport packages$,^Provider packages,^Checks: Helm tests$,^Test OpenAPI*.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] dimberman commented on pull request #14083: Allow users of the KPO to template environment variables

Posted by GitBox <gi...@apache.org>.
dimberman commented on pull request #14083:
URL: https://github.com/apache/airflow/pull/14083#issuecomment-774545387


   @kaxil looking now


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] github-actions[bot] commented on pull request #14083: Allow users of the KPO to template environment variables

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #14083:
URL: https://github.com/apache/airflow/pull/14083#issuecomment-773740521






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] kaxil commented on a change in pull request #14083: Allow users of the KPO to template environment variables

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #14083:
URL: https://github.com/apache/airflow/pull/14083#discussion_r570470770



##########
File path: airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
##########
@@ -271,6 +273,22 @@ def __init__(  # pylint: disable=too-many-arguments,too-many-locals
         self.client: CoreV1Api = None
         self.pod: k8s.V1Pod = None
 
+    def add_template_fields_to_env_vars(self, env_vars):
+        """
+        Adds the field `templated_fields` to V1EnvVar so that Airflow can apply jinja templating
+        to both the name and value of an environment variable.
+
+        Addresses https://github.com/apache/airflow/issues/13348
+        @param env_vars:
+        @return:

Review comment:
       ```suggestion
           @param env_vars:
           @return:
   ```
   
   needs description

##########
File path: airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
##########
@@ -271,6 +273,22 @@ def __init__(  # pylint: disable=too-many-arguments,too-many-locals
         self.client: CoreV1Api = None
         self.pod: k8s.V1Pod = None
 
+    def add_template_fields_to_env_vars(self, env_vars):
+        """
+        Adds the field `templated_fields` to V1EnvVar so that Airflow can apply jinja templating
+        to both the name and value of an environment variable.
+
+        Addresses https://github.com/apache/airflow/issues/13348

Review comment:
       ```suggestion
   
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] dimberman commented on a change in pull request #14083: Allow users of the KPO to template environment variables

Posted by GitBox <gi...@apache.org>.
dimberman commented on a change in pull request #14083:
URL: https://github.com/apache/airflow/pull/14083#discussion_r570473438



##########
File path: airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
##########
@@ -271,6 +273,22 @@ def __init__(  # pylint: disable=too-many-arguments,too-many-locals
         self.client: CoreV1Api = None
         self.pod: k8s.V1Pod = None
 
+    def add_template_fields_to_env_vars(self, env_vars):

Review comment:
       @kaxil this is specific to the KPO as the k8s.V1EnvVar object doesn't have a templated_fields option. This problem only applies to fields that take in k8s objects. Do you have thoughts on other things that are the same?
   
   The thing you are pointing out says that the FIELD is templatable, but if the object within that field is a class that doesn't have a templated_fields field, then the render template function doesn't know what to do. All other elements in that list are strings or dictionaries so they shouldn't be an issue.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] github-actions[bot] commented on pull request #14083: Allow users of the KPO to template environment variables

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #14083:
URL: https://github.com/apache/airflow/pull/14083#issuecomment-774265544


   [The Workflow run](https://github.com/apache/airflow/actions/runs/541199160) is cancelling this PR. Building images for the PR has failed. Follow the the workflow link to check the reason.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] github-actions[bot] commented on pull request #14083: Allow users of the KPO to template environment variables

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #14083:
URL: https://github.com/apache/airflow/pull/14083#issuecomment-774027385


   The PR is likely OK to be merged with just subset of tests for default Python and Database versions without running the full matrix of tests, because it does not modify the core of Airflow. If the committers decide that the full tests matrix is needed, they will add the label 'full tests needed'. Then you should rebase to the latest master or amend the last commit of the PR, and push it with --force-with-lease.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] kaxil commented on a change in pull request #14083: Allow users of the KPO to template environment variables

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #14083:
URL: https://github.com/apache/airflow/pull/14083#discussion_r570470770



##########
File path: airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
##########
@@ -271,6 +273,22 @@ def __init__(  # pylint: disable=too-many-arguments,too-many-locals
         self.client: CoreV1Api = None
         self.pod: k8s.V1Pod = None
 
+    def add_template_fields_to_env_vars(self, env_vars):
+        """
+        Adds the field `templated_fields` to V1EnvVar so that Airflow can apply jinja templating
+        to both the name and value of an environment variable.
+
+        Addresses https://github.com/apache/airflow/issues/13348
+        @param env_vars:
+        @return:

Review comment:
       ```suggestion
           @param env_vars:
           @return:
   ```
   
   needs description

##########
File path: airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
##########
@@ -271,6 +273,22 @@ def __init__(  # pylint: disable=too-many-arguments,too-many-locals
         self.client: CoreV1Api = None
         self.pod: k8s.V1Pod = None
 
+    def add_template_fields_to_env_vars(self, env_vars):
+        """
+        Adds the field `templated_fields` to V1EnvVar so that Airflow can apply jinja templating
+        to both the name and value of an environment variable.
+
+        Addresses https://github.com/apache/airflow/issues/13348

Review comment:
       ```suggestion
   
   ```

##########
File path: airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
##########
@@ -271,6 +273,22 @@ def __init__(  # pylint: disable=too-many-arguments,too-many-locals
         self.client: CoreV1Api = None
         self.pod: k8s.V1Pod = None
 
+    def add_template_fields_to_env_vars(self, env_vars):

Review comment:
       Also this only address Env Variables, what about other template_field

##########
File path: airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
##########
@@ -271,6 +273,22 @@ def __init__(  # pylint: disable=too-many-arguments,too-many-locals
         self.client: CoreV1Api = None
         self.pod: k8s.V1Pod = None
 
+    def add_template_fields_to_env_vars(self, env_vars):

Review comment:
       https://github.com/apache/airflow/blob/3909232fafd09ac72b49010ecdfd6ea48f06d5cf/airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py#L158-L166

##########
File path: airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
##########
@@ -271,6 +273,22 @@ def __init__(  # pylint: disable=too-many-arguments,too-many-locals
         self.client: CoreV1Api = None
         self.pod: k8s.V1Pod = None
 
+    def add_template_fields_to_env_vars(self, env_vars):

Review comment:
       We should have something generic that applies to all of this in KPO

##########
File path: airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
##########
@@ -271,6 +273,22 @@ def __init__(  # pylint: disable=too-many-arguments,too-many-locals
         self.client: CoreV1Api = None
         self.pod: k8s.V1Pod = None
 
+    def add_template_fields_to_env_vars(self, env_vars):

Review comment:
       right that's correct

##########
File path: airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
##########
@@ -271,6 +273,22 @@ def __init__(  # pylint: disable=too-many-arguments,too-many-locals
         self.client: CoreV1Api = None
         self.pod: k8s.V1Pod = None
 
+    def add_template_fields_to_env_vars(self, env_vars):
+        """
+        Adds the field `templated_fields` to V1EnvVar so that Airflow can apply jinja templating
+        to both the name and value of an environment variable.
+
+        Addresses https://github.com/apache/airflow/issues/13348
+        @param env_vars:
+        @return:

Review comment:
       This needs fixing

##########
File path: airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
##########
@@ -271,6 +273,21 @@ def __init__(  # pylint: disable=too-many-arguments,too-many-locals
         self.client: CoreV1Api = None
         self.pod: k8s.V1Pod = None
 
+    def add_template_fields_to_env_vars(self, env_vars):
+        """
+        Adds the field `templated_fields` to V1EnvVar so that Airflow can apply jinja templating

Review comment:
       ```suggestion
           Adds the field ``templated_fields`` to ``V1EnvVar`` so that Airflow can apply jinja templating
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] github-actions[bot] commented on pull request #14083: Allow users of the KPO to template environment variables

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #14083:
URL: https://github.com/apache/airflow/pull/14083#issuecomment-773740169






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] kaxil commented on a change in pull request #14083: Allow users of the KPO to template environment variables

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #14083:
URL: https://github.com/apache/airflow/pull/14083#discussion_r570471165



##########
File path: airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
##########
@@ -271,6 +273,22 @@ def __init__(  # pylint: disable=too-many-arguments,too-many-locals
         self.client: CoreV1Api = None
         self.pod: k8s.V1Pod = None
 
+    def add_template_fields_to_env_vars(self, env_vars):

Review comment:
       Also this only address Env Variables, what about other template_field




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] kaxil commented on a change in pull request #14083: Allow users of the KPO to template environment variables

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #14083:
URL: https://github.com/apache/airflow/pull/14083#discussion_r570507824



##########
File path: airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
##########
@@ -271,6 +273,21 @@ def __init__(  # pylint: disable=too-many-arguments,too-many-locals
         self.client: CoreV1Api = None
         self.pod: k8s.V1Pod = None
 
+    def add_template_fields_to_env_vars(self, env_vars):
+        """
+        Adds the field `templated_fields` to V1EnvVar so that Airflow can apply jinja templating

Review comment:
       ```suggestion
           Adds the field ``templated_fields`` to ``V1EnvVar`` so that Airflow can apply jinja templating
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] ashb commented on pull request #14083: Allow users of the KPO to template environment variables

Posted by GitBox <gi...@apache.org>.
ashb commented on pull request #14083:
URL: https://github.com/apache/airflow/pull/14083#issuecomment-774672849


   Fix incoming.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] kaxil commented on a change in pull request #14083: Allow users of the KPO to template environment variables

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #14083:
URL: https://github.com/apache/airflow/pull/14083#discussion_r570940442



##########
File path: airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
##########
@@ -271,6 +273,21 @@ def __init__(  # pylint: disable=too-many-arguments,too-many-locals
         self.client: CoreV1Api = None
         self.pod: k8s.V1Pod = None
 
+    def add_template_fields_to_env_vars(self, env_vars):
+        """
+        Adds the field ``templated_fields`` to ``V1EnvVar`` so that Airflow can apply jinja templating
+        to both the name and value of an environment variable.
+
+        @param env_vars: a list of k8s.V1EnvVar objects
+        @return: A list of k8s.V1EnvVar objects but with the "template_fields" member populated

Review comment:
       ```suggestion
           :param env_vars: a list of k8s.V1EnvVar objects
           :return: A list of k8s.V1EnvVar objects but with the "template_fields" member populated
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org