From cdb56fcb2acab8b292811942eb7f3fd4d9db40b1 Mon Sep 17 00:00:00 2001 From: Jacob LeGrone Date: Mon, 16 Jul 2018 17:49:21 -0400 Subject: [PATCH] Add standard helm labels to resources --- charts/virtual-kubelet/templates/NOTES.txt | 2 +- charts/virtual-kubelet/templates/_helpers.tpl | 13 +++++++++++++ .../templates/clusterrolebinding.yaml | 1 + charts/virtual-kubelet/templates/deployment.yaml | 6 ++++-- charts/virtual-kubelet/templates/secret.yaml | 1 + .../virtual-kubelet/templates/serviceaccount.yaml | 1 + .../virtual-kubelet/templates/tests/helloworld.yaml | 4 ++-- 7 files changed, 23 insertions(+), 5 deletions(-) diff --git a/charts/virtual-kubelet/templates/NOTES.txt b/charts/virtual-kubelet/templates/NOTES.txt index 173aded51..ae4fc0943 100644 --- a/charts/virtual-kubelet/templates/NOTES.txt +++ b/charts/virtual-kubelet/templates/NOTES.txt @@ -2,7 +2,7 @@ The virtual kubelet is getting deployed on your cluster. To verify that virtual kubelet has started, run: - kubectl --namespace={{ .Release.Namespace }} get pods -l "app={{ template "vk.fullname" . }}" + kubectl --namespace={{ .Release.Namespace }} get pods -l "app={{ template "vk.name" . }}" {{- if (not .Values.env.apiserverCert) and (not .Values.env.apiserverKey) }} diff --git a/charts/virtual-kubelet/templates/_helpers.tpl b/charts/virtual-kubelet/templates/_helpers.tpl index 2f07d9545..4b0b69928 100644 --- a/charts/virtual-kubelet/templates/_helpers.tpl +++ b/charts/virtual-kubelet/templates/_helpers.tpl @@ -14,3 +14,16 @@ We truncate at 24 chars because some Kubernetes name fields are limited to this {{- $name := default .Chart.Name .Values.nameOverride -}} {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} {{- end -}} + +{{/* +Standard labels for helm resources +*/}} +{{- define "vk.labels" -}} +labels: + heritage: "{{ .Release.Service }}" + release: "{{ .Release.Name }}" + revision: "{{ .Release.Revision }}" + chart: "{{ .Chart.Name }}" + chartVersion: "{{ .Chart.Version }}" + app: {{ template "vk.name" . }} +{{- end -}} diff --git a/charts/virtual-kubelet/templates/clusterrolebinding.yaml b/charts/virtual-kubelet/templates/clusterrolebinding.yaml index a00bf6a83..5f80001f6 100644 --- a/charts/virtual-kubelet/templates/clusterrolebinding.yaml +++ b/charts/virtual-kubelet/templates/clusterrolebinding.yaml @@ -3,6 +3,7 @@ apiVersion: "rbac.authorization.k8s.io/{{ .Values.rbac.apiVersion }}" kind: ClusterRoleBinding metadata: name: {{ template "vk.fullname" . }} +{{ include "vk.labels" . | indent 2 }} subjects: - kind: ServiceAccount name: {{ template "vk.fullname" . }} diff --git a/charts/virtual-kubelet/templates/deployment.yaml b/charts/virtual-kubelet/templates/deployment.yaml index 8bbdd304f..0d07189ea 100644 --- a/charts/virtual-kubelet/templates/deployment.yaml +++ b/charts/virtual-kubelet/templates/deployment.yaml @@ -2,14 +2,16 @@ apiVersion: extensions/v1beta1 kind: Deployment metadata: name: {{ template "vk.fullname" . }} +{{ include "vk.labels" . | indent 2 }} + component: kubelet annotations: virtual-kubelet/provider: {{ required "provider is required" .Values.provider }} spec: replicas: 1 template: metadata: - labels: - app: {{ template "vk.fullname" . }} +{{ include "vk.labels" . | indent 6 }} + component: kubelet annotations: checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }} spec: diff --git a/charts/virtual-kubelet/templates/secret.yaml b/charts/virtual-kubelet/templates/secret.yaml index 5975cbcec..7df587009 100644 --- a/charts/virtual-kubelet/templates/secret.yaml +++ b/charts/virtual-kubelet/templates/secret.yaml @@ -2,6 +2,7 @@ apiVersion: v1 kind: Secret metadata: name: {{ template "vk.fullname" . }} +{{ include "vk.labels" . | indent 2 }} type: Opaque data: {{- if (not .Values.env.apiserverCert) and (not .Values.env.apiserverKey) }} diff --git a/charts/virtual-kubelet/templates/serviceaccount.yaml b/charts/virtual-kubelet/templates/serviceaccount.yaml index a25f8777f..dcc9f926e 100644 --- a/charts/virtual-kubelet/templates/serviceaccount.yaml +++ b/charts/virtual-kubelet/templates/serviceaccount.yaml @@ -3,4 +3,5 @@ apiVersion: v1 kind: ServiceAccount metadata: name: {{ template "vk.fullname" . }} +{{ include "vk.labels" . | indent 2 }} {{ end }} diff --git a/charts/virtual-kubelet/templates/tests/helloworld.yaml b/charts/virtual-kubelet/templates/tests/helloworld.yaml index 41fa0173f..c29fb30a4 100644 --- a/charts/virtual-kubelet/templates/tests/helloworld.yaml +++ b/charts/virtual-kubelet/templates/tests/helloworld.yaml @@ -2,8 +2,8 @@ apiVersion: v1 kind: Pod metadata: name: "{{ .Release.Name }}-{{ .Release.Revision }}-test" - labels: - role: test +{{ include "vk.labels" . | indent 2 }} + component: test annotations: "helm.sh/hook": test-success spec: