Skip to content

Commit

Permalink
Alertmanager and Prometheus names templated
Browse files Browse the repository at this point in the history
Signed-off-by: Sergei Kuzmin <sergeikuzmin@gmail.com>
  • Loading branch information
ksa-real committed May 4, 2022
1 parent 0283faa commit e088e62
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 17 deletions.
2 changes: 1 addition & 1 deletion charts/kube-prometheus-stack/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ name: kube-prometheus-stack
sources:
- https://github.com/prometheus-community/helm-charts
- https://github.com/prometheus-operator/kube-prometheus
version: 35.0.3
version: 35.0.4
appVersion: 0.56.0
kubeVersion: ">=1.16.0-0"
home: https://github.com/prometheus-operator/kube-prometheus
Expand Down
18 changes: 18 additions & 0 deletions charts/kube-prometheus-stack/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,29 @@ The longest name that gets created adds and extra 37 characters, so truncation s
{{- printf "%s-prometheus" (include "kube-prometheus-stack.fullname" .) -}}
{{- end }}

{{/* Prometheus custom resource instance name */}}
{{- define "kube-prometheus-stack.prometheus.crname" -}}
{{- if .Values.cleanPrometheusOperatorObjectNames }}
{{- include "kube-prometheus-stack.fullname" . }}
{{- else }}
{{- printf "%s-prometheus" (include "kube-prometheus-stack.fullname" .) }}
{{- end }}
{{- end }}

{{/* Fullname suffixed with alertmanager */}}
{{- define "kube-prometheus-stack.alertmanager.fullname" -}}
{{- printf "%s-alertmanager" (include "kube-prometheus-stack.fullname" .) -}}
{{- end }}

