Skip to content

python_kubernetes_script.jinja2 file missing from apache-airflow-providers-cncf-kubernetes==4.4.0 release #26910

Description

@fletchjeff

Apache Airflow Provider(s)

cncf-kubernetes

Versions of Apache Airflow Providers

$ pip freeze | grep apache-airflow-providers
apache-airflow-providers-cncf-kubernetes==4.4.0

Apache Airflow version

2.4.1

Operating System

macos-12.6

Deployment

Other Docker-based deployment

Deployment details

Using the astro cli.

What happened

Trying to test the @task.kubernetes decorator with Airflow 2.4.1 and the apache-airflow-providers-cncf-kubernetes==4.4.0 package, I get the following error:

[2022-10-06, 10:49:01 UTC] {taskinstance.py:1851} ERROR - Task failed with exception
Traceback (most recent call last):
  File "/Users/jeff/tmp/penv/lib/python3.9/site-packages/airflow/providers/cncf/kubernetes/decorators/kubernetes.py", line 95, in execute
    write_python_script(jinja_context=jinja_context, filename=script_filename)
  File "/Users/jeff/tmp/penv/lib/python3.9/site-packages/airflow/providers/cncf/kubernetes/python_kubernetes_script.py", line 79, in write_python_script
    template = template_env.get_template('python_kubernetes_script.jinja2')
  File "/Users/jeff/tmp/penv/lib/python3.9/site-packages/jinja2/environment.py", line 1010, in get_template
    return self._load_template(name, globals)
  File "/Users/jeff/tmp/penv/lib/python3.9/site-packages/jinja2/environment.py", line 969, in _load_template
    template = self.loader.load(self, name, self.make_globals(globals))
  File "/Users/jeff/tmp/penv/lib/python3.9/site-packages/jinja2/loaders.py", line 126, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "/Users/jeff/tmp/penv/lib/python3.9/site-packages/jinja2/loaders.py", line 218, in get_source
    raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: python_kubernetes_script.jinja2

Looking the source file for the apache-airflow-providers-cncf-kubernetes==4.4.0 package, I can see that python_kubernetes_script.py is there but not python_kubernetes_script.jinja2

$ tar -ztvf apache-airflow-providers-cncf-kubernetes-4.4.0.tar.gz 'apache-airflow-providers-cncf-kubernetes-4.4.0/airflow/providers/cncf/kubernetes/py*'
-rw-r--r--  0 root   root     2949 Sep 22 15:25 apache-airflow-providers-cncf-kubernetes-4.4.0/airflow/providers/cncf/kubernetes/python_kubernetes_script.py

What you think should happen instead

The python_kubernetes_script.jinja2 file that is available here https://github.com/apache/airflow/blob/main/airflow/providers/cncf/kubernetes/python_kubernetes_script.jinja2 should be included in the apache-airflow-providers-cncf-kubernetes==4.4.0 pypi package.

How to reproduce

With a default installation of apache-airflow==2.4.1 and apache-airflow-providers-cncf-kubernetes==4.4.0, running the following DAG will reproduce the issue.

import pendulum
from airflow.decorators import dag, task

@dag(
    schedule_interval=None,
    start_date=pendulum.datetime(2022, 7, 20, tz="UTC"),
    catchup=False,
    tags=['xray_classifier'],
)
def k8s_taskflow():

    @task.kubernetes(
        image="python:3.8-slim-buster",
        name="k8s_test",
        namespace="default",
        in_cluster=False,
        config_file="/path/to/config"
    )
    def execute_in_k8s_pod():
        import time
        print("Hello from k8s pod")
        time.sleep(2)


    execute_in_k8s_pod_instance = execute_in_k8s_pod()        

k8s_taskflow_dag = k8s_taskflow()

Anything else

If I manually add the python_kubernetes_script.jinja2 into my site-packages/airflow/providers/cncf/kubernetes/ folder, then it works as expected.

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:bug
    on Oct 6, 2022
  2. boring-cyborg commented on Oct 6, 2022

    @boring-cyborg

    Thanks for opening your first issue here! Be sure to follow the issue template!

  3. kaxil commented on Oct 6, 2022

    @kaxil
    Member

    yeah we should fix it

  4. kaxil commented on Oct 6, 2022

    @kaxil
    Member

    We should add it to package_data for just the k8s provider

    airflow/setup.cfg

    Lines 140 to 155 in 8898db9

    [options.package_data]
    airflow=
    py.typed
    alembic.ini
    git_version
    customized_form_field_behaviours.schema.json
    provider_info.schema.json
    airflow.api_connexion.openapi=*.yaml
    airflow.serialization=*.json
    airflow.utils=
    context.pyi
    [options.data_files]
    generated=
    generated/provider_dependencies.json

  5. added
    provider:cncf-kubernetes
    on Oct 6, 2022
  6. kaxil commented on Oct 6, 2022

    @kaxil
    Member
  7. added this to the Airflow 2.4.2 milestone on Oct 6, 2022
  8. potiuk commented on Oct 6, 2022

    @potiuk
    Member

    Yeah. it has to be added to the template - likely we could add all *.jinja2 files found in airflow.providers.<PROVIDER> - to not complicate provider.yaml. I will have no time to do it before holidays so it's up for grabs to anyone :)

  9. ashb commented on Oct 7, 2022

    @ashb
    Member

    I wonder about using something like setuptools-scm which will then "just" include all files tracked in git might work too

  10. potiuk commented on Oct 10, 2022

    @potiuk
    Member

    I wonder about using something like setuptools-scm which will then "just" include all files tracked in git might work too

    Not really becaause we cannot have providers as regular packages (until we split them) because they are subdirectory of "airflow/providers" now and setuptools-scm are very unlikely to work in this case. They might work for airflow so we might want to do it there, but until our providers are single source tree with airflow none of such tools will likely work and we have to do it more "manual" way.

  11. added a commit that references this issue on Oct 20, 2022
    c31c957
  12. added a commit that references this issue on Oct 21, 2022
    7be7772
  13. added a commit that references this issue on Oct 24, 2022
    e2bb8a5
  14. removed this from the Airflow 2.4.3 milestone on Oct 27, 2022
  15. added a commit that references this issue on Nov 10, 2022
    8cea072
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:providerskind:bugprovider:cncf-kubernetes

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions