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 051720401d Possibility to set labels specific to the migrateDatabaseJob objects and pods (#37490) 051720401d is described below commit 051720401d37d47c9c86867fd3d044b899b8b0ca Author: Ceeno <44981126+cyl...@users.noreply.github.com> AuthorDate: Wed Feb 28 00:55:47 2024 +0100 Possibility to set labels specific to the migrateDatabaseJob objects and pods (#37490) --------- Co-authored-by: cyla <cy...@numberly.com> --- .../jobs/migrate-database-job-serviceaccount.yaml | 4 +- chart/templates/jobs/migrate-database-job.yaml | 4 +- chart/values.schema.json | 8 +++ chart/values.yaml | 3 ++ .../airflow_aux/test_migrate_database_job.py | 63 ++++++++++++++++++++++ 5 files changed, 78 insertions(+), 4 deletions(-) diff --git a/chart/templates/jobs/migrate-database-job-serviceaccount.yaml b/chart/templates/jobs/migrate-database-job-serviceaccount.yaml index 52a07e5b03..edd74523cd 100644 --- a/chart/templates/jobs/migrate-database-job-serviceaccount.yaml +++ b/chart/templates/jobs/migrate-database-job-serviceaccount.yaml @@ -32,8 +32,8 @@ metadata: release: {{ .Release.Name }} chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" heritage: {{ .Release.Service }} - {{- with .Values.labels }} - {{- toYaml . | nindent 4 }} + {{- if or (.Values.labels) (.Values.migrateDatabaseJob.labels) }} + {{- mustMerge .Values.migrateDatabaseJob.labels .Values.labels | toYaml | nindent 4 }} {{- end }} {{- with .Values.migrateDatabaseJob.serviceAccount.annotations }} annotations: {{- toYaml . | nindent 4 }} diff --git a/chart/templates/jobs/migrate-database-job.yaml b/chart/templates/jobs/migrate-database-job.yaml index 728137726b..978595c598 100644 --- a/chart/templates/jobs/migrate-database-job.yaml +++ b/chart/templates/jobs/migrate-database-job.yaml @@ -60,8 +60,8 @@ spec: tier: airflow component: run-airflow-migrations release: {{ .Release.Name }} - {{- with .Values.labels }} - {{- toYaml . | nindent 8 }} + {{- if or (.Values.labels) (.Values.migrateDatabaseJob.labels) }} + {{- mustMerge .Values.migrateDatabaseJob.labels .Values.labels | toYaml | nindent 8 }} {{- end }} {{- if or .Values.airflowPodAnnotations .Values.migrateDatabaseJob.annotations }} annotations: diff --git a/chart/values.schema.json b/chart/values.schema.json index 04aa71ebf4..87846acdf2 100644 --- a/chart/values.schema.json +++ b/chart/values.schema.json @@ -4005,6 +4005,14 @@ "type": "string" } }, + "labels": { + "description": "Labels to add to the migrate database job objects and pods.", + "type": "object", + "default": {}, + "additionalProperties": { + "type": "string" + } + }, "serviceAccount": { "description": "Create ServiceAccount.", "type": "object", diff --git a/chart/values.yaml b/chart/values.yaml index 3a7b09af93..62c5174c5d 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -1086,6 +1086,9 @@ migrateDatabaseJob: # jobAnnotations are annotations on the database migration job jobAnnotations: {} + # Labels specific to migrate database job objects and pods + labels: {} + # When not set, the values defined in the global securityContext will be used securityContext: {} # runAsUser: 50000 diff --git a/helm_tests/airflow_aux/test_migrate_database_job.py b/helm_tests/airflow_aux/test_migrate_database_job.py index ea9a35134e..a13f62e29c 100644 --- a/helm_tests/airflow_aux/test_migrate_database_job.py +++ b/helm_tests/airflow_aux/test_migrate_database_job.py @@ -60,6 +60,39 @@ class TestMigrateDatabaseJob: assert "fiz" in job_annotations assert "fuz" == job_annotations["fiz"] + def test_should_add_component_specific_labels(self): + docs = render_chart( + values={ + "migrateDatabaseJob": { + "labels": {"test_label": "test_label_value"}, + }, + }, + show_only=["templates/jobs/migrate-database-job.yaml"], + ) + assert "test_label" in jmespath.search("spec.template.metadata.labels", docs[0]) + assert jmespath.search("spec.template.metadata.labels", docs[0])["test_label"] == "test_label_value" + + def test_should_merge_common_labels_and_component_specific_labels(self): + docs = render_chart( + values={ + "labels": {"test_common_label": "test_common_label_value"}, + "migrateDatabaseJob": { + "labels": {"test_specific_label": "test_specific_label_value"}, + }, + }, + show_only=["templates/jobs/migrate-database-job.yaml"], + ) + assert "test_common_label" in jmespath.search("spec.template.metadata.labels", docs[0]) + assert ( + jmespath.search("spec.template.metadata.labels", docs[0])["test_common_label"] + == "test_common_label_value" + ) + assert "test_specific_label" in jmespath.search("spec.template.metadata.labels", docs[0]) + assert ( + jmespath.search("spec.template.metadata.labels", docs[0])["test_specific_label"] + == "test_specific_label_value" + ) + def test_should_create_valid_affinity_tolerations_and_node_selector(self): docs = render_chart( values={ @@ -340,6 +373,36 @@ class TestMigrateDatabaseJob: class TestMigrateDatabaseJobServiceAccount: """Tests migrate database job service account.""" + def test_should_add_component_specific_labels(self): + docs = render_chart( + values={ + "migrateDatabaseJob": { + "labels": {"test_label": "test_label_value"}, + }, + }, + show_only=["templates/jobs/migrate-database-job-serviceaccount.yaml"], + ) + + assert "test_label" in jmespath.search("metadata.labels", docs[0]) + assert jmespath.search("metadata.labels", docs[0])["test_label"] == "test_label_value" + + def test_should_merge_common_labels_and_component_specific_labels(self): + docs = render_chart( + values={ + "labels": {"test_common_label": "test_common_label_value"}, + "migrateDatabaseJob": { + "labels": {"test_specific_label": "test_specific_label_value"}, + }, + }, + show_only=["templates/jobs/migrate-database-job-serviceaccount.yaml"], + ) + assert "test_common_label" in jmespath.search("metadata.labels", docs[0]) + assert jmespath.search("metadata.labels", docs[0])["test_common_label"] == "test_common_label_value" + assert "test_specific_label" in jmespath.search("metadata.labels", docs[0]) + assert ( + jmespath.search("metadata.labels", docs[0])["test_specific_label"] == "test_specific_label_value" + ) + def test_default_automount_service_account_token(self): docs = render_chart( values={