From dd627d7f4605d2918395b7e9ca9baaa62c9724d4 Mon Sep 17 00:00:00 2001 From: vizeit <44128024+vizeit@users.noreply.github.com> Date: Thu, 25 Jan 2024 16:32:20 -0800 Subject: [PATCH] 36888-Fix k8 configmap issue in 7.14.0rc1 (#37001) --- airflow/providers/cncf/kubernetes/operators/pod.py | 11 +++++++---- tests/providers/cncf/kubernetes/operators/test_pod.py | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/airflow/providers/cncf/kubernetes/operators/pod.py b/airflow/providers/cncf/kubernetes/operators/pod.py index 4caa37b6efb2f..693932f022a65 100644 --- a/airflow/providers/cncf/kubernetes/operators/pod.py +++ b/airflow/providers/cncf/kubernetes/operators/pod.py @@ -230,7 +230,7 @@ class KubernetesPodOperator(BaseOperator): "volumes", "volume_mounts", "cluster_context", - "configmaps", + "env_from", ) template_fields_renderers = {"env_vars": "py"} @@ -313,9 +313,8 @@ def __init__( if pod_runtime_info_envs: self.env_vars.extend([convert_pod_runtime_info_env(p) for p in pod_runtime_info_envs]) self.env_from = env_from or [] - self.configmaps = configmaps - if self.configmaps: - self.env_from.extend([convert_configmap(c) for c in self.configmaps]) + if configmaps: + self.env_from.extend([convert_configmap(c) for c in configmaps]) self.ports = [convert_port(p) for p in ports] if ports else [] self.volume_mounts = [convert_volume_mount(v) for v in volume_mounts] if volume_mounts else [] self.volumes = [convert_volume(volume) for volume in volumes] if volumes else [] @@ -420,6 +419,10 @@ def _render_nested_template_fields( template_fields = ("claim_name",) elif isinstance(content, k8s.V1ConfigMapVolumeSource): template_fields = ("name",) + elif isinstance(content, k8s.V1EnvFromSource): + template_fields = ("config_map_ref",) + elif isinstance(content, k8s.V1ConfigMapEnvSource): + template_fields = ("name",) else: template_fields = None diff --git a/tests/providers/cncf/kubernetes/operators/test_pod.py b/tests/providers/cncf/kubernetes/operators/test_pod.py index 5da60fabfa37c..b896f57ee5d05 100644 --- a/tests/providers/cncf/kubernetes/operators/test_pod.py +++ b/tests/providers/cncf/kubernetes/operators/test_pod.py @@ -179,7 +179,7 @@ def test_templates(self, create_task_instance_of_operator): assert dag_id == ti.task.arguments assert dag_id == ti.task.env_vars[0] assert dag_id == rendered.annotations["dag-id"] - assert dag_id == ti.task.configmaps[0] + assert dag_id == ti.task.env_from[0].config_map_ref.name assert dag_id == rendered.volumes[0].name assert dag_id == rendered.volumes[0].config_map.name