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
This commit is contained in:
parent
da99ce9a07
commit
75e0c2d0f5
@ -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 -}}
|
||||
|
Loading…
Reference in New Issue
Block a user