diff --git a/chart/files/pod-template-file.kubernetes-helm-yaml b/chart/files/pod-template-file.kubernetes-helm-yaml index c43412884ea53..f82d7d27a77a2 100644 --- a/chart/files/pod-template-file.kubernetes-helm-yaml +++ b/chart/files/pod-template-file.kubernetes-helm-yaml @@ -31,9 +31,14 @@ metadata: {{- with .Values.labels }} {{ toYaml . | indent 4 }} {{- end }} - {{- if .Values.airflowPodAnnotations }} + {{- if or .Values.airflowPodAnnotations .Values.workers.podAnnotations }} annotations: - {{- toYaml .Values.airflowPodAnnotations | nindent 4 }} + {{- if .Values.airflowPodAnnotations }} + {{- toYaml .Values.airflowPodAnnotations | nindent 4 }} + {{- end }} + {{- if .Values.workers.podAnnotations }} + {{- toYaml .Values.workers.podAnnotations | nindent 4 }} + {{- end }} {{- end }} spec: {{- if or (and .Values.dags.gitSync.enabled (not .Values.dags.persistence.enabled)) .Values.workers.extraInitContainers }} diff --git a/tests/charts/test_pod_template_file.py b/tests/charts/test_pod_template_file.py index 98dffb2d65ac6..12d1d590c50f9 100644 --- a/tests/charts/test_pod_template_file.py +++ b/tests/charts/test_pod_template_file.py @@ -564,6 +564,30 @@ def test_airflow_pod_annotations(self): assert "my_annotation" in annotations assert "annotated!" in annotations["my_annotation"] + def test_workers_pod_annotations(self): + docs = render_chart( + values={"workers": {"podAnnotations": {"my_annotation": "annotated!"}}}, + show_only=["templates/pod-template-file.yaml"], + chart_dir=self.temp_chart_dir, + ) + annotations = jmespath.search("metadata.annotations", docs[0]) + assert "my_annotation" in annotations + assert "annotated!" in annotations["my_annotation"] + + def test_airflow_and_workers_pod_annotations(self): + # should give preference to workers.podAnnotations + docs = render_chart( + values={ + "airflowPodAnnotations": {"my_annotation": "airflowPodAnnotations"}, + "workers": {"podAnnotations": {"my_annotation": "workerPodAnnotations"}}, + }, + show_only=["templates/pod-template-file.yaml"], + chart_dir=self.temp_chart_dir, + ) + annotations = jmespath.search("metadata.annotations", docs[0]) + assert "my_annotation" in annotations + assert "workerPodAnnotations" in annotations["my_annotation"] + def test_should_add_extra_init_containers(self): docs = render_chart( values={