jedcunningham commented on a change in pull request #18481:
URL: https://github.com/apache/airflow/pull/18481#discussion_r715272702



##########
File path: chart/tests/test_annotations.py
##########
@@ -19,20 +19,7 @@
 
 from tests.helm_template_generator import render_chart
 
-# Values for each service mapped to the 'example'
-# key annotation
-CUSTOM_ANNOTATION_VALUES = (
-    CUSTOM_SCHEDULER_ANNOTATION,
-    CUSTOM_WEBSERVER_ANNOTATION,
-    CUSTOM_WORKER_ANNOTATION,
-    CUSTOM_CLEANUP_ANNOTATION,
-    CUSTOM_FLOWER_ANNOTATION,
-    CUSTOM_PGBOUNCER_ANNOTATION,
-    CUSTOM_STATSD_ANNOTATION,
-    CUSTOM_CREATE_USER_JOB_ANNOTATION,
-    CUSTOM_MIGRATE_DATABASE_JOB_ANNOTATION,
-    CUSTOM_REDIS_ANNOTATION,
-) = (
+COMPONENTS_SUPPORTING_CUSTOM_SERVICEACCOUNT_ANNOTATIONS = (

Review comment:
       If we are only going to use these for asserting counts, I'm not sure 
it's worth enumerating them. A simple `assert len(x) == 11` seems cleaner?

##########
File path: chart/tests/test_annotations.py
##########
@@ -134,5 +138,114 @@ def test_service_account_annotations(self):
 
         self.assertCountEqual(
             list_of_annotation_values_in_objects,
-            CUSTOM_ANNOTATION_VALUES,
+            COMPONENTS_SUPPORTING_CUSTOM_SERVICEACCOUNT_ANNOTATIONS,
         )
+
+    def test_per_component_custom_annotations(self):
+        release_name = "RELEASE_NAME"
+
+        k8s_objects = render_chart(
+            name=release_name,
+            values={
+                "scheduler": {
+                    "podAnnotations": {
+                        "example": "scheduler",
+                    },
+                },
+                "webserver": {
+                    "podAnnotations": {
+                        "example": "webserver",
+                    },
+                },
+                "workers": {
+                    "podAnnotations": {
+                        "example": "worker",
+                    },
+                },
+                "flower": {
+                    "podAnnotations": {
+                        "example": "flower",
+                    },
+                },
+                "airflowVersion": "2.2.0",  # Needed for triggerer to be 
enabled.
+                "triggerer": {
+                    "podAnnotations": {
+                        "example": "triggerer",
+                    },
+                },
+            },
+            show_only=[
+                "templates/scheduler/scheduler-deployment.yaml",
+                "templates/workers/worker-deployment.yaml",
+                "templates/webserver/webserver-deployment.yaml",
+                "templates/flower/flower-deployment.yaml",
+                "templates/triggerer/triggerer-deployment.yaml",
+            ],
+        )
+
+        # The test relies on the convention that the Deployment name
+        # is always `{ Release.Name }-<component_name>`.
+        obj_by_component_name = {
+            obj["metadata"]["name"].replace(release_name + "-", ""): obj for 
obj in k8s_objects
+        }
+
+        self.assertCountEqual(obj_by_component_name, 
COMPONENTS_SUPPORTING_CUSTOM_POD_ANNOTATIONS)
+
+        for component_name, obj in obj_by_component_name.items():
+            self.assertIn("example", 
obj["spec"]["template"]["metadata"]["annotations"])
+            self.assertEqual(component_name, 
obj["spec"]["template"]["metadata"]["annotations"]["example"])

Review comment:
       ```suggestion
               assert "example" in 
obj["spec"]["template"]["metadata"]["annotations"]
               assert component_name == 
obj["spec"]["template"]["metadata"]["annotations"]["example"]
   ```
   
   Minor, but we prefer plain asserts.




-- 
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]


Reply via email to