0

I am using Airflow2.0 with KubernetesPodOperator want to run a command that use as a parameter a file from inside the image ran by the Operator. This is what I used:

KubernetesPodOperator(
    namespace=commons.kubernetes_namespace,
    labels=commons.labels,
    image=f"myregistry.io/myimage:{config['IMAGE_TAG']}",
    arguments=[
        "python",
        "run_module.py ",
        "-i",
        f'args/{config["INPUT_DIR"]}/{task_id}.json'
    ],
    name=dag_name + task_id,
    task_id=task_id,
    secrets=[secret_volume]
)

But this gives me the error:

raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: args/airflow2test/processing-pipeline.json

The image does not use any macros.

Anyone has any clue? What do I do wrong?

Elad Kalif
  • 14,110
  • 2
  • 17
  • 49
salvob
  • 1,300
  • 3
  • 21
  • 41

1 Answers1

1

This was a bug that started with PR released in version 2.0.0 of apache-airflow-providers-cncf-kubernetes. The goal of the change was to allow templating of .json files. There was a GitHub issue about the problems it created. The bug was eventually resolved by PR which was released in version 2.0.2 of the provider.

Solution:

  1. Upgrade to the latest apache-airflow-providers-cncf-kubernetes (currently 2.0.2)
  2. If upgrade is not an option use custom KubernetesPodOperator

There are two ways to workaround that problem one is to change template_fields the other is to change template_ext:

1st option: As posted on issue by raphaelauv is not to allow rendering of arguments field:

class MyKubernetesPodOperator(KubernetesPodOperator):
    template_fields = tuple(x for x in KubernetesPodOperator.template_fields if x != "arguments")

2st option: if you prefer not to render .json files:

class MyKubernetesPodOperator(KubernetesPodOperator):
    template_ext = ('.yaml', '.yml',)
Elad Kalif
  • 14,110
  • 2
  • 17
  • 49
  • thank you! I did try to update to the last apache-airflow (2.1.4)... but still it has not been applied the patch. apache-airflow-providers-cncf-kubernetes==2.0.0 – salvob Oct 04 '21 at 08:05
  • @salvob This issue isn't about Airflow version. It's about the provider version. Don't get confused by the similarity of the version numbering. You need to upgrade the version of `apache-airflow-providers-cncf-kubernetes` to latest version. currently the latest provider version is 2.0.2 see https://pypi.org/project/apache-airflow-providers-cncf-kubernetes/#history – Elad Kalif Oct 04 '21 at 08:20
  • since I use the helm chart for apache-airflow directly. Do you know if, how and when will be applied the patch ? – salvob Oct 04 '21 at 08:30
  • 1
    @salvob see https://airflow.apache.org/docs/helm-chart/stable/production-guide.html#extending-and-customizing-airflow-image to add/update a pypi package – Elad Kalif Oct 04 '21 at 08:54
  • FWIW, if anyone comes across this post trying to get a `spark-submit` job running with a `json` config, the same error occurs. Need to switch over to `yaml` files to get it to work. – eljusticiero67 Dec 05 '22 at 23:24