Repository navigation
Description
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
- I agree to follow this project's Code of Conduct
Activity
boring-cyborg commentedon Oct 6, 2022
Thanks for opening your first issue here! Be sure to follow the issue template!
kaxil commentedon Oct 6, 2022
yeah we should fix it
kaxil commentedon Oct 6, 2022
We should add it to package_data for just the k8s provider
airflow/setup.cfg
Lines 140 to 155 in 8898db9
kaxil commentedon Oct 6, 2022
Or provide this information via
provider.yamland read it and add it in https://github.com/apache/airflow/blob/main/dev/provider_packages/SETUP_TEMPLATE.cfg.jinja2potiuk commentedon Oct 6, 2022
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 :)ashb commentedon Oct 7, 2022
I wonder about using something like setuptools-scm which will then "just" include all files tracked in git might work too
potiuk commentedon Oct 10, 2022
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
airflowso we might want to do it there, but until our providers are single source tree withairflownone of such tools will likely work and we have to do it more "manual" way.Add *.jinja2 files to provider packages
Add *.jinja2 files to provider packages (#27171)
Add *.jinja2 files to provider packages (apache#27171)
Fix jinja file inclusion in cncf.kubernetes provider package (#27451)
Add *.jinja2 files to provider packages (#27171)