You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2021/09/21 18:43:31 UTC

[airflow] branch main updated: Labels on job templates (#18403)

This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new a91d9a7  Labels on job templates (#18403)
a91d9a7 is described below

commit a91d9a7d681a5227d7d72876110e31b448383c20
Author: Gabriel Machado <ga...@hotmail.com>
AuthorDate: Tue Sep 21 20:43:12 2021 +0200

    Labels on job templates (#18403)
---
 chart/templates/jobs/create-user-job.yaml      |  3 +++
 chart/templates/jobs/migrate-database-job.yaml |  3 +++
 chart/tests/test_basic_helm_chart.py           | 35 ++++++++++++++++++++++++++
 3 files changed, 41 insertions(+)

diff --git a/chart/templates/jobs/create-user-job.yaml b/chart/templates/jobs/create-user-job.yaml
index 5f7b894..c88ed5a 100644
--- a/chart/templates/jobs/create-user-job.yaml
+++ b/chart/templates/jobs/create-user-job.yaml
@@ -49,6 +49,9 @@ spec:
         tier: airflow
         component: create-user-job
         release: {{ .Release.Name }}
+{{- with .Values.labels }}
+{{ toYaml . | indent 8 }}
+{{- end }}
       {{- if or .Values.airflowPodAnnotations .Values.createUserJob.annotations }}
       annotations:
         {{- if .Values.airflowPodAnnotations }}
diff --git a/chart/templates/jobs/migrate-database-job.yaml b/chart/templates/jobs/migrate-database-job.yaml
index ec01e13..7ee5b75 100644
--- a/chart/templates/jobs/migrate-database-job.yaml
+++ b/chart/templates/jobs/migrate-database-job.yaml
@@ -48,6 +48,9 @@ spec:
         tier: airflow
         component: run-airflow-migrations
         release: {{ .Release.Name }}
+{{- with .Values.labels }}
+{{ toYaml . | indent 8 }}
+{{- end }}
       {{- if or .Values.airflowPodAnnotations .Values.migrateDatabaseJob.annotations }}
       annotations:
         {{- if .Values.airflowPodAnnotations }}
diff --git a/chart/tests/test_basic_helm_chart.py b/chart/tests/test_basic_helm_chart.py
index 014283e..4ff746b 100644
--- a/chart/tests/test_basic_helm_chart.py
+++ b/chart/tests/test_basic_helm_chart.py
@@ -223,6 +223,41 @@ class TestBaseChartTest(unittest.TestCase):
         if kind_k8s_obj_labels_tuples:
             warnings.warn(f"Unchecked objects: {kind_k8s_obj_labels_tuples.keys()}")
 
+    def test_labels_are_valid_on_job_templates(self):
+        """Test labels are correctly applied on all job templates created by this chart"""
+        release_name = "TEST-BASIC"
+        k8s_objects = render_chart(
+            name=release_name,
+            values={
+                "labels": {"label1": "value1", "label2": "value2"},
+                "executor": "CeleryExecutor",
+                "pgbouncer": {"enabled": True},
+                "redis": {"enabled": True},
+                "networkPolicies": {"enabled": True},
+                "cleanup": {"enabled": True},
+                "postgresql": {"enabled": False},  # We won't check the objects created by the postgres chart
+            },
+        )
+        dict_of_labels_in_job_templates = {
+            k8s_object['metadata']['name']: k8s_object['spec']['template']['metadata']['labels']
+            for k8s_object in k8s_objects
+            if k8s_object['kind'] == "Job"
+        }
+
+        kind_names_tuples = [
+            (f"{release_name}-create-user", "create-user-job"),
+            (f"{release_name}-run-airflow-migrations", "run-airflow-migrations"),
+        ]
+        for k8s_object_name, component in kind_names_tuples:
+            expected_labels = {
+                "label1": "value1",
+                "label2": "value2",
+                "tier": "airflow",
+                "release": release_name,
+                "component": component,
+            }
+            assert dict_of_labels_in_job_templates.get(k8s_object_name) == expected_labels
+
     def test_annotations_on_airflow_pods_in_deployment(self):
         """
         Test Annotations are correctly applied on all pods created Scheduler, Webserver & Worker