{{/* Alertmanager custom resource instance name */}}
{{- define "kube-prometheus-stack.alertmanager.crname" -}}
{{- if .Values.cleanPrometheusOperatorObjectNames }}
{{- include "kube-prometheus-stack.fullname" . }}
{{- else }}
{{- printf "%s-alertmanager" (include "kube-prometheus-stack.fullname" .) -}}
{{- end }}
{{- 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 -}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apiVersion: monitoring.coreos.com/v1
kind: Alertmanager
metadata:
name: {{ template "kube-prometheus-stack.fullname" . }}
name: {{ template "kube-prometheus-stack.alertmanager.crname" . }}
namespace: {{ template "kube-prometheus-stack.namespace" . }}
labels:
app: {{ template "kube-prometheus-stack.name" . }}-alertmanager
Expand Down Expand Up @@ -104,7 +104,7 @@ spec:
labelSelector:
matchExpressions:
- {key: app.kubernetes.io/name, operator: In, values: [alertmanager]}
- {key: alertmanager, operator: In, values: [{{ template "kube-prometheus-stack.fullname" . }}]}
- {key: alertmanager, operator: In, values: [{{ template "kube-prometheus-stack.alertmanager.crname" . }}]}
{{- else if eq .Values.alertmanager.alertmanagerSpec.podAntiAffinity "soft" }}
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
Expand All @@ -114,7 +114,7 @@ spec:
labelSelector:
matchExpressions:
- {key: app.kubernetes.io/name, operator: In, values: [alertmanager]}
- {key: alertmanager, operator: In, values: [{{ template "kube-prometheus-stack.fullname" . }}]}
- {key: alertmanager, operator: In, values: [{{ template "kube-prometheus-stack.alertmanager.crname" . }}]}
{{- end }}
{{- if .Values.alertmanager.alertmanagerSpec.tolerations }}
tolerations:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ spec:
selector:
matchLabels:
app.kubernetes.io/name: alertmanager
alertmanager: {{ template "kube-prometheus-stack.fullname" . }}
alertmanager: {{ template "kube-prometheus-stack.alertmanager.crname" . }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apiVersion: v1
kind: Secret
metadata:
name: alertmanager-{{ template "kube-prometheus-stack.fullname" . }}
name: alertmanager-{{ template "kube-prometheus-stack.alertmanager.crname" . }}
namespace: {{ template "kube-prometheus-stack.namespace" . }}
{{- if .Values.alertmanager.secret.annotations }}
annotations:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ spec:
{{- end }}
selector:
app.kubernetes.io/name: alertmanager
alertmanager: {{ template "kube-prometheus-stack.fullname" . }}
alertmanager: {{ template "kube-prometheus-stack.alertmanager.crname" . }}
type: "{{ .Values.alertmanager.service.type }}"
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ items:
targetPort: {{ $serviceValues.targetPort }}
selector:
app.kubernetes.io/name: alertmanager
alertmanager: {{ template "kube-prometheus-stack.fullname" $ }}
statefulset.kubernetes.io/pod-name: alertmanager-{{ include "kube-prometheus-stack.fullname" $ }}-{{ $i }}
alertmanager: {{ template "kube-prometheus-stack.alertmanager.crname" $ }}
statefulset.kubernetes.io/pod-name: alertmanager-{{ include "kube-prometheus-stack.alertmanager.crname" $ }}-{{ $i }}
type: "{{ $serviceValues.type }}"
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ data:
- name: Prometheus-{{ . }}
type: prometheus
uid: {{ .Values.grafana.sidecar.datasources.uid }}-replica-{{ . }}
url: http://prometheus-{{ template "kube-prometheus-stack.fullname" $ }}-{{ . }}.prometheus-operated:9090/{{ trimPrefix "/" $.Values.prometheus.prometheusSpec.routePrefix }}
url: http://prometheus-{{ template "kube-prometheus-stack.prometheus.crname" $ }}-{{ . }}.prometheus-operated:9090/{{ trimPrefix "/" $.Values.prometheus.prometheusSpec.routePrefix }}
access: proxy
isDefault: false
jsonData:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ spec:
selector:
matchLabels:
app.kubernetes.io/name: prometheus
prometheus: {{ template "kube-prometheus-stack.fullname" . }}
prometheus: {{ template "kube-prometheus-stack.prometheus.crname" . }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
name: {{ template "kube-prometheus-stack.fullname" . }}
name: {{ template "kube-prometheus-stack.prometheus.crname" . }}
namespace: {{ template "kube-prometheus-stack.namespace" . }}
labels:
app: {{ template "kube-prometheus-stack.name" . }}-prometheus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ spec:
publishNotReadyAddresses: {{ .Values.prometheus.service.publishNotReadyAddresses }}
selector:
app.kubernetes.io/name: prometheus
prometheus: {{ template "kube-prometheus-stack.fullname" . }}
prometheus: {{ template "kube-prometheus-stack.prometheus.crname" . }}
{{- if .Values.prometheus.service.sessionAffinity }}
sessionAffinity: {{ .Values.prometheus.service.sessionAffinity }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ spec:
{{- end }}
selector:
app.kubernetes.io/name: prometheus
prometheus: {{ template "kube-prometheus-stack.fullname" . }}
prometheus: {{ template "kube-prometheus-stack.prometheus.crname" . }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ spec:
{{- end }}
selector:
app.kubernetes.io/name: prometheus
prometheus: {{ template "kube-prometheus-stack.fullname" . }}
prometheus: {{ template "kube-prometheus-stack.prometheus.crname" . }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ items:
targetPort: {{ $serviceValues.targetPort }}
selector:
app.kubernetes.io/name: prometheus
prometheus: {{ include "kube-prometheus-stack.fullname" $ }}
statefulset.kubernetes.io/pod-name: prometheus-{{ include "kube-prometheus-stack.fullname" $ }}-{{ $i }}
prometheus: {{ include "kube-prometheus-stack.prometheus.crname" $ }}
statefulset.kubernetes.io/pod-name: prometheus-{{ include "kube-prometheus-stack.prometheus.crname" $ }}-{{ $i }}
type: "{{ $serviceValues.type }}"
{{- end }}
{{- end }}
4 changes: 4 additions & 0 deletions charts/kube-prometheus-stack/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2813,3 +2813,7 @@ prometheus:
## https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#podmetricsendpoint
##
# podMetricsEndpoints: []

## Setting to true produces cleaner names, but may require a data migration because of persistent volume claim name change.
##
cleanPrometheusOperatorObjectNames: false

0 comments on commit e088e62

Please sign in to comment.