From 75e0c2d0f526d29ea947e03e3d1ea2ea34a48881 Mon Sep 17 00:00:00 2001 From: Sean Eagan Date: Mon, 3 Dec 2018 14:57:07 -0600 Subject: [PATCH] helm-toolkit: Support standard kubernetes/helm labels As documented in [1]. Also add quotes around those and existing metadata labels. [1]: https://docs.helm.sh/chart_best_practices/#standard-labels Change-Id: I1e195deb23e87567041e237212b5a828bb34f3e8 --- .../snippets/_kubernetes_metadata_labels.tpl | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/helm-toolkit/templates/snippets/_kubernetes_metadata_labels.tpl b/helm-toolkit/templates/snippets/_kubernetes_metadata_labels.tpl index f67bfaf28..7faadd932 100644 --- a/helm-toolkit/templates/snippets/_kubernetes_metadata_labels.tpl +++ b/helm-toolkit/templates/snippets/_kubernetes_metadata_labels.tpl @@ -16,22 +16,45 @@ limitations under the License. {{/* abstract: | - Renders a set of standardised labels + Renders a set of standardised labels as per: + https://docs.helm.sh/chart_best_practices/#standard-labels values: | release_group: null usage: | {{ tuple . "foo" "bar" | include "helm-toolkit.snippets.kubernetes_metadata_labels" }} return: | - release_group: RELEASE-NAME - application: foo - component: bar + helm.sh/chart: "CHART-NAME-CHART-VERSION" + app.kubernetes.io/managed-by: "Tiller" + app.kubernetes.io/instance: "RELEASE-NAME" + app.kubernetes.io/version: "APP-VERSION" + app.kubernetes.io/name: "foo" + app.kubernetes.io/component: "bar" + release_group: "RELEASE-NAME" + application: "foo" + component: "bar" */}} +{{/* TODO: Remove old deprecated labels after an appropriate migration period */}} {{- define "helm-toolkit.snippets.kubernetes_metadata_labels" -}} {{- $envAll := index . 0 -}} -{{- $application := index . 1 -}} -{{- $component := index . 2 -}} -release_group: {{ $envAll.Values.release_group | default $envAll.Release.Name }} +{{- $chart := print $envAll.Chart.Name "-" $envAll.Chart.Version | replace "+" "_" | quote -}} +{{- $_application := index . 1 -}} +{{- $partOf := $envAll.Values.part_of | default $_application | quote -}} +{{- $application := $_application | quote -}} +{{- $component := index . 2 | quote -}} +{{- $instance := $envAll.Values.release_group | default $envAll.Release.Name | quote -}} +{{- $version := $envAll.Chart.AppVersion -}} +{{- $managedBy := $envAll.Release.Service | quote -}} +helm.sh/chart: {{ $chart }} +app.kubernetes.io/managed-by: {{ $managedBy }} +app.kubernetes.io/instance: {{ $instance }} +{{- if $version }} +app.kubernetes.io/version: {{ $version }} +{{- end }} +app.kubernetes.io/name: {{ $application }} +app.kubernetes.io/component: {{ $component }} +app.kubernetes.io/part-of: {{ $partOf }} +release_group: {{ $instance }} application: {{ $application }} component: {{ $component }} {{- end -}}