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 2022/08/11 09:42:05 UTC

[GitHub] [airflow] fletchjeff opened a new pull request, #25663: Working @task.kubernetes decorator

fletchjeff opened a new pull request, #25663:
URL: https://github.com/apache/airflow/pull/25663

   Adds the `@task.kubernetes` decorator to run arbitrary python code in a DAG in a k8s pod using the KubernetesPodOperator.
   
   closes: https://github.com/apache/airflow/issues/19135
   
   This fixes some of the changes requested with pull request [21077](https://github.com/apache/airflow/pull/21077). Shout out to @subkanthi who did most of the work, I just made the final requested changes.
   
   The `python_kubernetes_script.py` and `python_kubernetes_script.jinja2` are now in the `airflow/providers/cncf/kubernetes` folder.
   
   ---
   **^ Add meaningful description above**
   
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+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 a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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


[GitHub] [airflow] kaxil commented on a diff in pull request #25663: Add @task.kubernetes taskflow decorator

Posted by GitBox <gi...@apache.org>.
kaxil commented on code in PR #25663:
URL: https://github.com/apache/airflow/pull/25663#discussion_r944287454


##########
airflow/decorators/__init__.pyi:
##########
@@ -22,11 +22,14 @@
 
 from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional, Union, overload
 
+from kubernetes.client import models as k8s

Review Comment:
   oh wait, this is `.pyi` file



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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


[GitHub] [airflow] josh-fell commented on a diff in pull request #25663: Add @task.kubernetes taskflow decorator

Posted by GitBox <gi...@apache.org>.
josh-fell commented on code in PR #25663:
URL: https://github.com/apache/airflow/pull/25663#discussion_r948047987


##########
airflow/example_dags/example_kubernetes_decorator.py:
##########
@@ -0,0 +1,68 @@
+#

Review Comment:
   Should this example live with the Kubernetes provider instead of core Airflow? 
   
   Or since this example DAG is net-new, should this actually be AIP-47 compliant as a provider system test similar to the [`@task.docker` example](https://github.com/apache/airflow/blob/main/tests/system/providers/docker/example_taskflow_api_etl_docker_virtualenv.py)?



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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


[GitHub] [airflow] fletchjeff commented on pull request #25663: Add @task.kubernetes taskflow decorator

Posted by GitBox <gi...@apache.org>.
fletchjeff commented on PR #25663:
URL: https://github.com/apache/airflow/pull/25663#issuecomment-1223932784

   Thank you all!! Super excited to get to use this 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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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


[GitHub] [airflow] boring-cyborg[bot] commented on pull request #25663: Add @task.kubernetes taskflow decorator

Posted by GitBox <gi...@apache.org>.
boring-cyborg[bot] commented on PR #25663:
URL: https://github.com/apache/airflow/pull/25663#issuecomment-1222721355

   Awesome work, congrats on your first merged pull request!
   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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


[GitHub] [airflow] kaxil commented on pull request #25663: Add @task.kubernetes taskflow decorator

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

   @fletchjeff Thanks for staying on top of this 🎉 


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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


[GitHub] [airflow] boring-cyborg[bot] commented on pull request #25663: Working @task.kubernetes decorator

Posted by GitBox <gi...@apache.org>.
boring-cyborg[bot] commented on PR #25663:
URL: https://github.com/apache/airflow/pull/25663#issuecomment-1211760775

   Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
   Here are some useful points:
   - Pay attention to the quality of your code (flake8, mypy and type annotations). Our [pre-commits]( https://github.com/apache/airflow/blob/main/STATIC_CODE_CHECKS.rst#prerequisites-for-pre-commit-hooks) will help you with that.
   - In case of a new feature add useful documentation (in docstrings or in `docs/` directory). Adding a new operator? Check this short [guide](https://github.com/apache/airflow/blob/main/docs/apache-airflow/howto/custom-operator.rst) Consider adding an example DAG that shows how users should use it.
   - Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/BREEZE.rst) for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
   - Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
   - Please follow [ASF Code of Conduct](https://www.apache.org/foundation/policies/conduct) for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
   - Be sure to read the [Airflow Coding style]( https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#coding-style-and-best-practices).
   Apache Airflow is a community-driven project and together we are making it better 🚀.
   In case of doubts contact the developers at:
   Mailing List: dev@airflow.apache.org
   Slack: https://s.apache.org/airflow-slack
   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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


[GitHub] [airflow] uranusjr commented on a diff in pull request #25663: Add @task.kubernetes taskflow decorator

Posted by GitBox <gi...@apache.org>.
uranusjr commented on code in PR #25663:
URL: https://github.com/apache/airflow/pull/25663#discussion_r948112384


##########
airflow/example_dags/example_kubernetes_decorator.py:
##########
@@ -0,0 +1,68 @@
+#

Review Comment:
   > should this actually be AIP-47 compliant as a provider system test similar to the `@task.docker` example?
   
   Oh yes. The example DAG was implemented way before AIP-47 was accepted (shows how long this dragged on…)
   
   I’ll add a commit to convert it.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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


[GitHub] [airflow] kaxil commented on pull request #25663: Add @task.kubernetes taskflow decorator

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

   Thanks for making this cross the finish line @fletchjeff 


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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


[GitHub] [airflow] uranusjr merged pull request #25663: Add @task.kubernetes taskflow decorator

Posted by GitBox <gi...@apache.org>.
uranusjr merged PR #25663:
URL: https://github.com/apache/airflow/pull/25663


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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


[GitHub] [airflow] uranusjr commented on a diff in pull request #25663: Add @task.kubernetes taskflow decorator

Posted by GitBox <gi...@apache.org>.
uranusjr commented on code in PR #25663:
URL: https://github.com/apache/airflow/pull/25663#discussion_r944274148


##########
airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py:
##########
@@ -147,7 +147,6 @@ class KubernetesPodOperator(BaseOperator):
         to populate the environment variables with. The contents of the target
         ConfigMap's Data field will represent the key-value pairs as environment variables.
         Extends env_from.
-    :param: kubernetes_conn_id: To retrieve credentials for your k8s cluster from an Airflow connection

Review Comment:
   This docstring is duplicated; there’s already one near the top, so I took the chance to remove it.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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


[GitHub] [airflow] kaxil commented on a diff in pull request #25663: Add @task.kubernetes taskflow decorator

Posted by GitBox <gi...@apache.org>.
kaxil commented on code in PR #25663:
URL: https://github.com/apache/airflow/pull/25663#discussion_r944290506


##########
airflow/example_dags/example_kubernetes_decorator.py:
##########
@@ -0,0 +1,68 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+This is an example dag for using the @task.kubernetes decorator.
+"""
+
+from datetime import datetime
+
+from airflow import DAG
+from airflow.decorators import task
+
+with DAG(
+    dag_id='example_kubernetes_decorator',
+    schedule_interval=None,
+    start_date=datetime(2021, 1, 1),
+    tags=['example'],
+    catchup=False,
+) as dag:
+
+    @task.kubernetes(
+        image='python:3.8-slim-buster',
+        name='k8s_test',
+        namespace='default',
+        in_cluster=False,
+        config_file="/path/to/.kube/config",
+    )
+    def execute_in_k8s_pod():
+        import time
+
+        print("Hello from k8s pod")
+        time.sleep(2)
+
+    @task.kubernetes(
+        image='python:3.8-slim-buster',
+        namespace='default',
+        in_cluster=False,
+        config_file="/path/to/.kube/config",
+    )
+    def print_pattern():
+        n = 5
+        for i in range(0, n):
+            # inner loop to handle number of columns
+            # values changing acc. to outer loop
+            for j in range(0, i + 1):
+                # printing stars
+                print("* ", end="")
+
+            # ending line after each row
+            print("\r")
+
+    execute_in_k8s_pod_instance = execute_in_k8s_pod()
+    print_pattern_instance = print_pattern()
+    execute_in_k8s_pod_instance >> print_pattern_instance

Review Comment:
   ```suggestion
   #
   # Licensed to the Apache Software Foundation (ASF) under one
   # or more contributor license agreements.  See the NOTICE file
   # distributed with this work for additional information
   # regarding copyright ownership.  The ASF licenses this file
   # to you under the Apache License, Version 2.0 (the
   # "License"); you may not use this file except in compliance
   # with the License.  You may obtain a copy of the License at
   #
   #   http://www.apache.org/licenses/LICENSE-2.0
   #
   # Unless required by applicable law or agreed to in writing,
   # software distributed under the License is distributed on an
   # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   # KIND, either express or implied.  See the License for the
   # specific language governing permissions and limitations
   # under the License.
   """
   This is an example dag for using the @task.kubernetes decorator.
   """
   
   from datetime import datetime
   
   from airflow import DAG
   from airflow.decorators import task
   
   with DAG(
       dag_id="example_kubernetes_decorator",
       schedule_interval=None,
       start_date=datetime(2021, 1, 1),
       tags=["example"],
       catchup=False,
   ) as dag:
   
       @task.kubernetes(
           image="python:3.8-slim-buster",
           name="k8s_test",
           namespace="default",
           in_cluster=False,
           config_file="/path/to/.kube/config",
       )
       def execute_in_k8s_pod():
           import time
   
           print("Hello from k8s pod")
           time.sleep(2)
   
       @task.kubernetes(
           image="python:3.8-slim-buster",
           namespace="default",
           in_cluster=False,
           config_file="/path/to/.kube/config",
       )
       def print_pattern():
           n = 5
           for i in range(0, n):
               # inner loop to handle number of columns
               # values changing acc. to outer loop
               for j in range(0, i + 1):
                   # printing stars
                   print("* ", end="")
   
               # ending line after each row
               print("\r")
   
       execute_in_k8s_pod_instance = execute_in_k8s_pod()
       print_pattern_instance = print_pattern()
       execute_in_k8s_pod_instance >> print_pattern_instance
   ```



##########
airflow/example_dags/example_kubernetes_decorator.py:
##########
@@ -0,0 +1,68 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+This is an example dag for using the @task.kubernetes decorator.
+"""
+
+from datetime import datetime
+
+from airflow import DAG
+from airflow.decorators import task
+
+with DAG(
+    dag_id='example_kubernetes_decorator',
+    schedule_interval=None,
+    start_date=datetime(2021, 1, 1),
+    tags=['example'],
+    catchup=False,
+) as dag:
+
+    @task.kubernetes(
+        image='python:3.8-slim-buster',
+        name='k8s_test',
+        namespace='default',
+        in_cluster=False,
+        config_file="/path/to/.kube/config",
+    )
+    def execute_in_k8s_pod():
+        import time
+
+        print("Hello from k8s pod")
+        time.sleep(2)
+
+    @task.kubernetes(
+        image='python:3.8-slim-buster',
+        namespace='default',
+        in_cluster=False,
+        config_file="/path/to/.kube/config",
+    )
+    def print_pattern():
+        n = 5
+        for i in range(0, n):
+            # inner loop to handle number of columns
+            # values changing acc. to outer loop
+            for j in range(0, i + 1):
+                # printing stars
+                print("* ", end="")
+
+            # ending line after each row
+            print("\r")
+
+    execute_in_k8s_pod_instance = execute_in_k8s_pod()
+    print_pattern_instance = print_pattern()
+    execute_in_k8s_pod_instance >> print_pattern_instance

Review Comment:
   For consistency



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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


[GitHub] [airflow] uranusjr commented on a diff in pull request #25663: Add @task.kubernetes taskflow decorator

Posted by GitBox <gi...@apache.org>.
uranusjr commented on code in PR #25663:
URL: https://github.com/apache/airflow/pull/25663#discussion_r944296152


##########
airflow/decorators/__init__.pyi:
##########
@@ -22,11 +22,14 @@
 
 from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional, Union, overload
 
+from kubernetes.client import models as k8s

Review Comment:
   Yeah I believe this is OK



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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


[GitHub] [airflow] potiuk commented on pull request #25663: Add @task.kubernetes taskflow decorator

Posted by GitBox <gi...@apache.org>.
potiuk commented on PR #25663:
URL: https://github.com/apache/airflow/pull/25663#issuecomment-1222821833

   wooooooohoooo 🎉 


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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


[GitHub] [airflow] kaxil commented on pull request #25663: Add @task.kubernetes taskflow decorator

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

   > Hi @kaxil , both of those failures seem to be related to snowflake connector.
   > 
   > ```
   > Unknown warnings generated:
   >   
   >   /usr/local/lib/python3.7/site-packages/snowflake/connector/options.py:99:
   > You have an incompatible version of 'pyarrow' installed (5.0.0), please install a version that adheres to: 
   > 'pyarrow<8.1.0,>=8.0.0; extra == "pandas"'
   > ```
   > 
   > I see similar messages in the `airflow/scripts/in_container/verify_providers.py` file in `KNOWN_DEPRECATED_MESSAGES` e.g.
   > 
   > ```
   >     (
   >         "You have an incompatible version of 'pyarrow' installed (6.0.1), please install a version that "
   >         "adheres to: 'pyarrow<8.1.0,>=8.0.0; extra == \"pandas\"'",
   >         "snowflake",
   >     )
   > ```
   
   Should be fixed by https://github.com/apache/airflow/pull/25697 -- I have rebased the PR 🤞 


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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


[GitHub] [airflow] kaxil commented on a diff in pull request #25663: Add @task.kubernetes taskflow decorator

Posted by GitBox <gi...@apache.org>.
kaxil commented on code in PR #25663:
URL: https://github.com/apache/airflow/pull/25663#discussion_r944286787


##########
airflow/decorators/__init__.pyi:
##########
@@ -22,11 +22,14 @@
 
 from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional, Union, overload
 
+from kubernetes.client import models as k8s

Review Comment:
   hmm this will raise an Import error for folks who don't have k8s library installed but still want to use the other decorators from this file



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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


[GitHub] [airflow] kaxil commented on pull request #25663: Add @task.kubernetes taskflow decorator

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

   @fletchjeff @uranusjr Can one of you look at the failing tests please:
   
   - https://github.com/apache/airflow/runs/7804776296?check_suite_focus=true
   - https://github.com/apache/airflow/runs/7804775881?check_suite_focus=true
   
   Feels related since those are provider failures only


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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


[GitHub] [airflow] fletchjeff commented on pull request #25663: Add @task.kubernetes taskflow decorator

Posted by GitBox <gi...@apache.org>.
fletchjeff commented on PR #25663:
URL: https://github.com/apache/airflow/pull/25663#issuecomment-1213163117

   Hi @kaxil , both of those failures seem to be related to snowflake connector.
   
   ```
   Unknown warnings generated:
     
     /usr/local/lib/python3.7/site-packages/snowflake/connector/options.py:99:You have an incompatible version of 'pyarrow' installed (5.0.0), please install a version that adheres to: 'pyarrow<8.1.0,>=8.0.0; extra == "pandas"'
   ```
   
   I see similar messages in the `airflow/scripts/in_container/verify_providers.py` file in `KNOWN_DEPRECATED_MESSAGES` e.g.
   
   ```
       (
           "You have an incompatible version of 'pyarrow' installed (6.0.1), please install a version that "
           "adheres to: 'pyarrow<8.1.0,>=8.0.0; extra == \"pandas\"'",
           "snowflake",
       )
   ```
   
   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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