question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fix template_ext processing for Kubernetes Pod Operator

See original GitHub issue

The “template_ext” mechanism is useful for automatically loading and jinja-processing files which are specified in parameters of Operators. However this might lead to certain problems for example (from slack conversation):

The templated_fields in  KubernetesPodOperator seems cause the error airflow jinja2.exceptions.TemplateNotFound when some character in the column, e.g / in env_vars.
The code got error.
env_vars=[
            k8s.V1EnvVar(
                name="GOOGLE_APPLICATION_CREDENTIALS",
                value="/var/secrets/google/service-account.json",
            ),

I believe the behaviour changed comparing to not-so-long-past. Some of the changes with processing parameters with jinja recursively caused this template behaviour to be applied also nested parameters like above.

There were also several discussions and user confusion with this behaviour: #15942, #16922

There are two ways we could improve the situation:

  1. limit the “template_extension” resolution to only direct string kwargs passed to the operator (I think this is no brainer and we should do it)

  2. propose some “escaping” mechanism, where you could either disable template_extension processing entirely or somehow mark the parameters that should not be treated as templates.

Here I have several proposals:

a) we could add “skip_template_ext_processing” or similar parameter in BaseOperator <- I do not like it as many operators rely on this behaviour for a good reason b) we could add “template_ext” parameter in the operator that could override the original class-level-field <- I like this one a lot c) we could add “disable_template_ext_pattern” (str) parameter where we could specify list of regexp’s where we could filter out only specific values <- this one will allow to disable template_ext much more “selectively” - only for certain parameters.

UPDATE: It only affects Kubenernetes Pod Operator due to it’s recursive behaviour and should be fixed there.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
uranusjrcommented, Jul 23, 2021

Oh, of course we shouldn’t use typing.Literal. I was just borrowing the name and should’ve clarified. We should implement something like from airflow import Literal.

0reactions
raphaelauvcommented, Sep 29, 2021

For people confused by the release 2.0.2

the commit Fix using XCom with ''KubernetesPodOperator'' (#17760) mostly fix the error of the templating of the K8S secrets

so don’t use 2.0.1 !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use the KubernetesPodOperator | Cloud Composer
This page describes how to use the KubernetesPodOperator to launch Kubernetes pods from Cloud Composer into the Google Kubernetes Engine cluster that is...
Read more >
Use the KubernetesPodOperator | Astronomer Documentation
The KubernetesPodOperator (KPO) runs a Docker image in a dedicated Kubernetes Pod. By abstracting calls to the Kubernetes API, the KubernetesPodOperator ...
Read more >
KubernetesPodOperator — apache-airflow-providers-cncf ...
If you use Google Kubernetes Engine, consider using the GKEStartPodOperator operator as it simplifies the Kubernetes authorization process.
Read more >
Debug Pods - Kubernetes
Debug Pods. This guide is to help users debug applications that are deployed into Kubernetes and not behaving correctly.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found