Skip to content

Commit 1264316

Browse files
authored
Drive-by improvements to convert_env_vars (#36062)
1 parent de71a62 commit 1264316

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

airflow/providers/cncf/kubernetes/backcompat/backwards_compat_converters.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,15 @@ def convert_port(port) -> k8s.V1ContainerPort:
7171

7272
def convert_env_vars(env_vars: list[k8s.V1EnvVar] | dict[str, str]) -> list[k8s.V1EnvVar]:
7373
"""
74-
Convert a dictionary into a list of env_vars.
74+
Coerce env var collection for kubernetes.
7575
76-
:param env_vars:
76+
If the collection is a str-str dict, convert it into a list of ``V1EnvVar``s.
7777
"""
78-
if isinstance(env_vars, dict):
79-
res = []
80-
for k, v in env_vars.items():
81-
res.append(k8s.V1EnvVar(name=k, value=v))
82-
return res
83-
elif isinstance(env_vars, list):
78+
if isinstance(env_vars, list):
8479
return env_vars
85-
else:
86-
raise AirflowException(f"Expected dict or list, got {type(env_vars)}")
80+
if isinstance(env_vars, dict):
81+
return [k8s.V1EnvVar(name=k, value=v) for k, v in env_vars.items()]
82+
raise AirflowException(f"Expected dict or list, got {type(env_vars)}")
8783

8884

8985
def convert_pod_runtime_info_env(pod_runtime_info_envs) -> k8s.V1EnvVar:

0 commit comments

Comments
 (0)