From dbc36835a16f3c4f7e813a8a536c0922ef1f6bbd Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Fri, 23 Sep 2022 11:45:27 +0200 Subject: Add labels template --- templates/_helpers.tpl | 27 +++++++++++++++++++++++++++ templates/configmap.yaml | 6 +++--- templates/deployment.yaml | 11 +++-------- templates/hpa.yaml | 6 +++--- templates/service.yaml | 7 ++----- 5 files changed, 38 insertions(+), 19 deletions(-) (limited to 'templates') diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index 52158b7..638fade 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -14,3 +14,30 @@ We truncate at 63 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 -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "invidious.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "invidious.labels" -}} +helm.sh/chart: {{ include "invidious.chart" . }} +{{ include "invidious.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "invidious.selectorLabels" -}} +app.kubernetes.io/name: {{ include "invidious.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} diff --git a/templates/configmap.yaml b/templates/configmap.yaml index 58542a3..74d6603 100644 --- a/templates/configmap.yaml +++ b/templates/configmap.yaml @@ -1,11 +1,11 @@ +--- apiVersion: v1 kind: ConfigMap metadata: name: {{ template "invidious.fullname" . }} labels: - app: {{ template "invidious.name" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" - release: {{ .Release.Name }} + {{- include "invidious.labels" . | nindent 4 }} data: INVIDIOUS_CONFIG: | {{ toYaml .Values.config | indent 4 }} +... diff --git a/templates/deployment.yaml b/templates/deployment.yaml index ea1bab5..f0ac30f 100644 --- a/templates/deployment.yaml +++ b/templates/deployment.yaml @@ -4,21 +4,16 @@ kind: Deployment metadata: name: {{ template "invidious.fullname" . }} labels: - app: {{ template "invidious.name" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" - release: {{ .Release.Name }} + {{- include "invidious.labels" . | nindent 4 }} spec: replicas: {{ .Values.replicaCount }} selector: matchLabels: - app: {{ template "invidious.name" . }} - release: {{ .Release.Name }} + {{- include "invidious.selectorLabels" . | nindent 6 }} template: metadata: labels: - app: {{ template "invidious.name" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" - release: {{ .Release.Name }} + {{- include "invidious.selectorLabels" . | nindent 8 }} spec: securityContext: runAsUser: {{ .Values.securityContext.runAsUser }} diff --git a/templates/hpa.yaml b/templates/hpa.yaml index c6fbefe..fe1f4e4 100644 --- a/templates/hpa.yaml +++ b/templates/hpa.yaml @@ -1,12 +1,11 @@ +--- {{- if .Values.autoscaling.enabled }} apiVersion: autoscaling/v1 kind: HorizontalPodAutoscaler metadata: name: {{ template "invidious.fullname" . }} labels: - app: {{ template "invidious.name" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" - release: {{ .Release.Name }} + {{- include "invidious.labels" . | nindent 4 }} spec: scaleTargetRef: apiVersion: apps/v1 @@ -16,3 +15,4 @@ spec: maxReplicas: {{ .Values.autoscaling.maxReplicas }} targetCPUUtilizationPercentage: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} {{- end }} +... diff --git a/templates/service.yaml b/templates/service.yaml index f1dc7ea..0513f51 100644 --- a/templates/service.yaml +++ b/templates/service.yaml @@ -4,9 +4,7 @@ kind: Service metadata: name: {{ template "invidious.fullname" . }} labels: - app: {{ template "invidious.name" . }} - chart: {{ .Chart.Name }} - release: {{ .Release.Name }} + {{- include "invidious.labels" . | nindent 4 }} spec: type: {{ .Values.service.type }} ports: @@ -14,8 +12,7 @@ spec: port: {{ .Values.service.port }} targetPort: 3000 selector: - app: {{ template "invidious.name" . }} - release: {{ .Release.Name }} + {{- include "invidious.selectorLabels" . | nindent 4 }} {{- if .Values.service.loadBalancerIP }} loadBalancerIP: {{ .Values.service.loadBalancerIP }} {{- end }} -- cgit v1.1