gm55 opened a new issue #14287:
URL: https://github.com/apache/airflow/issues/14287
**Environment:**
Airflow 2.0.1, Python 3.7.9. KubernetesExecutor is set in the configuration.
**Issue:**
KubernetsPodOperators does not process env_vars with Jinja templates like {{
dag.conf['key'] }} and leaves text as is, no substitution is done.
The method
[render_template](https://github.com/apache/airflow/blob/2.0.1/airflow/models/baseoperator.py#L875)
of BaseOperator checks types of content using
```Python
if isinstance(content, <some_type>):
```
As **env_vars** of type List[V1EnvVar] is submitted to render_templates as
a content parameter and has type 'list', it is passed to that part:
```Python
elif isinstance(content, list):
return [self.render_template(element, context, jinja_env) for element
in content]
```
But elements now have type <class
'kubernetes.client.models.v1_env_var.V1EnvVar'>, not a 'dict'
Old version would have processed the template in the following part:
```Python
elif isinstance(content, dict):
return {key: self.render_template(value, context, jinja_env) for key,
value in content.items()}
```
But now it goes to the very end of the method, into the final 'else'. The
type <class 'kubernetes.client.models.v1_env_var.V1EnvVar'> is not mentioned
anywhere above and this part is the last resort for it.
```Python
else:
if seen_oids is None:
seen_oids = set()
self._render_nested_template_fields(content, context, jinja_env,
seen_oids)
```
This part does nothing as env_vars elements are not nested templates.
[KubernetesPodOperator](https://github.com/apache/airflow/blob/2.0.1/airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py#L158)
has the following list of fields that support substitution by Jinja. So
expansion of templates in env_vars should be supported.
```Python
template_fields: Iterable[str] = (
'image',
'cmds',
'arguments',
'env_vars',
'labels',
'config_file',
'pod_template_file',
```
It happens when a dag triggers another dag and sets env_vars.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]