diff --git a/chart/templates/configmaps/extra-configmaps.yaml b/chart/templates/configmaps/extra-configmaps.yaml index 1ac0d6ab485e1..dca885c2c6b45 100644 --- a/chart/templates/configmaps/extra-configmaps.yaml +++ b/chart/templates/configmaps/extra-configmaps.yaml @@ -39,6 +39,9 @@ metadata: "helm.sh/hook": "pre-install,pre-upgrade" "helm.sh/hook-delete-policy": "before-hook-creation" "helm.sh/hook-weight": "0" + {{- if $configMapContent.annotations }} + {{- toYaml $configMapContent.annotations | nindent 4 }} + {{- end }} {{- if $configMapContent.data }} data: {{- with $configMapContent.data }} diff --git a/chart/templates/secrets/extra-secrets.yaml b/chart/templates/secrets/extra-secrets.yaml index f528f20d24b26..daadc9ac1b12c 100644 --- a/chart/templates/secrets/extra-secrets.yaml +++ b/chart/templates/secrets/extra-secrets.yaml @@ -39,6 +39,9 @@ metadata: "helm.sh/hook": "pre-install,pre-upgrade" "helm.sh/hook-delete-policy": "before-hook-creation" "helm.sh/hook-weight": "0" + {{- if $secretContent.annotations }} + {{- toYaml $secretContent.annotations | nindent 4 }} + {{- end }} {{- if $secretContent.type }} type: {{ $secretContent.type }} {{- end }} diff --git a/chart/values.schema.json b/chart/values.schema.json index 3df9266c208f6..f877e195acf29 100644 --- a/chart/values.schema.json +++ b/chart/values.schema.json @@ -891,6 +891,14 @@ "type": "string" } }, + "annotations": { + "description": "Annotations 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" @@ -929,6 +937,14 @@ "type": "string" } }, + "annotations": { + "description": "Annotations for the configmap", + "type": "object", + "default": null, + "additionalProperties": { + "type": "string" + } + }, "data": { "description": "Content **as string** for the 'data' item of the configmap (can be templated)", "type": "string" diff --git a/chart/values_schema.schema.json b/chart/values_schema.schema.json index f74d8ab871326..64179d5a7a47f 100644 --- a/chart/values_schema.schema.json +++ b/chart/values_schema.schema.json @@ -9,7 +9,7 @@ "not": { "properties": { "description": { - "pattern": "^Labels for the configmap$|^Labels for the secret$" + "pattern": "^Labels for the configmap$|^Labels for the secret$|^Annotations for the configmap$|^Annotations for the secret$" } } } diff --git a/tests/charts/test_extra_configmaps_secrets.py b/tests/charts/test_extra_configmaps_secrets.py index 0ed5bd3ec9581..bc22f26cfe089 100644 --- a/tests/charts/test_extra_configmaps_secrets.py +++ b/tests/charts/test_extra_configmaps_secrets.py @@ -185,3 +185,33 @@ def test_extra_configmaps_secrets_additional_labels(self, chart_labels, local_la } for k8s_object in k8s_objects: assert k8s_object["metadata"]["labels"] == {**common_labels, **chart_labels, **local_labels} + + def test_extra_configmaps_secrets_additional_annotations(self): + k8s_objects = render_chart( + name=RELEASE_NAME, + values={ + "extraSecrets": { + "{{ .Release.Name }}-extra-secret-1": { + "annotations": {"test_annotation": "test_annotation_value"}, + "stringData": "data: secretData", + } + }, + "extraConfigMaps": { + "{{ .Release.Name }}-extra-configmap-1": { + "annotations": {"test_annotation": "test_annotation_value"}, + "data": "data: configData", + } + }, + }, + show_only=["templates/configmaps/extra-configmaps.yaml", "templates/secrets/extra-secrets.yaml"], + ) + + expected_annotations = { + "helm.sh/hook": "pre-install,pre-upgrade", + "helm.sh/hook-delete-policy": "before-hook-creation", + "helm.sh/hook-weight": "0", + "test_annotation": "test_annotation_value", + } + + for k8s_object in k8s_objects: + assert k8s_object["metadata"]["annotations"] == expected_annotations