Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templatize resourceLabels for standardization #539

Merged
merged 3 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions charts/temporal/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,61 @@ and we want to make sure that the component is included in the name.
{{- printf "%s-%s" (include "temporal.fullname" $global | trunc (sub 62 (len $component) | int) | trimSuffix "-" ) $component | trimSuffix "-" -}}
{{- end -}}

{{/*
Define the AppVersion
*/}}
{{- define "temporal.appVersion" -}}
{{- if .Chart.AppVersion -}}
{{ .Chart.AppVersion | replace "+" "_" | quote }}
{{- else -}}
{{ include "temporal.chart" $ }}
{{- end -}}
{{- end -}}

{{/*
Create the labels for all resources
*/}}
{{- define "temporal.resourceLabels" -}}
{{- $global := index . 0 -}}
{{- $scope := index . 1 -}}
{{- $resourceType := index . 2 -}}
{{- $component := "server" -}}
{{- if (or (eq $scope "admintools") (eq $scope "web")) -}}
{{- $component = $scope -}}
{{- end -}}
{{- with $scope -}}
app.kubernetes.io/component: {{ . }}
{{ end -}}
app.kubernetes.io/name: {{ include "temporal.name" $global }}
helm.sh/chart: {{ include "temporal.chart" $global }}
app.kubernetes.io/managed-by: {{ index $global "Release" "Service" }}
app.kubernetes.io/instance: {{ index $global "Release" "Name" }}
app.kubernetes.io/version: {{ include "temporal.appVersion" $global }}
app.kubernetes.io/part-of: {{ $global.Chart.Name }}
{{- with $resourceType -}}
{{- $resourceTypeKey := printf "%sLabels" . -}}
{{- $resourceLabels := dict -}}
{{- if or (eq $scope "") (ne $component "server") -}}
{{- $resourceLabels = (index $global.Values $component $resourceTypeKey) -}}
{{- else -}}
{{- $resourceLabels = (index $global.Values $component $scope $resourceTypeKey) -}}
{{- end -}}
{{- range $label_name, $label_value := $resourceLabels -}}
{{ $label_name}}: {{ $label_value }}
{{- end -}}
{{- end -}}
{{ include "temporal.additionalResourceLabels" $global }}
{{- end -}}

{{/*
Additonal user specified labels for all resources
*/}}
{{- define "temporal.additionalResourceLabels" -}}
{{- range $label_name, $label_value := .Values.additionalLabels }}
{{ $label_name }}: {{ $label_value }}
{{- end -}}
{{- end -}}

