This is an automated email from the ASF dual-hosted git repository.
uranusjr pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 1264316fe7 Drive-by improvements to convert_env_vars (#36062)
1264316fe7 is described below
commit 1264316fe7ab15eba3be6c985a28bb573c85c92b
Author: Tzu-ping Chung <[email protected]>
AuthorDate: Tue Dec 5 18:38:13 2023 +0800
Drive-by improvements to convert_env_vars (#36062)
---
.../kubernetes/backcompat/backwards_compat_converters.py | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git
a/airflow/providers/cncf/kubernetes/backcompat/backwards_compat_converters.py
b/airflow/providers/cncf/kubernetes/backcompat/backwards_compat_converters.py
index 4fcb9e45ae..44d464ac25 100644
---
a/airflow/providers/cncf/kubernetes/backcompat/backwards_compat_converters.py
+++
b/airflow/providers/cncf/kubernetes/backcompat/backwards_compat_converters.py
@@ -71,19 +71,15 @@ def convert_port(port) -> k8s.V1ContainerPort:
def convert_env_vars(env_vars: list[k8s.V1EnvVar] | dict[str, str]) ->
list[k8s.V1EnvVar]:
"""
- Convert a dictionary into a list of env_vars.
+ Coerce env var collection for kubernetes.
- :param env_vars:
+ If the collection is a str-str dict, convert it into a list of
``V1EnvVar``s.
"""
- if isinstance(env_vars, dict):
- res = []
- for k, v in env_vars.items():
- res.append(k8s.V1EnvVar(name=k, value=v))
- return res
- elif isinstance(env_vars, list):
+ if isinstance(env_vars, list):
return env_vars
- else:
- raise AirflowException(f"Expected dict or list, got {type(env_vars)}")
+ if isinstance(env_vars, dict):
+ return [k8s.V1EnvVar(name=k, value=v) for k, v in env_vars.items()]
+ raise AirflowException(f"Expected dict or list, got {type(env_vars)}")
def convert_pod_runtime_info_env(pod_runtime_info_envs) -> k8s.V1EnvVar: