From 02bb6d650ef64107c07206012765b1de21f10e57 Mon Sep 17 00:00:00 2001 From: Christian Kotzbauer Date: Sat, 20 Jun 2020 09:45:39 +0200 Subject: [PATCH] use template function for labels Signed-off-by: Christian Kotzbauer --- charts/kured/templates/_helpers.tpl | 10 ++++++++++ charts/kured/templates/clusterrole.yaml | 5 +---- charts/kured/templates/clusterrolebinding.yaml | 5 +---- charts/kured/templates/daemonset.yaml | 11 +++-------- charts/kured/templates/podsecuritypolicy.yaml | 5 +---- charts/kured/templates/role.yaml | 5 +---- charts/kured/templates/rolebinding.yaml | 5 +---- charts/kured/templates/serviceaccount.yaml | 2 ++ 8 files changed, 20 insertions(+), 28 deletions(-) diff --git a/charts/kured/templates/_helpers.tpl b/charts/kured/templates/_helpers.tpl index 38c3a43..271b902 100644 --- a/charts/kured/templates/_helpers.tpl +++ b/charts/kured/templates/_helpers.tpl @@ -52,3 +52,13 @@ Return the appropriate apiVersion for podsecuritypolicy. {{- print "policy/v1beta1" -}} {{- end -}} {{- end -}} + +{{/* +Returns a set of labels applied to each resource. +*/}} +{{- define "kured.labels" -}} +app: {{ template "kured.name" . }} +chart: {{ template "kured.chart" . }} +release: {{ .Release.Name }} +heritage: {{ .Release.Service }} +{{- end -}} diff --git a/charts/kured/templates/clusterrole.yaml b/charts/kured/templates/clusterrole.yaml index f077c21..1abde05 100644 --- a/charts/kured/templates/clusterrole.yaml +++ b/charts/kured/templates/clusterrole.yaml @@ -4,10 +4,7 @@ kind: ClusterRole metadata: name: {{ template "kured.fullname" . }} labels: - app: {{ template "kured.name" . }} - chart: {{ template "kured.chart" . }} - release: {{ .Release.Name }} - heritage: {{ .Release.Service }} + {{- include "kured.labels" . | nindent 4 }} rules: # Allow kured to read spec.unschedulable # Allow kubectl to drain/uncordon diff --git a/charts/kured/templates/clusterrolebinding.yaml b/charts/kured/templates/clusterrolebinding.yaml index a5586e9..1b2e45b 100644 --- a/charts/kured/templates/clusterrolebinding.yaml +++ b/charts/kured/templates/clusterrolebinding.yaml @@ -4,10 +4,7 @@ kind: ClusterRoleBinding metadata: name: {{ template "kured.fullname" . }} labels: - app: {{ template "kured.name" . }} - chart: {{ template "kured.chart" . }} - release: {{ .Release.Name }} - heritage: {{ .Release.Service }} + {{- include "kured.labels" . | nindent 4 }} roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole diff --git a/charts/kured/templates/daemonset.yaml b/charts/kured/templates/daemonset.yaml index 4f141ae..215199d 100644 --- a/charts/kured/templates/daemonset.yaml +++ b/charts/kured/templates/daemonset.yaml @@ -4,22 +4,17 @@ metadata: name: {{ template "kured.fullname" . }} namespace: {{ .Release.Namespace }} labels: - app: {{ template "kured.name" . }} - chart: {{ template "kured.chart" . }} - release: {{ .Release.Name }} - heritage: {{ .Release.Service }} + {{- include "kured.labels" . | nindent 4 }} spec: updateStrategy: type: {{ .Values.updateStrategy }} selector: matchLabels: - app: {{ template "kured.name" . }} - release: {{ .Release.Name }} + {{- include "kured.labels" . | nindent 6 }} template: metadata: labels: - app: {{ template "kured.name" . }} - release: {{ .Release.Name }} + {{- include "kured.labels" . | nindent 8 }} {{- if .Values.podAnnotations }} annotations: {{- range $key, $value := .Values.podAnnotations }} diff --git a/charts/kured/templates/podsecuritypolicy.yaml b/charts/kured/templates/podsecuritypolicy.yaml index d4e2f18..71a3095 100644 --- a/charts/kured/templates/podsecuritypolicy.yaml +++ b/charts/kured/templates/podsecuritypolicy.yaml @@ -4,10 +4,7 @@ kind: PodSecurityPolicy metadata: name: {{ template "kured.fullname" . }} labels: - app: {{ template "kured.name" . }} - chart: {{ template "kured.chart" . }} - release: {{ .Release.Name }} - heritage: {{ .Release.Service }} + {{- include "kured.labels" . | nindent 4 }} spec: privileged: true hostPID: true diff --git a/charts/kured/templates/role.yaml b/charts/kured/templates/role.yaml index 5576036..cf0b8b0 100644 --- a/charts/kured/templates/role.yaml +++ b/charts/kured/templates/role.yaml @@ -5,10 +5,7 @@ metadata: namespace: {{ .Release.Namespace }} name: {{ template "kured.fullname" . }} labels: - app: {{ template "kured.name" . }} - chart: {{ template "kured.chart" . }} - release: {{ .Release.Name }} - heritage: {{ .Release.Service }} + {{- include "kured.labels" . | nindent 4 }} rules: # Allow kured to lock/unlock itself - apiGroups: ["extensions"] diff --git a/charts/kured/templates/rolebinding.yaml b/charts/kured/templates/rolebinding.yaml index df3f177..58f1b26 100644 --- a/charts/kured/templates/rolebinding.yaml +++ b/charts/kured/templates/rolebinding.yaml @@ -5,10 +5,7 @@ metadata: namespace: {{ .Release.Namespace }} name: {{ template "kured.fullname" . }} labels: - app: {{ template "kured.name" . }} - chart: {{ template "kured.chart" . }} - release: {{ .Release.Name }} - heritage: {{ .Release.Service }} + {{- include "kured.labels" . | nindent 4 }} subjects: - kind: ServiceAccount namespace: {{ .Release.Namespace }} diff --git a/charts/kured/templates/serviceaccount.yaml b/charts/kured/templates/serviceaccount.yaml index 8a754ea..4ce53b9 100644 --- a/charts/kured/templates/serviceaccount.yaml +++ b/charts/kured/templates/serviceaccount.yaml @@ -4,4 +4,6 @@ kind: ServiceAccount metadata: name: {{ template "kured.serviceAccountName" . }} namespace: {{ .Release.Namespace }} + labels: + {{- include "kured.labels" . | nindent 4 }} {{- end -}}