{{/*
Call nested templates.
Source: https://stackoverflow.com/a/52024583/3027614
Expand Down
19 changes: 2 additions & 17 deletions charts/temporal/templates/admintools-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ kind: Deployment
metadata:
name: {{ include "temporal.componentname" (list . "admintools") }}
labels:
app.kubernetes.io/name: {{ include "temporal.name" . }}
helm.sh/chart: {{ include "temporal.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: admintools
app.kubernetes.io/part-of: {{ .Chart.Name }}
{{- include "temporal.resourceLabels" (list . "admintools" "") | nindent 4 }}
spec:
replicas: 1
selector:
Expand All @@ -21,16 +15,7 @@ spec:
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "temporal.name" . }}
helm.sh/chart: {{ include "temporal.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: admintools
app.kubernetes.io/part-of: {{ .Chart.Name }}
{{- with $.Values.admintools.podLabels }}
robholland marked this conversation as resolved.
Show resolved Hide resolved
{{- toYaml . | nindent 8 }}
{{- end }}
{{- include "temporal.resourceLabels" (list . "admintools" "pod") | nindent 8 }}
{{- with $.Values.admintools.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
Expand Down
8 changes: 1 addition & 7 deletions charts/temporal/templates/admintools-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ kind: Service
metadata:
name: {{ include "temporal.componentname" (list . "admintools") }}
labels:
app.kubernetes.io/name: {{ include "temporal.name" . }}
helm.sh/chart: {{ include "temporal.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: admintools
app.kubernetes.io/part-of: {{ .Chart.Name }}
{{- include "temporal.resourceLabels" (list . "admintools" "") | nindent 4 }}
spec:
type: ClusterIP
ports:
Expand Down
8 changes: 1 addition & 7 deletions charts/temporal/templates/frontend-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@ kind: Ingress
metadata:
name: {{ include "temporal.componentname" (list . "frontend") }}
labels:
app.kubernetes.io/name: {{ include "temporal.name" . }}
helm.sh/chart: {{ include "temporal.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: frontend
app.kubernetes.io/part-of: {{ .Chart.Name }}
{{- include "temporal.resourceLabels" (list . "frontend" "") | nindent 4 }}
{{- with .Values.server.frontend.ingress.annotations }}
annotations:
{{ toYaml . | indent 4 }}
Expand Down
7 changes: 1 addition & 6 deletions charts/temporal/templates/server-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ kind: ConfigMap
metadata:
name: "{{ include "temporal.fullname" $ }}-config"
labels:
app.kubernetes.io/name: {{ include "temporal.name" $ }}
helm.sh/chart: {{ include "temporal.chart" $ }}
app.kubernetes.io/managed-by: {{ $.Release.Service }}
app.kubernetes.io/instance: {{ $.Release.Name }}
app.kubernetes.io/version: {{ $.Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/part-of: {{ $.Chart.Name }}
{{- include "temporal.resourceLabels" (list . "" "") | nindent 4 }}
data:
config_template.yaml: |-
log:
Expand Down
19 changes: 2 additions & 17 deletions charts/temporal/templates/server-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ kind: Deployment
metadata:
name: {{ include "temporal.componentname" (list $ $service) }}
labels:
app.kubernetes.io/name: {{ include "temporal.name" $ }}
helm.sh/chart: {{ include "temporal.chart" $ }}
app.kubernetes.io/managed-by: {{ $.Release.Service }}
app.kubernetes.io/instance: {{ $.Release.Name }}
app.kubernetes.io/version: {{ $.Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: {{ $service }}
app.kubernetes.io/part-of: {{ $.Chart.Name }}
{{- include "temporal.resourceLabels" (list $ $service "") | nindent 4 }}
spec:
replicas: {{ default $.Values.server.replicaCount $serviceValues.replicaCount }}
selector:
Expand All @@ -23,16 +17,7 @@ spec:
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "temporal.name" $ }}
helm.sh/chart: {{ include "temporal.chart" $ }}
app.kubernetes.io/managed-by: {{ $.Release.Service }}
app.kubernetes.io/instance: {{ $.Release.Name }}
app.kubernetes.io/version: {{ $.Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: {{ $service }}
app.kubernetes.io/part-of: {{ $.Chart.Name }}
{{- with (default $.Values.server.podLabels $serviceValues.podLabels) }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- include "temporal.resourceLabels" (list $ $service "pod") | nindent 8 }}
annotations:
checksum/config: {{ include (print $.Template.BasePath "/server-configmap.yaml") $ | sha256sum }}
{{- if (default $.Values.server.metrics.annotations.enabled $serviceValues.metrics.annotations.enabled) }}
Expand Down
7 changes: 1 addition & 6 deletions charts/temporal/templates/server-dynamicconfigmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ kind: ConfigMap
metadata:
name: "{{ include "temporal.fullname" . }}-dynamic-config"
labels:
app.kubernetes.io/name: {{ include "temporal.name" . }}
helm.sh/chart: {{ include "temporal.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/part-of: {{ .Chart.Name }}
{{- include "temporal.resourceLabels" (list . "" "") | nindent 4 }}
data:
dynamic_config.yaml: |-
{{- if $.Values.server.dynamicConfig }}
Expand Down
17 changes: 3 additions & 14 deletions charts/temporal/templates/server-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,15 @@ kind: Job
metadata:
name: {{ include "temporal.componentname" (list . "schema") }}
labels:
app.kubernetes.io/name: {{ include "temporal.name" . }}
helm.sh/chart: {{ include "temporal.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: database
app.kubernetes.io/part-of: {{ .Chart.Name }}
{{- include "temporal.resourceLabels" (list . "database" "") | nindent 4 }}
spec:
backoffLimit: {{ $.Values.schema.setup.backoffLimit }}
template:
metadata:
name: {{ include "temporal.componentname" (list . "schema") }}
labels:
app.kubernetes.io/name: {{ include "temporal.name" . }}
helm.sh/chart: {{ include "temporal.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: database
app.kubernetes.io/part-of: {{ .Chart.Name }}
# Currently there are no labels for job type
{{- include "temporal.resourceLabels" (list . "database" "") | nindent 8 }}
spec:
{{ include "temporal.serviceAccount" . }}
restartPolicy: OnFailure
Expand Down
8 changes: 1 addition & 7 deletions charts/temporal/templates/server-pdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ kind: PodDisruptionBudget
metadata:
name: {{ include "temporal.componentname" (list $ $service) }}-pdb
labels:
app.kubernetes.io/name: {{ include "temporal.name" $ }}
helm.sh/chart: {{ include "temporal.chart" $ }}
app.kubernetes.io/managed-by: {{ $.Release.Service }}
app.kubernetes.io/instance: {{ $.Release.Name }}
app.kubernetes.io/version: {{ $.Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: {{ $service }}
app.kubernetes.io/part-of: {{ $.Chart.Name }}
{{- include "temporal.resourceLabels" (list . $service "") | nindent 4 }}
spec:
{{ toYaml $serviceValues.podDisruptionBudget }}
selector:
Expand Down
10 changes: 1 addition & 9 deletions charts/temporal/templates/server-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@ kind: Secret
metadata:
name: {{ $secretName }}
labels:
app.kubernetes.io/name: {{ include "temporal.name" $ }}
helm.sh/chart: {{ include "temporal.chart" $ }}
app.kubernetes.io/managed-by: {{ $.Release.Service }}
app.kubernetes.io/instance: {{ $.Release.Name }}
app.kubernetes.io/version: {{ $.Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/part-of: {{ $.Chart.Name }}
{{- with $.Values.server.secretLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- include "temporal.resourceLabels" (list $ "" "secret") | nindent 4 }}
{{- with $.Values.server.secretAnnotations }}
annotations:
{{- toYaml . | nindent 4 }}
Expand Down
8 changes: 1 addition & 7 deletions charts/temporal/templates/server-service-monitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ kind: ServiceMonitor
metadata:
name: {{ include "temporal.componentname" (list $ $service) }}
labels:
app.kubernetes.io/name: {{ include "temporal.name" $ }}
helm.sh/chart: {{ include "temporal.chart" $ }}
app.kubernetes.io/managed-by: {{ $.Release.Service }}
app.kubernetes.io/instance: {{ $.Release.Name }}
app.kubernetes.io/version: {{ $.Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: {{ $service }}
app.kubernetes.io/part-of: {{ $.Chart.Name }}
{{- include "temporal.resourceLabels" (list $ $service "") | nindent 4 }}
{{- with (default $.Values.server.metrics.serviceMonitor.additionalLabels $serviceValues.metrics.serviceMonitor.additionalLabels) }}
{{- toYaml . | nindent 4 }}
{{- end }}
Expand Down
16 changes: 2 additions & 14 deletions charts/temporal/templates/server-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ kind: Service
metadata:
name: {{ include "temporal.componentname" (list . "frontend") }}
labels:
app.kubernetes.io/name: {{ include "temporal.name" . }}
helm.sh/chart: {{ include "temporal.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: frontend
app.kubernetes.io/part-of: {{ .Chart.Name }}
{{- include "temporal.resourceLabels" (list $ "frontend" "") | nindent 4 }}
{{- if .Values.server.frontend.service.annotations }}
annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.server.frontend.service.annotations "context" $) | nindent 4 }}
{{- end }}
Expand Down Expand Up @@ -42,13 +36,7 @@ kind: Service
metadata:
name: {{ include "temporal.componentname" (list $ (printf "%s-headless" $service)) }}
labels:
app.kubernetes.io/name: {{ include "temporal.name" $ }}
helm.sh/chart: {{ include "temporal.chart" $ }}
app.kubernetes.io/managed-by: {{ $.Release.Service }}
app.kubernetes.io/instance: {{ $.Release.Name }}
app.kubernetes.io/version: {{ $.Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: {{ $service }}
app.kubernetes.io/part-of: {{ $.Chart.Name }}
{{- include "temporal.resourceLabels" (list $ $service "") | nindent 4 }}
app.kubernetes.io/headless: 'true'
prometheus.io/job: {{ $.Chart.Name }}-{{ $service }}
prometheus.io/scrape: 'true'
Expand Down
7 changes: 1 addition & 6 deletions charts/temporal/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ kind: ServiceAccount
metadata:
name: {{ include "temporal.serviceAccountName" . }}
labels:
app.kubernetes.io/name: {{ include "temporal.name" . }}
helm.sh/chart: {{ include "temporal.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/part-of: {{ .Chart.Name }}
{{- include "temporal.resourceLabels" (list . "" "") | nindent 4 }}
annotations:
helm.sh/hook: pre-install, pre-upgrade
helm.sh/hook-weight: "-10"
Expand Down
8 changes: 1 addition & 7 deletions charts/temporal/templates/tests/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ kind: Pod
metadata:
name: "{{ include "temporal.fullname" . }}-test-wfl"
labels:
app.kubernetes.io/name: {{ include "temporal.name" . }}
helm.sh/chart: {{ include "temporal.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: test
app.kubernetes.io/part-of: {{ .Chart.Name }}
{{- include "temporal.resourceLabels" (list $ "test" "") | nindent 4 }}
annotations:
"helm.sh/hook": test
spec:
Expand Down
19 changes: 2 additions & 17 deletions charts/temporal/templates/web-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ kind: Deployment
metadata:
name: {{ include "temporal.componentname" (list . "web") }}
labels:
app.kubernetes.io/name: {{ include "temporal.name" . }}
helm.sh/chart: {{ include "temporal.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: web
app.kubernetes.io/part-of: {{ .Chart.Name }}
{{- include "temporal.resourceLabels" (list . "web" "") | nindent 4 }}
spec:
replicas: {{ .Values.web.replicaCount }}
selector:
Expand All @@ -21,16 +15,7 @@ spec:
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "temporal.name" . }}
helm.sh/chart: {{ include "temporal.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: web
app.kubernetes.io/part-of: {{ .Chart.Name }}
{{- with .Values.web.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- include "temporal.resourceLabels" (list $ "web" "pod") | nindent 8 }}
{{- with .Values.web.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
Expand Down
8 changes: 1 addition & 7 deletions charts/temporal/templates/web-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@ kind: Ingress
metadata:
name: {{ include "temporal.componentname" (list . "web") }}
labels:
app.kubernetes.io/name: {{ include "temporal.name" . }}
helm.sh/chart: {{ include "temporal.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: web
app.kubernetes.io/part-of: {{ .Chart.Name }}
{{- include "temporal.resourceLabels" (list . "web" "") | nindent 4 }}
{{- with .Values.web.ingress.annotations }}
annotations:
{{ toYaml . | indent 4 }}
Expand Down
8 changes: 1 addition & 7 deletions charts/temporal/templates/web-pdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ kind: PodDisruptionBudget
metadata:
name: {{ include "temporal.componentname" (list . "web") }}-pdb
labels:
app.kubernetes.io/name: {{ include "temporal.name" $ }}
helm.sh/chart: {{ include "temporal.chart" $ }}
app.kubernetes.io/managed-by: {{ $.Release.Service }}
app.kubernetes.io/instance: {{ $.Release.Name }}
app.kubernetes.io/version: {{ $.Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: web
app.kubernetes.io/part-of: {{ $.Chart.Name }}
{{- include "temporal.resourceLabels" (list . "web" "") | nindent 4 }}
spec:
{{ toYaml $.Values.web.podDisruptionBudget }}
selector:
Expand Down
8 changes: 1 addition & 7 deletions charts/temporal/templates/web-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ kind: Service
metadata:
name: {{ include "temporal.componentname" (list . "web") }}
labels:
app.kubernetes.io/name: {{ include "temporal.name" . }}
helm.sh/chart: {{ include "temporal.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: web
app.kubernetes.io/part-of: {{ .Chart.Name }}
{{- include "temporal.resourceLabels" (list . "web" "") | nindent 4 }}
{{- if .Values.web.service.annotations }}
annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.web.service.annotations "context" $) | nindent 4 }}
{{- end }}
Expand Down
Loading
Loading