You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by je...@apache.org on 2022/08/04 22:11:21 UTC

[airflow] branch main updated: Chart: custom labels for extrasecrets/configmaps (#25283)

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

jedcunningham 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 58fb646385 Chart: custom labels for extrasecrets/configmaps (#25283)
58fb646385 is described below

commit 58fb6463858ff4d3c73d71fd78230b5547539b0b
Author: Aakcht <aa...@gmail.com>
AuthorDate: Fri Aug 5 01:11:08 2022 +0300

    Chart: custom labels for extrasecrets/configmaps (#25283)
---
 chart/templates/configmaps/extra-configmaps.yaml |  3 ++
 chart/templates/secrets/extra-secrets.yaml       |  3 ++
 chart/values.schema.json                         | 18 +++++++++++-
 chart/values.yaml                                |  8 ++++--
 chart/values_schema.schema.json                  | 15 ++++++++--
 tests/charts/test_extra_configmaps_secrets.py    | 36 ++++++++++++++++++++++++
 6 files changed, 78 insertions(+), 5 deletions(-)

diff --git a/chart/templates/configmaps/extra-configmaps.yaml b/chart/templates/configmaps/extra-configmaps.yaml
index 5daac57660..58805a827a 100644
--- a/chart/templates/configmaps/extra-configmaps.yaml
+++ b/chart/templates/configmaps/extra-configmaps.yaml
@@ -31,6 +31,9 @@ metadata:
     heritage: {{ $Global.Release.Service }}
 {{- with $Global.Values.labels }}
 {{ toYaml . | indent 4 }}
+{{- end }}
+{{- if $configMapContent.labels }}
+{{ toYaml $configMapContent.labels | indent 4 }}
 {{- end }}
   annotations:
     "helm.sh/hook": "pre-install,pre-upgrade"
diff --git a/chart/templates/secrets/extra-secrets.yaml b/chart/templates/secrets/extra-secrets.yaml
index 20c1751d96..40c56306f2 100644
--- a/chart/templates/secrets/extra-secrets.yaml
+++ b/chart/templates/secrets/extra-secrets.yaml
@@ -31,6 +31,9 @@ metadata:
     heritage: {{ $Global.Release.Service }}
 {{- with $Global.Values.labels }}
 {{ toYaml . | indent 4 }}
+{{- end }}
+{{- if $secretContent.labels }}
+{{ toYaml $secretContent.labels | indent 4 }}
 {{- end }}
   annotations:
     "helm.sh/hook": "pre-install,pre-upgrade"
diff --git a/chart/values.schema.json b/chart/values.schema.json
index b24e8fcf0c..279a59d955 100644
--- a/chart/values.schema.json
+++ b/chart/values.schema.json
@@ -857,6 +857,14 @@
                         "description": "Type **as string** of secret E.G. Opaque, kubernetes.io/dockerconfigjson, etc.",
                         "type": "string"
                     },
+                    "labels": {
+                        "description": "Labels for the secret",
+                        "type": "object",
+                        "default": null,
+                        "additionalProperties": {
+                            "type": "string"
+                        }
+                    },
                     "data": {
                         "description": "Content **as string** for the 'data' item of the secret (can be templated)",
                         "type": "string"
@@ -887,8 +895,16 @@
                 "minProperties": 1,
                 "additionalProperties": false,
                 "properties": {
+                    "labels": {
+                        "description": "Labels for the configmap",
+                        "type": "object",
+                        "default": null,
+                        "additionalProperties": {
+                            "type": "string"
+                        }
+                    },
                     "data": {
-                        "description": "Content **as string** for the 'data' item of the secret (can be templated)",
+                        "description": "Content **as string** for the 'data' item of the configmap (can be templated)",
                         "type": "string"
                     }
                 }
diff --git a/chart/values.yaml b/chart/values.yaml
index f795e0f02a..9df5572388 100644
--- a/chart/values.yaml
+++ b/chart/values.yaml
@@ -268,7 +268,7 @@ enableBuiltInSecretEnvVars:
 
 # Extra secrets that will be managed by the chart
 # (You can use them with extraEnv or extraEnvFrom or some of the extraVolumes values).
-# The format is "key/value" where
+# The format for secret data is "key/value" where
 #    * key (can be templated) is the name of the secret that will be created
 #    * value: an object with the standard 'data' or 'stringData' key (or both).
 #          The value associated with those keys must be a string (can be templated)
@@ -277,6 +277,8 @@ extraSecrets: {}
 # extraSecrets:
 #   '{{ .Release.Name }}-airflow-connections':
 #     type: 'Opaque'
+#     labels:
+#       my.custom.label/v1: my_custom_label_value_1
 #     data: |
 #       AIRFLOW_CONN_GCP: 'base64_encoded_gcp_conn_string'
 #       AIRFLOW_CONN_AWS: 'base64_encoded_aws_conn_string'
@@ -288,7 +290,7 @@ extraSecrets: {}
 
 # Extra ConfigMaps that will be managed by the chart
 # (You can use them with extraEnv or extraEnvFrom or some of the extraVolumes values).
-# The format is "key/value" where
+# The format for configmap data is "key/value" where
 #    * key (can be templated) is the name of the configmap that will be created
 #    * value: an object with the standard 'data' key.
 #          The value associated with this keys must be a string (can be templated)
@@ -296,6 +298,8 @@ extraConfigMaps: {}
 # eg:
 # extraConfigMaps:
 #   '{{ .Release.Name }}-airflow-variables':
+#     labels:
+#       my.custom.label/v2: my_custom_label_value_2
 #     data: |
 #       AIRFLOW_VAR_HELLO_MESSAGE: "Hi!"
 #       AIRFLOW_VAR_KUBERNETES_NAMESPACE: "{{ .Release.Namespace }}"
diff --git a/chart/values_schema.schema.json b/chart/values_schema.schema.json
index f4b344d613..f74d8ab871 100644
--- a/chart/values_schema.schema.json
+++ b/chart/values_schema.schema.json
@@ -5,8 +5,19 @@
     "definitions": {
         "leafs": {
             "additionalProperties": {
-                "additionalProperties": {
-                    "$ref": "#/definitions/leafs"
+                "if": {
+                    "not": {
+                        "properties": {
+                            "description": {
+                                "pattern": "^Labels for the configmap$|^Labels for the secret$"
+                            }
+                        }
+                    }
+                },
+                "then": {
+                    "additionalProperties": {
+                        "$ref": "#/definitions/leafs"
+                    }
                 }
             },
             "if": {
diff --git a/tests/charts/test_extra_configmaps_secrets.py b/tests/charts/test_extra_configmaps_secrets.py
index c129b786ff..7bf0b9fab5 100644
--- a/tests/charts/test_extra_configmaps_secrets.py
+++ b/tests/charts/test_extra_configmaps_secrets.py
@@ -21,6 +21,7 @@ from base64 import b64encode
 from unittest import mock
 
 import yaml
+from parameterized import parameterized
 
 from tests.charts.helm_template_generator import prepare_k8s_lookup_dict, render_chart
 
@@ -148,3 +149,38 @@ class ExtraConfigMapsSecretsTest(unittest.TestCase):
         }
         for k8s_object in k8s_objects:
             assert k8s_object['metadata']['labels'] == expected_labels
+
+    @parameterized.expand(
+        [
+            ({}, {"label3": "value3", "label4": "value4"}),
+            ({"label1": "value1", "label2": "value2"}, {}),
+            ({"label1": "value1", "label2": "value2"}, {"label3": "value3", "label4": "value4"}),
+        ]
+    )
+    def test_extra_configmaps_secrets_additional_labels(self, chart_labels, local_labels):
+        k8s_objects = render_chart(
+            name=RELEASE_NAME,
+            values={
+                "labels": chart_labels,
+                "extraSecrets": {
+                    "{{ .Release.Name }}-extra-secret-1": {
+                        "labels": local_labels,
+                        "stringData": "data: secretData",
+                    }
+                },
+                "extraConfigMaps": {
+                    "{{ .Release.Name }}-extra-configmap-1": {
+                        "labels": local_labels,
+                        "data": "data: configData",
+                    }
+                },
+            },
+            show_only=["templates/configmaps/extra-configmaps.yaml", "templates/secrets/extra-secrets.yaml"],
+        )
+        common_labels = {
+            "release": RELEASE_NAME,
+            "heritage": "Helm",
+            "chart": mock.ANY,
+        }
+        for k8s_object in k8s_objects:
+            assert k8s_object['metadata']['labels'] == {**common_labels, **chart_labels, **local_labels}