From 4340e272d7c83abce0b5c597999e4bab758cad45 Mon Sep 17 00:00:00 2001 From: Marlin Cremers Date: Thu, 23 Sep 2021 15:57:22 +0200 Subject: [PATCH] feat(helm-toolkit): allow setting extra labels on pods Currently it isn't possible to set extra labels on pods that use the labels snippet. This means users are required to fork the helm repository for OpenStack services to add custom labels. Use cases for this are for example injecting Istio sidecars. This change introduces the ability to set one set of labels on all resources that use the labels snippet. Change-Id: Iefc8465300f434b89c07b18ba75260fee0a05ef5 --- helm-toolkit/Chart.yaml | 2 +- .../snippets/_kubernetes_metadata_labels.tpl | 16 ++++++++++++++++ releasenotes/notes/helm-toolkit.yaml | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/helm-toolkit/Chart.yaml b/helm-toolkit/Chart.yaml index 2ee0787b4..2c566e915 100644 --- a/helm-toolkit/Chart.yaml +++ b/helm-toolkit/Chart.yaml @@ -15,7 +15,7 @@ apiVersion: v1 appVersion: v1.0.0 description: OpenStack-Helm Helm-Toolkit name: helm-toolkit -version: 0.2.21 +version: 0.2.22 home: https://docs.openstack.org/openstack-helm icon: https://www.openstack.org/themes/openstack/images/project-mascots/OpenStack-Helm/OpenStack_Project_OpenStackHelm_vertical.png sources: diff --git a/helm-toolkit/templates/snippets/_kubernetes_metadata_labels.tpl b/helm-toolkit/templates/snippets/_kubernetes_metadata_labels.tpl index 0324e682d..48b53fa10 100644 --- a/helm-toolkit/templates/snippets/_kubernetes_metadata_labels.tpl +++ b/helm-toolkit/templates/snippets/_kubernetes_metadata_labels.tpl @@ -17,12 +17,20 @@ abstract: | Renders a set of standardised labels values: | release_group: null + pod: + labels: + default: + label1.example.com: value + bar: + label2.example.com: bar usage: | {{ tuple . "foo" "bar" | include "helm-toolkit.snippets.kubernetes_metadata_labels" }} return: | release_group: RELEASE-NAME application: foo component: bar + label1.example.com: value + label2.example.com: bar */}} {{- define "helm-toolkit.snippets.kubernetes_metadata_labels" -}} @@ -32,4 +40,12 @@ return: | release_group: {{ $envAll.Values.release_group | default $envAll.Release.Name }} application: {{ $application }} component: {{ $component }} +{{- if ($envAll.Values.pod).labels }} +{{- if hasKey $envAll.Values.pod.labels $component }} +{{ index $envAll.Values.pod "labels" $component | toYaml }} +{{- end -}} +{{- if hasKey $envAll.Values.pod.labels "default" }} +{{ $envAll.Values.pod.labels.default | toYaml }} +{{- end -}} +{{- end -}} {{- end -}} diff --git a/releasenotes/notes/helm-toolkit.yaml b/releasenotes/notes/helm-toolkit.yaml index 951996d79..568f65e72 100644 --- a/releasenotes/notes/helm-toolkit.yaml +++ b/releasenotes/notes/helm-toolkit.yaml @@ -28,4 +28,5 @@ helm-toolkit: - 0.2.19 Revoke all privileges for PUBLIC role in postgres dbs - 0.2.20 Modify the template of rbac_role to make secrets accessible - 0.2.21 Fix issue with db backup error return code being eaten + - 0.2.22 Add ability to set labels to add to resources ...