You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Miretpl (via GitHub)" <gi...@apache.org> on 2026/04/10 17:47:20 UTC

[PR] Add workers.celery.podAnnotations & workers.kubernetes.podAnnotations [airflow]

Miretpl opened a new pull request, #65027:
URL: https://github.com/apache/airflow/pull/65027

    <!-- SPDX-License-Identifier: Apache-2.0
         https://www.apache.org/licenses/LICENSE-2.0 -->
   
   <!--
   Thank you for contributing!
   
   Please provide above a brief description of the changes made in this pull request.
   Write a good git commit message following this guide: http://chris.beams.io/posts/git-commit/
   
   Please make sure that your code changes are covered with tests.
   And in case of new features or big changes remember to adjust the documentation.
   
   Feel free to ping (in general) for the review if you do not see reaction for a few days
   (72 Hours is the minimum reaction time you can expect from volunteers) - we sometimes miss notifications.
   
   In case of an existing issue, reference it using one of the following:
   
   * closes: #ISSUE
   * related: #ISSUE
   -->
   
   related: https://github.com/apache/airflow/issues/28880
   
   This PR introduces two new fields: `workers.celery.podAnnotations` and `workers.kubernetes.podAnnotations`. The `workers.podAnnotations` field is now deprecated.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   <!--
   If generative AI tooling has been used in the process of authoring this PR, please
   change below checkbox to `[X]` followed by the name of the tool, uncomment the "Generated-by".
   -->
   
   - [ ] Yes (please specify the tool below)
   
   <!--
   Generated-by: [Tool Name] following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   -->
   
   ---
   
   * Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
   * For fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   * When adding dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   * For significant user-facing changes create newsfragment: `{pr_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments). You can add this file in a follow-up commit after the PR is created so you know the PR number.
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add workers.celery.podAnnotations & workers.kubernetes.podAnnotations [airflow]

Posted by "jscheffl (via GitHub)" <gi...@apache.org>.
jscheffl merged PR #65027:
URL: https://github.com/apache/airflow/pull/65027


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add workers.celery.podAnnotations & workers.kubernetes.podAnnotations [airflow]

Posted by "Miretpl (via GitHub)" <gi...@apache.org>.
Miretpl commented on code in PR #65027:
URL: https://github.com/apache/airflow/pull/65027#discussion_r3066887527


##########
helm-tests/tests/helm_tests/airflow_aux/test_pod_template_file.py:
##########
@@ -1043,29 +1043,82 @@ def test_safe_to_evict_annotation_other_services(self, workers_values):
             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):
+    def test_global_pod_annotations_templated(self):
         docs = render_chart(
-            values={"workers": {"podAnnotations": {"my_annotation": "annotated!"}}},
+            values={"airflowPodAnnotations": {"global": "{{ .Release.Name }}"}},
             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"]
+        assert len(annotations) == 2  # safe-to-evict + extra annotation

Review Comment:
   Yup, I changed that in other PRs and haven't gone through all of them yet, so it will be fixed before marking it as ready.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add workers.celery.podAnnotations & workers.kubernetes.podAnnotations [airflow]

Posted by "Miretpl (via GitHub)" <gi...@apache.org>.
Miretpl commented on code in PR #65027:
URL: https://github.com/apache/airflow/pull/65027#discussion_r3066885212


##########
chart/files/pod-template-file.kubernetes-helm-yaml:
##########
@@ -29,7 +29,7 @@
 {{- $containerSecurityContext := include "containerSecurityContext" (list .Values.workers.kubernetes .Values.workers .Values) }}
 {{- $containerLifecycleHooks := or .Values.workers.kubernetes.containerLifecycleHooks .Values.workers.containerLifecycleHooks .Values.containerLifecycleHooks }}
 {{- $safeToEvict := dict "cluster-autoscaler.kubernetes.io/safe-to-evict" (or .Values.workers.kubernetes.safeToEvict (and (not (has .Values.workers.kubernetes.safeToEvict (list true false))) .Values.workers.safeToEvict) | toString) }}
-{{- $podAnnotations := mergeOverwrite (deepCopy .Values.airflowPodAnnotations) $safeToEvict .Values.workers.podAnnotations }}
+{{- $podAnnotations := mergeOverwrite (deepCopy .Values.airflowPodAnnotations) $safeToEvict (.Values.workers.kubernetes.podAnnotations | default .Values.workers.podAnnotations) }}

Review Comment:
   The current logic is correct.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add workers.celery.podAnnotations & workers.kubernetes.podAnnotations [airflow]

Posted by "Miretpl (via GitHub)" <gi...@apache.org>.
Miretpl commented on code in PR #65027:
URL: https://github.com/apache/airflow/pull/65027#discussion_r3068053004


##########
helm-tests/tests/helm_tests/airflow_aux/test_pod_template_file.py:
##########
@@ -1043,29 +1043,82 @@ def test_safe_to_evict_annotation_other_services(self, workers_values):
             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):
+    def test_global_pod_annotations_templated(self):
         docs = render_chart(
-            values={"workers": {"podAnnotations": {"my_annotation": "annotated!"}}},
+            values={"airflowPodAnnotations": {"global": "{{ .Release.Name }}"}},
             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"]
+        assert len(annotations) == 2  # safe-to-evict + extra annotation
+        assert annotations["global"] == "release-name"
 
-    def test_airflow_and_workers_pod_annotations(self):
+    @pytest.mark.parametrize(
+        "workers_values",
+        [
+            {"podAnnotations": {"my_annotation": "{{ .Release.Name }}"}},
+            {"kubernetes": {"podAnnotations": {"my_annotation": "{{ .Release.Name }}"}}},
+            {
+                "podAnnotations": {"test": "test"},
+                "kubernetes": {"podAnnotations": {"my_annotation": "{{ .Release.Name }}"}},
+            },
+        ],
+    )
+    def test_workers_pod_annotations_templated(self, workers_values):
+        docs = render_chart(
+            values={"workers": workers_values},
+            show_only=["templates/pod-template-file.yaml"],
+            chart_dir=self.temp_chart_dir,
+        )
+
+        annotations = jmespath.search("metadata.annotations", docs[0])
+        assert len(annotations) == 2  # safe-to-evict + extra annotation
+        assert annotations["my_annotation"] == "release-name"
+
+    @pytest.mark.parametrize(
+        "workers_values",
+        [
+            {"podAnnotations": {"my_annotation": "workerPodAnnotations"}},
+            {"kubernetes": {"podAnnotations": {"my_annotation": "workerPodAnnotations"}}},
+        ],
+    )
+    def test_workers_pod_annotations_override(self, workers_values):
         # should give preference to workers.podAnnotations

Review Comment:
   Fixed.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add workers.celery.podAnnotations & workers.kubernetes.podAnnotations [airflow]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #65027:
URL: https://github.com/apache/airflow/pull/65027#discussion_r3066478506


##########
helm-tests/tests/helm_tests/airflow_aux/test_pod_template_file.py:
##########
@@ -1043,29 +1043,82 @@ def test_safe_to_evict_annotation_other_services(self, workers_values):
             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):
+    def test_global_pod_annotations_templated(self):
         docs = render_chart(
-            values={"workers": {"podAnnotations": {"my_annotation": "annotated!"}}},
+            values={"airflowPodAnnotations": {"global": "{{ .Release.Name }}"}},
             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"]
+        assert len(annotations) == 2  # safe-to-evict + extra annotation
+        assert annotations["global"] == "release-name"
 
-    def test_airflow_and_workers_pod_annotations(self):
+    @pytest.mark.parametrize(
+        "workers_values",
+        [
+            {"podAnnotations": {"my_annotation": "{{ .Release.Name }}"}},
+            {"kubernetes": {"podAnnotations": {"my_annotation": "{{ .Release.Name }}"}}},
+            {
+                "podAnnotations": {"test": "test"},
+                "kubernetes": {"podAnnotations": {"my_annotation": "{{ .Release.Name }}"}},
+            },
+        ],
+    )
+    def test_workers_pod_annotations_templated(self, workers_values):
+        docs = render_chart(
+            values={"workers": workers_values},
+            show_only=["templates/pod-template-file.yaml"],
+            chart_dir=self.temp_chart_dir,
+        )
+
+        annotations = jmespath.search("metadata.annotations", docs[0])
+        assert len(annotations) == 2  # safe-to-evict + extra annotation

Review Comment:
   Asserting the total annotation count makes these tests brittle (they will fail if the chart adds another default annotation). Prefer asserting only the required keys/values are present (and, when relevant, that specific keys are absent) rather than asserting `len(annotations)`.



##########
chart/files/pod-template-file.kubernetes-helm-yaml:
##########
@@ -29,7 +29,7 @@
 {{- $containerSecurityContext := include "containerSecurityContext" (list .Values.workers.kubernetes .Values.workers .Values) }}
 {{- $containerLifecycleHooks := or .Values.workers.kubernetes.containerLifecycleHooks .Values.workers.containerLifecycleHooks .Values.containerLifecycleHooks }}
 {{- $safeToEvict := dict "cluster-autoscaler.kubernetes.io/safe-to-evict" (or .Values.workers.kubernetes.safeToEvict (and (not (has .Values.workers.kubernetes.safeToEvict (list true false))) .Values.workers.safeToEvict) | toString) }}
-{{- $podAnnotations := mergeOverwrite (deepCopy .Values.airflowPodAnnotations) $safeToEvict .Values.workers.podAnnotations }}
+{{- $podAnnotations := mergeOverwrite (deepCopy .Values.airflowPodAnnotations) $safeToEvict (.Values.workers.kubernetes.podAnnotations | default .Values.workers.podAnnotations) }}

Review Comment:
   Using `default` here makes an explicitly empty `workers.kubernetes.podAnnotations: {}` fall back to the deprecated `workers.podAnnotations`, which prevents users from intentionally clearing pod-template-file annotations while still having legacy values set. Prefer checking key presence (e.g., via `hasKey` on `.Values.workers.kubernetes`) to distinguish 'unset' from 'set to empty', and only fall back to `workers.podAnnotations` when the new key is not provided.
   ```suggestion
   {{- $workerPodAnnotations := .Values.workers.podAnnotations }}
   {{- if hasKey .Values.workers.kubernetes "podAnnotations" }}
   {{- $workerPodAnnotations = .Values.workers.kubernetes.podAnnotations }}
   {{- end }}
   {{- $podAnnotations := mergeOverwrite (deepCopy .Values.airflowPodAnnotations) $safeToEvict $workerPodAnnotations }}
   ```



##########
helm-tests/tests/helm_tests/airflow_aux/test_pod_template_file.py:
##########
@@ -1043,29 +1043,82 @@ def test_safe_to_evict_annotation_other_services(self, workers_values):
             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):
+    def test_global_pod_annotations_templated(self):
         docs = render_chart(
-            values={"workers": {"podAnnotations": {"my_annotation": "annotated!"}}},
+            values={"airflowPodAnnotations": {"global": "{{ .Release.Name }}"}},
             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"]
+        assert len(annotations) == 2  # safe-to-evict + extra annotation

Review Comment:
   Asserting the total annotation count makes these tests brittle (they will fail if the chart adds another default annotation). Prefer asserting only the required keys/values are present (and, when relevant, that specific keys are absent) rather than asserting `len(annotations)`.



##########
helm-tests/tests/helm_tests/airflow_aux/test_pod_template_file.py:
##########
@@ -1043,29 +1043,82 @@ def test_safe_to_evict_annotation_other_services(self, workers_values):
             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):
+    def test_global_pod_annotations_templated(self):
         docs = render_chart(
-            values={"workers": {"podAnnotations": {"my_annotation": "annotated!"}}},
+            values={"airflowPodAnnotations": {"global": "{{ .Release.Name }}"}},
             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"]
+        assert len(annotations) == 2  # safe-to-evict + extra annotation
+        assert annotations["global"] == "release-name"
 
-    def test_airflow_and_workers_pod_annotations(self):
+    @pytest.mark.parametrize(
+        "workers_values",
+        [
+            {"podAnnotations": {"my_annotation": "{{ .Release.Name }}"}},
+            {"kubernetes": {"podAnnotations": {"my_annotation": "{{ .Release.Name }}"}}},
+            {
+                "podAnnotations": {"test": "test"},
+                "kubernetes": {"podAnnotations": {"my_annotation": "{{ .Release.Name }}"}},
+            },
+        ],
+    )
+    def test_workers_pod_annotations_templated(self, workers_values):
+        docs = render_chart(
+            values={"workers": workers_values},
+            show_only=["templates/pod-template-file.yaml"],
+            chart_dir=self.temp_chart_dir,
+        )
+
+        annotations = jmespath.search("metadata.annotations", docs[0])
+        assert len(annotations) == 2  # safe-to-evict + extra annotation
+        assert annotations["my_annotation"] == "release-name"
+
+    @pytest.mark.parametrize(
+        "workers_values",
+        [
+            {"podAnnotations": {"my_annotation": "workerPodAnnotations"}},
+            {"kubernetes": {"podAnnotations": {"my_annotation": "workerPodAnnotations"}}},
+        ],
+    )
+    def test_workers_pod_annotations_override(self, workers_values):
         # should give preference to workers.podAnnotations

Review Comment:
   This comment is now misleading because the test is parametrized to cover both `workers.podAnnotations` and `workers.kubernetes.podAnnotations`. Consider updating it to reflect the actual intent (e.g., worker-specific annotations override `airflowPodAnnotations`, regardless of whether they come from the deprecated key or the new kubernetes key).
   ```suggestion
           # Worker-specific pod annotations should override airflowPodAnnotations,
           # whether they come from workers.podAnnotations or workers.kubernetes.podAnnotations.
   ```



##########
helm-tests/tests/helm_tests/airflow_aux/test_pod_template_file.py:
##########
@@ -1043,29 +1043,82 @@ def test_safe_to_evict_annotation_other_services(self, workers_values):
             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):
+    def test_global_pod_annotations_templated(self):
         docs = render_chart(
-            values={"workers": {"podAnnotations": {"my_annotation": "annotated!"}}},
+            values={"airflowPodAnnotations": {"global": "{{ .Release.Name }}"}},
             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"]
+        assert len(annotations) == 2  # safe-to-evict + extra annotation
+        assert annotations["global"] == "release-name"
 
-    def test_airflow_and_workers_pod_annotations(self):
+    @pytest.mark.parametrize(
+        "workers_values",
+        [
+            {"podAnnotations": {"my_annotation": "{{ .Release.Name }}"}},
+            {"kubernetes": {"podAnnotations": {"my_annotation": "{{ .Release.Name }}"}}},
+            {
+                "podAnnotations": {"test": "test"},
+                "kubernetes": {"podAnnotations": {"my_annotation": "{{ .Release.Name }}"}},
+            },
+        ],
+    )
+    def test_workers_pod_annotations_templated(self, workers_values):
+        docs = render_chart(
+            values={"workers": workers_values},
+            show_only=["templates/pod-template-file.yaml"],
+            chart_dir=self.temp_chart_dir,
+        )
+
+        annotations = jmespath.search("metadata.annotations", docs[0])
+        assert len(annotations) == 2  # safe-to-evict + extra annotation
+        assert annotations["my_annotation"] == "release-name"
+
+    @pytest.mark.parametrize(
+        "workers_values",
+        [
+            {"podAnnotations": {"my_annotation": "workerPodAnnotations"}},
+            {"kubernetes": {"podAnnotations": {"my_annotation": "workerPodAnnotations"}}},
+        ],
+    )
+    def test_workers_pod_annotations_override(self, workers_values):
         # should give preference to workers.podAnnotations
         docs = render_chart(
             values={
                 "airflowPodAnnotations": {"my_annotation": "airflowPodAnnotations"},
-                "workers": {"podAnnotations": {"my_annotation": "workerPodAnnotations"}},
+                "workers": workers_values,
             },
             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"]
+        assert len(annotations) == 2  # safe-to-evict + extra annotation

Review Comment:
   Asserting the total annotation count makes these tests brittle (they will fail if the chart adds another default annotation). Prefer asserting only the required keys/values are present (and, when relevant, that specific keys are absent) rather than asserting `len(annotations)`.



##########
helm-tests/tests/helm_tests/airflow_aux/test_pod_template_file.py:
##########
@@ -1043,29 +1043,82 @@ def test_safe_to_evict_annotation_other_services(self, workers_values):
             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):
+    def test_global_pod_annotations_templated(self):
         docs = render_chart(
-            values={"workers": {"podAnnotations": {"my_annotation": "annotated!"}}},
+            values={"airflowPodAnnotations": {"global": "{{ .Release.Name }}"}},
             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"]
+        assert len(annotations) == 2  # safe-to-evict + extra annotation
+        assert annotations["global"] == "release-name"
 
-    def test_airflow_and_workers_pod_annotations(self):
+    @pytest.mark.parametrize(
+        "workers_values",
+        [
+            {"podAnnotations": {"my_annotation": "{{ .Release.Name }}"}},
+            {"kubernetes": {"podAnnotations": {"my_annotation": "{{ .Release.Name }}"}}},
+            {
+                "podAnnotations": {"test": "test"},
+                "kubernetes": {"podAnnotations": {"my_annotation": "{{ .Release.Name }}"}},
+            },
+        ],
+    )
+    def test_workers_pod_annotations_templated(self, workers_values):
+        docs = render_chart(
+            values={"workers": workers_values},
+            show_only=["templates/pod-template-file.yaml"],
+            chart_dir=self.temp_chart_dir,
+        )
+
+        annotations = jmespath.search("metadata.annotations", docs[0])
+        assert len(annotations) == 2  # safe-to-evict + extra annotation
+        assert annotations["my_annotation"] == "release-name"
+
+    @pytest.mark.parametrize(
+        "workers_values",
+        [
+            {"podAnnotations": {"my_annotation": "workerPodAnnotations"}},
+            {"kubernetes": {"podAnnotations": {"my_annotation": "workerPodAnnotations"}}},
+        ],
+    )
+    def test_workers_pod_annotations_override(self, workers_values):
         # should give preference to workers.podAnnotations
         docs = render_chart(
             values={
                 "airflowPodAnnotations": {"my_annotation": "airflowPodAnnotations"},
-                "workers": {"podAnnotations": {"my_annotation": "workerPodAnnotations"}},
+                "workers": workers_values,
             },
             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"]
+        assert len(annotations) == 2  # safe-to-evict + extra annotation
+        assert annotations["my_annotation"] == "workerPodAnnotations"
+
+    @pytest.mark.parametrize(
+        "workers_values",
+        [
+            {"podAnnotations": {"local": "workerPodAnnotations"}},
+            {"kubernetes": {"podAnnotations": {"local": "workerPodAnnotations"}}},
+        ],
+    )
+    def test_pod_annotations_merge(self, workers_values):
+        docs = render_chart(
+            values={
+                "airflowPodAnnotations": {"global": "airflowPodAnnotations"},
+                "workers": workers_values,
+            },
+            show_only=["templates/pod-template-file.yaml"],
+            chart_dir=self.temp_chart_dir,
+        )
+
+        annotations = jmespath.search("metadata.annotations", docs[0])
+        assert len(annotations) == 3  # safe-to-evict + extra annotations

Review Comment:
   Asserting the total annotation count makes these tests brittle (they will fail if the chart adds another default annotation). Prefer asserting only the required keys/values are present (and, when relevant, that specific keys are absent) rather than asserting `len(annotations)`.
   ```suggestion
           assert "global" in annotations
           assert "local" in annotations
   ```



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add workers.celery.podAnnotations & workers.kubernetes.podAnnotations [airflow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #65027:
URL: https://github.com/apache/airflow/pull/65027#issuecomment-4229947992

   ### Backport successfully created: chart/v1-2x-test
   
   Note: As of [Merging PRs targeted for Airflow 3.X](https://github.com/apache/airflow/blob/main/dev/README_AIRFLOW3_DEV.md#merging-prs-targeted-for-airflow-3x)
   the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.
   
   In matter of doubt please ask in [#release-management](https://apache-airflow.slack.com/archives/C03G9H97MM2) Slack channel.
   
   <table>
           <tr>
           <th>Status</th>
           <th>Branch</th>
           <th>Result</th>
       </tr>
       <tr>
           <td>✅</td>
           <td>chart/v1-2x-test</td>
           <td><a href="https://github.com/apache/airflow/pull/65068"><img src="https://img.shields.io/badge/PR-65068-blue" alt="PR Link"></a></td>
       </tr>
   </table>


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add workers.celery.podAnnotations & workers.kubernetes.podAnnotations [airflow]

Posted by "Miretpl (via GitHub)" <gi...@apache.org>.
Miretpl commented on code in PR #65027:
URL: https://github.com/apache/airflow/pull/65027#discussion_r3066888449


##########
helm-tests/tests/helm_tests/airflow_aux/test_pod_template_file.py:
##########
@@ -1043,29 +1043,82 @@ def test_safe_to_evict_annotation_other_services(self, workers_values):
             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):
+    def test_global_pod_annotations_templated(self):
         docs = render_chart(
-            values={"workers": {"podAnnotations": {"my_annotation": "annotated!"}}},
+            values={"airflowPodAnnotations": {"global": "{{ .Release.Name }}"}},
             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"]
+        assert len(annotations) == 2  # safe-to-evict + extra annotation
+        assert annotations["global"] == "release-name"
 
-    def test_airflow_and_workers_pod_annotations(self):
+    @pytest.mark.parametrize(
+        "workers_values",
+        [
+            {"podAnnotations": {"my_annotation": "{{ .Release.Name }}"}},
+            {"kubernetes": {"podAnnotations": {"my_annotation": "{{ .Release.Name }}"}}},
+            {
+                "podAnnotations": {"test": "test"},
+                "kubernetes": {"podAnnotations": {"my_annotation": "{{ .Release.Name }}"}},
+            },
+        ],
+    )
+    def test_workers_pod_annotations_templated(self, workers_values):
+        docs = render_chart(
+            values={"workers": workers_values},
+            show_only=["templates/pod-template-file.yaml"],
+            chart_dir=self.temp_chart_dir,
+        )
+
+        annotations = jmespath.search("metadata.annotations", docs[0])
+        assert len(annotations) == 2  # safe-to-evict + extra annotation

Review Comment:
   Yup, I changed that in other PRs and haven't gone through all of them yet, so it will be fixed before marking it as ready.



##########
helm-tests/tests/helm_tests/airflow_aux/test_pod_template_file.py:
##########
@@ -1043,29 +1043,82 @@ def test_safe_to_evict_annotation_other_services(self, workers_values):
             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):
+    def test_global_pod_annotations_templated(self):
         docs = render_chart(
-            values={"workers": {"podAnnotations": {"my_annotation": "annotated!"}}},
+            values={"airflowPodAnnotations": {"global": "{{ .Release.Name }}"}},
             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"]
+        assert len(annotations) == 2  # safe-to-evict + extra annotation
+        assert annotations["global"] == "release-name"
 
-    def test_airflow_and_workers_pod_annotations(self):
+    @pytest.mark.parametrize(
+        "workers_values",
+        [
+            {"podAnnotations": {"my_annotation": "{{ .Release.Name }}"}},
+            {"kubernetes": {"podAnnotations": {"my_annotation": "{{ .Release.Name }}"}}},
+            {
+                "podAnnotations": {"test": "test"},
+                "kubernetes": {"podAnnotations": {"my_annotation": "{{ .Release.Name }}"}},
+            },
+        ],
+    )
+    def test_workers_pod_annotations_templated(self, workers_values):
+        docs = render_chart(
+            values={"workers": workers_values},
+            show_only=["templates/pod-template-file.yaml"],
+            chart_dir=self.temp_chart_dir,
+        )
+
+        annotations = jmespath.search("metadata.annotations", docs[0])
+        assert len(annotations) == 2  # safe-to-evict + extra annotation
+        assert annotations["my_annotation"] == "release-name"
+
+    @pytest.mark.parametrize(
+        "workers_values",
+        [
+            {"podAnnotations": {"my_annotation": "workerPodAnnotations"}},
+            {"kubernetes": {"podAnnotations": {"my_annotation": "workerPodAnnotations"}}},
+        ],
+    )
+    def test_workers_pod_annotations_override(self, workers_values):
         # should give preference to workers.podAnnotations
         docs = render_chart(
             values={
                 "airflowPodAnnotations": {"my_annotation": "airflowPodAnnotations"},
-                "workers": {"podAnnotations": {"my_annotation": "workerPodAnnotations"}},
+                "workers": workers_values,
             },
             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"]
+        assert len(annotations) == 2  # safe-to-evict + extra annotation

Review Comment:
   Yup, I changed that in other PRs and haven't gone through all of them yet, so it will be fixed before marking it as ready.



##########
helm-tests/tests/helm_tests/airflow_aux/test_pod_template_file.py:
##########
@@ -1043,29 +1043,82 @@ def test_safe_to_evict_annotation_other_services(self, workers_values):
             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):
+    def test_global_pod_annotations_templated(self):
         docs = render_chart(
-            values={"workers": {"podAnnotations": {"my_annotation": "annotated!"}}},
+            values={"airflowPodAnnotations": {"global": "{{ .Release.Name }}"}},
             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"]
+        assert len(annotations) == 2  # safe-to-evict + extra annotation
+        assert annotations["global"] == "release-name"
 
-    def test_airflow_and_workers_pod_annotations(self):
+    @pytest.mark.parametrize(
+        "workers_values",
+        [
+            {"podAnnotations": {"my_annotation": "{{ .Release.Name }}"}},
+            {"kubernetes": {"podAnnotations": {"my_annotation": "{{ .Release.Name }}"}}},
+            {
+                "podAnnotations": {"test": "test"},
+                "kubernetes": {"podAnnotations": {"my_annotation": "{{ .Release.Name }}"}},
+            },
+        ],
+    )
+    def test_workers_pod_annotations_templated(self, workers_values):
+        docs = render_chart(
+            values={"workers": workers_values},
+            show_only=["templates/pod-template-file.yaml"],
+            chart_dir=self.temp_chart_dir,
+        )
+
+        annotations = jmespath.search("metadata.annotations", docs[0])
+        assert len(annotations) == 2  # safe-to-evict + extra annotation
+        assert annotations["my_annotation"] == "release-name"
+
+    @pytest.mark.parametrize(
+        "workers_values",
+        [
+            {"podAnnotations": {"my_annotation": "workerPodAnnotations"}},
+            {"kubernetes": {"podAnnotations": {"my_annotation": "workerPodAnnotations"}}},
+        ],
+    )
+    def test_workers_pod_annotations_override(self, workers_values):
         # should give preference to workers.podAnnotations
         docs = render_chart(
             values={
                 "airflowPodAnnotations": {"my_annotation": "airflowPodAnnotations"},
-                "workers": {"podAnnotations": {"my_annotation": "workerPodAnnotations"}},
+                "workers": workers_values,
             },
             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"]
+        assert len(annotations) == 2  # safe-to-evict + extra annotation
+        assert annotations["my_annotation"] == "workerPodAnnotations"
+
+    @pytest.mark.parametrize(
+        "workers_values",
+        [
+            {"podAnnotations": {"local": "workerPodAnnotations"}},
+            {"kubernetes": {"podAnnotations": {"local": "workerPodAnnotations"}}},
+        ],
+    )
+    def test_pod_annotations_merge(self, workers_values):
+        docs = render_chart(
+            values={
+                "airflowPodAnnotations": {"global": "airflowPodAnnotations"},
+                "workers": workers_values,
+            },
+            show_only=["templates/pod-template-file.yaml"],
+            chart_dir=self.temp_chart_dir,
+        )
+
+        annotations = jmespath.search("metadata.annotations", docs[0])
+        assert len(annotations) == 3  # safe-to-evict + extra annotations

Review Comment:
   Yup, I changed that in other PRs and haven't gone through all of them yet, so it will be fixed before marking it as ready.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org