s21lee commented on code in PR #47050:
URL: https://github.com/apache/airflow/pull/47050#discussion_r3032281405
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/backcompat/backwards_compat_converters.py:
##########
@@ -68,18 +104,52 @@ def convert_port(port) -> k8s.V1ContainerPort:
return _convert_kube_model_object(port, k8s.V1ContainerPort)
-def convert_env_vars(env_vars: list[k8s.V1EnvVar] | dict[str, str]) ->
list[k8s.V1EnvVar]:
+def convert_env_vars(
+ env_vars: list[k8s.V1EnvVar] | list[dict[str, Any]] | dict[str, str],
+) -> list[k8s.V1EnvVar]:
"""
Coerce env var collection for kubernetes.
- If the collection is a str-str dict, convert it into a list of
``V1EnvVar`` variables.
+ Supported shapes:
+
+ * ``dict[str, str]``: mapping of env name to literal value (documented API
style).
+ * ``list[k8s.V1EnvVar]``: pass through.
+ * ``list[dict]``: each element is either a minimal ``{"name": str,
"value": ...}`` mapping
+ or a Kubernetes-API-shaped dict deserialized to ``V1EnvVar`` (e.g. with
``valueFrom``).
+
+ The list-of-plain-dicts form was never described as a stable public
contract in historical
+ Airflow docs; it appears in the wild from templated YAML/JSON and older
examples. It is
+ therefore deprecated and may be removed in a future major
``cncf.kubernetes`` release—prefer
+ ``dict[str, str]`` or ``list[V1EnvVar]``.
"""
if isinstance(env_vars, dict):
return [k8s.V1EnvVar(name=k, value=v) for k, v in env_vars.items()]
- return env_vars
-
-
-def convert_env_vars_or_raise_error(env_vars: list[k8s.V1EnvVar] | dict[str,
str]) -> list[k8s.V1EnvVar]:
+ if not isinstance(env_vars, list):
+ return env_vars # type: ignore[return-value]
+ if not env_vars:
+ return []
+ all_v1 = all(isinstance(x, k8s.V1EnvVar) for x in env_vars)
+ all_dict = all(isinstance(x, dict) for x in env_vars)
+ if all_v1:
+ return env_vars
+ if all_dict:
Review Comment:
Thank you for comments. I will add
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]