From 8934ecae3d06dd4b29f9c7ba81e93ad5397fe1a8 Mon Sep 17 00:00:00 2001 From: Ryan McAfee Date: Tue, 14 Feb 2023 07:32:06 -0600 Subject: [PATCH] [prometheus-kube-stack] Fixes deployment of Thanos Ruler - Addresses Default Thanos Ruler name too long (#3021) * Updated thanos ruler name to use the shortened helm chart name + thanos-rule suffix to ensure that the thanos ruler name is always under the required 63 characters for resource names. Added support for overriding the value directly from the values file for the thanos ruler name. Signed-off-by: Ryan McAfee * Bump kube-prometheus-stack helm chart version to 45.0.1 Signed-off-by: Ryan McAfee --------- Signed-off-by: Ryan McAfee --- charts/kube-prometheus-stack/Chart.yaml | 2 +- charts/kube-prometheus-stack/templates/_helpers.tpl | 8 +++++++- .../templates/thanos-ruler/extrasecret.yaml | 4 ++-- .../templates/thanos-ruler/ingress.yaml | 4 ++-- .../templates/thanos-ruler/podDisruptionBudget.yaml | 6 +++--- .../templates/thanos-ruler/ruler.yaml | 12 ++++++------ .../templates/thanos-ruler/service.yaml | 8 ++++---- .../templates/thanos-ruler/serviceaccount.yaml | 6 +++--- .../templates/thanos-ruler/servicemonitor.yaml | 6 +++--- 9 files changed, 31 insertions(+), 25 deletions(-) diff --git a/charts/kube-prometheus-stack/Chart.yaml b/charts/kube-prometheus-stack/Chart.yaml index 0048287657a3..9928c50851fd 100644 --- a/charts/kube-prometheus-stack/Chart.yaml +++ b/charts/kube-prometheus-stack/Chart.yaml @@ -21,7 +21,7 @@ name: kube-prometheus-stack sources: - https://github.com/prometheus-community/helm-charts - https://github.com/prometheus-operator/kube-prometheus -version: 45.0.0 +version: 45.0.1 appVersion: v0.63.0 kubeVersion: ">=1.16.0-0" home: https://github.com/prometheus-operator/kube-prometheus diff --git a/charts/kube-prometheus-stack/templates/_helpers.tpl b/charts/kube-prometheus-stack/templates/_helpers.tpl index 242a2bbe042e..9e3e4d6779e3 100644 --- a/charts/kube-prometheus-stack/templates/_helpers.tpl +++ b/charts/kube-prometheus-stack/templates/_helpers.tpl @@ -57,6 +57,12 @@ The longest name that gets created adds and extra 37 characters, so truncation s {{- printf "%s-thanos-ruler" (include "kube-prometheus-stack.fullname" .) -}} {{- end }} +{{/* Shortened name suffixed with thanos-ruler */}} +{{- define "kube-prometheus-stack.thanosRuler.name" -}} +{{- default (printf "%s-thanos-ruler" (include "kube-prometheus-stack.name" .)) .Values.thanosRuler.name -}} +{{- end }} + + {{/* Create chart name and version as used by the chart label. */}} {{- define "kube-prometheus-stack.chartref" -}} {{- replace "+" "_" .Chart.Version | printf "%s-%s" .Chart.Name -}} @@ -106,7 +112,7 @@ heritage: {{ $.Release.Service | quote }} {{/* Create the name of thanosRuler service account to use */}} {{- define "kube-prometheus-stack.thanosRuler.serviceAccountName" -}} {{- if .Values.thanosRuler.serviceAccount.create -}} - {{ default (include "kube-prometheus-stack.thanosRuler.fullname" .) .Values.thanosRuler.serviceAccount.name }} + {{ default (include "kube-prometheus-stack.thanosRuler.name" .) .Values.thanosRuler.serviceAccount.name }} {{- else -}} {{ default "default" .Values.thanosRuler.serviceAccount.name }} {{- end -}} diff --git a/charts/kube-prometheus-stack/templates/thanos-ruler/extrasecret.yaml b/charts/kube-prometheus-stack/templates/thanos-ruler/extrasecret.yaml index fe2ea5be6d54..587fca2dca7c 100644 --- a/charts/kube-prometheus-stack/templates/thanos-ruler/extrasecret.yaml +++ b/charts/kube-prometheus-stack/templates/thanos-ruler/extrasecret.yaml @@ -1,5 +1,5 @@ {{- if .Values.thanosRuler.extraSecret.data -}} -{{- $secretName := printf "thanos-ruler-%s-extra" (include "kube-prometheus-stack.fullname" . ) -}} +{{- $secretName := printf "%s-extra" (include "kube-prometheus-stack.thanosRuler.name" . ) -}} apiVersion: v1 kind: Secret metadata: @@ -10,7 +10,7 @@ metadata: {{ toYaml .Values.thanosRuler.extraSecret.annotations | indent 4 }} {{- end }} labels: - app: {{ template "kube-prometheus-stack.name" . }}-thanos-ruler + app: {{ template "kube-prometheus-stack.thanosRuler.name" . }} app.kubernetes.io/component: thanos-ruler {{ include "kube-prometheus-stack.labels" . | indent 4 }} data: diff --git a/charts/kube-prometheus-stack/templates/thanos-ruler/ingress.yaml b/charts/kube-prometheus-stack/templates/thanos-ruler/ingress.yaml index 2760805c53ea..aed9db280f53 100644 --- a/charts/kube-prometheus-stack/templates/thanos-ruler/ingress.yaml +++ b/charts/kube-prometheus-stack/templates/thanos-ruler/ingress.yaml @@ -1,6 +1,6 @@ {{- if and .Values.thanosRuler.enabled .Values.thanosRuler.ingress.enabled }} {{- $pathType := .Values.thanosRuler.ingress.pathType | default "ImplementationSpecific" }} -{{- $serviceName := printf "%s-%s" (include "kube-prometheus-stack.fullname" .) "thanos-ruler" }} +{{- $serviceName := include "kube-prometheus-stack.thanosRuler.name" . }} {{- $servicePort := .Values.thanosRuler.service.port -}} {{- $routePrefix := list .Values.thanosRuler.thanosRulerSpec.routePrefix }} {{- $paths := .Values.thanosRuler.ingress.paths | default $routePrefix -}} @@ -16,7 +16,7 @@ metadata: {{ toYaml .Values.thanosRuler.ingress.annotations | indent 4 }} {{- end }} labels: - app: {{ template "kube-prometheus-stack.name" . }}-thanos-ruler + app: {{ template "kube-prometheus-stack.thanosRuler.name" . }} {{- if .Values.thanosRuler.ingress.labels }} {{ toYaml .Values.thanosRuler.ingress.labels | indent 4 }} {{- end }} diff --git a/charts/kube-prometheus-stack/templates/thanos-ruler/podDisruptionBudget.yaml b/charts/kube-prometheus-stack/templates/thanos-ruler/podDisruptionBudget.yaml index d3d378d693b6..83e54edf9b51 100644 --- a/charts/kube-prometheus-stack/templates/thanos-ruler/podDisruptionBudget.yaml +++ b/charts/kube-prometheus-stack/templates/thanos-ruler/podDisruptionBudget.yaml @@ -2,10 +2,10 @@ apiVersion: {{ include "kube-prometheus-stack.pdb.apiVersion" . }} kind: PodDisruptionBudget metadata: - name: {{ template "kube-prometheus-stack.fullname" . }}-thanos-ruler + name: {{ template "kube-prometheus-stack.thanosRuler.name" . }} namespace: {{ template "kube-prometheus-stack.namespace" . }} labels: - app: {{ template "kube-prometheus-stack.name" . }}-thanos-ruler + app: {{ template "kube-prometheus-stack.thanosRuler.name" . }} {{ include "kube-prometheus-stack.labels" . | indent 4 }} spec: {{- if .Values.thanosRuler.podDisruptionBudget.minAvailable }} @@ -17,5 +17,5 @@ spec: selector: matchLabels: app.kubernetes.io/name: thanos-ruler - thanos-ruler: {{ template "kube-prometheus-stack.fullname" . }}-thanos-ruler + thanos-ruler: {{ template "kube-prometheus-stack.thanosRuler.name" . }} {{- end }} diff --git a/charts/kube-prometheus-stack/templates/thanos-ruler/ruler.yaml b/charts/kube-prometheus-stack/templates/thanos-ruler/ruler.yaml index ebca08c4584e..cf678b5448ad 100644 --- a/charts/kube-prometheus-stack/templates/thanos-ruler/ruler.yaml +++ b/charts/kube-prometheus-stack/templates/thanos-ruler/ruler.yaml @@ -2,11 +2,11 @@ apiVersion: monitoring.coreos.com/v1 kind: ThanosRuler metadata: - name: {{ template "kube-prometheus-stack.fullname" . }}-thanos-ruler + name: {{ template "kube-prometheus-stack.thanosRuler.name" . }} namespace: {{ template "kube-prometheus-stack.namespace" . }} labels: - app: {{ template "kube-prometheus-stack.name" . }}-thanos-ruler -{{ include "kube-prometheus-stack.labels" . | indent 4 }} + app: {{ include "kube-prometheus-stack.thanosRuler.name" . }} +{{- include "kube-prometheus-stack.labels" . | indent 4 -}} {{- if .Values.thanosRuler.annotations }} annotations: {{ toYaml .Values.thanosRuler.annotations | indent 4 }} @@ -35,7 +35,7 @@ spec: {{- else if and .Values.thanosRuler.ingress.enabled .Values.thanosRuler.ingress.hosts }} externalPrefix: "http://{{ tpl (index .Values.thanosRuler.ingress.hosts 0) . }}{{ .Values.thanosRuler.thanosRulerSpec.routePrefix }}" {{- else }} - externalPrefix: http://{{ template "kube-prometheus-stack.fullname" . }}-thanosRuler.{{ template "kube-prometheus-stack.namespace" . }}:{{ .Values.thanosRuler.service.port }} + externalPrefix: http://{{ template "kube-prometheus-stack.thanosRuler.name" . }}.{{ template "kube-prometheus-stack.namespace" . }}:{{ .Values.thanosRuler.service.port }} {{- end }} {{- if .Values.thanosRuler.thanosRulerSpec.nodeSelector }} nodeSelector: @@ -126,7 +126,7 @@ spec: labelSelector: matchExpressions: - {key: app.kubernetes.io/name, operator: In, values: [thanos-ruler]} - - {key: thanos-ruler, operator: In, values: [{{ template "kube-prometheus-stack.fullname" . }}-thanos-ruler]} + - {key: thanos-ruler, operator: In, values: [{{ template "kube-prometheus-stack.thanosRuler.name" . }}]} {{- else if eq .Values.thanosRuler.thanosRulerSpec.podAntiAffinity "soft" }} podAntiAffinity: preferredDuringSchedulingIgnoredDuringExecution: @@ -136,7 +136,7 @@ spec: labelSelector: matchExpressions: - {key: app.kubernetes.io/name, operator: In, values: [thanos-ruler]} - - {key: thanos-ruler, operator: In, values: [{{ template "kube-prometheus-stack.fullname" . }}-thanos-ruler]} + - {key: thanos-ruler, operator: In, values: [{{ template "kube-prometheus-stack.thanosRuler.name" . }}]} {{- end }} {{- if .Values.thanosRuler.thanosRulerSpec.tolerations }} tolerations: diff --git a/charts/kube-prometheus-stack/templates/thanos-ruler/service.yaml b/charts/kube-prometheus-stack/templates/thanos-ruler/service.yaml index 093dbf7cd4bf..be0c8445910d 100644 --- a/charts/kube-prometheus-stack/templates/thanos-ruler/service.yaml +++ b/charts/kube-prometheus-stack/templates/thanos-ruler/service.yaml @@ -2,12 +2,12 @@ apiVersion: v1 kind: Service metadata: - name: {{ template "kube-prometheus-stack.fullname" . }}-thanos-ruler + name: {{ template "kube-prometheus-stack.thanosRuler.name" . }} namespace: {{ template "kube-prometheus-stack.namespace" . }} labels: - app: {{ template "kube-prometheus-stack.name" . }}-thanos-ruler + app: {{ template "kube-prometheus-stack.thanosRuler.name" . }} self-monitor: {{ .Values.thanosRuler.serviceMonitor.selfMonitor | quote }} -{{ include "kube-prometheus-stack.labels" . | indent 4 }} +{{- include "kube-prometheus-stack.labels" . | indent 4 -}} {{- if .Values.thanosRuler.service.labels }} {{ toYaml .Values.thanosRuler.service.labels | indent 4 }} {{- end }} @@ -48,6 +48,6 @@ spec: {{- end }} selector: app.kubernetes.io/name: thanos-ruler - thanos-ruler: {{ template "kube-prometheus-stack.fullname" . }}-thanos-ruler + thanos-ruler: {{ template "kube-prometheus-stack.thanosRuler.name" . }} type: "{{ .Values.thanosRuler.service.type }}" {{- end }} diff --git a/charts/kube-prometheus-stack/templates/thanos-ruler/serviceaccount.yaml b/charts/kube-prometheus-stack/templates/thanos-ruler/serviceaccount.yaml index 0138c357f533..b58f1cd4df5f 100644 --- a/charts/kube-prometheus-stack/templates/thanos-ruler/serviceaccount.yaml +++ b/charts/kube-prometheus-stack/templates/thanos-ruler/serviceaccount.yaml @@ -5,10 +5,10 @@ metadata: name: {{ template "kube-prometheus-stack.thanosRuler.serviceAccountName" . }} namespace: {{ template "kube-prometheus-stack.namespace" . }} labels: - app: {{ template "kube-prometheus-stack.name" . }}-thanos-ruler - app.kubernetes.io/name: {{ template "kube-prometheus-stack.name" . }}-thanos-ruler + app: {{ template "kube-prometheus-stack.thanosRuler.name" . }} + app.kubernetes.io/name: {{ template "kube-prometheus-stack.thanosRuler.name" . }} app.kubernetes.io/component: thanos-ruler -{{ include "kube-prometheus-stack.labels" . | indent 4 }} +{{- include "kube-prometheus-stack.labels" . | indent 4 -}} {{- if .Values.thanosRuler.serviceAccount.annotations }} annotations: {{ toYaml .Values.thanosRuler.serviceAccount.annotations | indent 4 }} diff --git a/charts/kube-prometheus-stack/templates/thanos-ruler/servicemonitor.yaml b/charts/kube-prometheus-stack/templates/thanos-ruler/servicemonitor.yaml index 7fead06c7e75..67dea7d1e67a 100644 --- a/charts/kube-prometheus-stack/templates/thanos-ruler/servicemonitor.yaml +++ b/charts/kube-prometheus-stack/templates/thanos-ruler/servicemonitor.yaml @@ -2,16 +2,16 @@ apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: - name: {{ template "kube-prometheus-stack.fullname" . }}-thanos-ruler + name: {{ template "kube-prometheus-stack.thanosRuler.name" . }} namespace: {{ template "kube-prometheus-stack.namespace" . }} labels: - app: {{ template "kube-prometheus-stack.name" . }}-thanos-ruler + app: {{ template "kube-prometheus-stack.thanosRuler.name" . }} {{ include "kube-prometheus-stack.labels" . | indent 4 }} spec: {{- include "servicemonitor.scrapeLimits" .Values.thanosRuler.serviceMonitor | nindent 2 }} selector: matchLabels: - app: {{ template "kube-prometheus-stack.name" . }}-thanos-ruler + app: {{ template "kube-prometheus-stack.thanosRuler.name" . }} release: {{ $.Release.Name | quote }} self-monitor: {{ .Values.thanosRuler.serviceMonitor.selfMonitor | quote }} namespaceSelector: