From 5323471166ec9b2dfaf7ec0940a5a55b50d49e73 Mon Sep 17 00:00:00 2001 From: "Reza J. Bavaghoush" Date: Tue, 9 Jul 2024 18:19:24 +0200 Subject: [PATCH] fix: duplicated keys in annotations caused by airfowPodAnnotations value being overwritten by safeToEvict value of worker (#40554) --- .../pod-template-file.kubernetes-helm-yaml | 2 +- .../airflow_aux/test_pod_template_file.py | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/chart/files/pod-template-file.kubernetes-helm-yaml b/chart/files/pod-template-file.kubernetes-helm-yaml index 421922561608c..259f6a71b8cbd 100644 --- a/chart/files/pod-template-file.kubernetes-helm-yaml +++ b/chart/files/pod-template-file.kubernetes-helm-yaml @@ -27,7 +27,7 @@ {{- $containerSecurityContext := include "containerSecurityContext" (list . .Values.workers) }} {{- $containerLifecycleHooks := or .Values.workers.containerLifecycleHooks .Values.containerLifecycleHooks }} {{- $safeToEvict := dict "cluster-autoscaler.kubernetes.io/safe-to-evict" (.Values.workers.safeToEvict | toString) }} -{{- $podAnnotations := mergeOverwrite .Values.airflowPodAnnotations $safeToEvict .Values.workers.podAnnotations }} +{{- $podAnnotations := mergeOverwrite (deepCopy .Values.airflowPodAnnotations) $safeToEvict .Values.workers.podAnnotations }} apiVersion: v1 kind: Pod metadata: diff --git a/helm_tests/airflow_aux/test_pod_template_file.py b/helm_tests/airflow_aux/test_pod_template_file.py index 1efccbf4106d4..43a8d1942343a 100644 --- a/helm_tests/airflow_aux/test_pod_template_file.py +++ b/helm_tests/airflow_aux/test_pod_template_file.py @@ -660,6 +660,27 @@ def test_safe_to_evict_annotation(self, safe_to_evict: bool): "cluster-autoscaler.kubernetes.io/safe-to-evict": "true" if safe_to_evict else "false" } + def test_safe_to_evict_annotation_other_services(self): + """Workers' safeToEvict value should not overwrite safeToEvict value of other services.""" + docs = render_chart( + values={ + "workers": {"safeToEvict": False}, + "scheduler": {"safeToEvict": True}, + "triggerer": {"safeToEvict": True}, + "executor": "KubernetesExecutor", + "dagProcessor": {"enabled": True, "safeToEvict": True}, + }, + show_only=[ + "templates/dag-processor/dag-processor-deployment.yaml", + "templates/triggerer/triggerer-deployment.yaml", + "templates/scheduler/scheduler-deployment.yaml", + ], + chart_dir=self.temp_chart_dir, + ) + for doc in docs: + annotations = jmespath.search("spec.template.metadata.annotations", doc) + assert annotations.get("cluster-autoscaler.kubernetes.io/safe-to-evict") == "true" + def test_workers_pod_annotations(self): docs = render_chart( values={"workers": {"podAnnotations": {"my_annotation": "annotated!"}}},