Skip to content

Improve code in KubernetesPodOperator._render_nested_template_fields #29759

Description

@jose-lpa

Apache Airflow Provider(s)

cncf-kubernetes

Versions of Apache Airflow Providers

apache-airflow-providers-cncf-kubernetes==5.2.1

Apache Airflow version

2.5.1

Operating System

Arch Linux

Deployment

Other

Deployment details

No response

What happened

Not really showing a failure in operation, but the code in the KubernetesPodOperator._render_nested_template_fields function could be improved.

The current code is formed by 6 conditionals checking the type of the content variable. Even when the 1st of the succeed, the other 5 conditionals are still checked, which is inefficient because the function could end right there, saving time and resources.

What you think should happen instead

The conditionals flow could be fixed with a simple map, using a dictionary to immediately get the value or fallback to the default one.

How to reproduce

There is no bug per se to reproduce. It's just making the code cleaner and more efficient, avoiding to keep computing conditionals even when the condition has been resolved.

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions