Skip to content

Commit 2c14af9

Browse files
zanac1986zanhsieh
andauthored
[alertmanager] Refactor (prometheus-community#2781)
* [alertmanager] Refactor [alertmanager] Refactor Signed-off-by: zanac1986 <[email protected]> * Update charts/alertmanager/README.md Signed-off-by: MH <[email protected]> Signed-off-by: zanac1986 <[email protected]> Signed-off-by: MH <[email protected]> Co-authored-by: MH <[email protected]>
1 parent 11139b5 commit 2c14af9

File tree

8 files changed

+113
-98
lines changed

8 files changed

+113
-98
lines changed

charts/alertmanager/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ icon: https://raw.githubusercontent.com/prometheus/prometheus.github.io/master/a
66
sources:
77
- https://github.com/prometheus/alertmanager
88
type: application
9-
version: 0.22.0
9+
version: 0.22.1
1010
appVersion: v0.24.0
1111
maintainers:
1212
- name: monotek

charts/alertmanager/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ As per [prometheus.io documentation](https://prometheus.io/docs/alerting/latest/
1010

1111
Kubernetes 1.14+
1212

13-
## Get Repo Info
13+
## Get Repository Info
1414

1515
```console
1616
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
1717
helm repo update
1818
```
1919

20-
_See [helm repo](https://helm.sh/docs/helm/helm_repo/) for command documentation._
20+
_See [`helm repo`](https://helm.sh/docs/helm/helm_repo/) for command documentation._
2121

2222
## Install Chart
2323

charts/alertmanager/templates/_helpers.tpl

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,61 +3,85 @@
33
Expand the name of the chart.
44
*/}}
55
{{- define "alertmanager.name" -}}
6-
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
7-
{{- end -}}
6+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
7+
{{- end }}
88

99
{{/*
1010
Create a default fully qualified app name.
1111
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
1212
If release name contains chart name it will be used as a full name.
1313
*/}}
1414
{{- define "alertmanager.fullname" -}}
15-
{{- if .Values.fullnameOverride -}}
16-
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
17-
{{- else -}}
18-
{{- $name := default .Chart.Name .Values.nameOverride -}}
19-
{{- if contains $name .Release.Name -}}
20-
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
21-
{{- else -}}
22-
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
23-
{{- end -}}
24-
{{- end -}}
25-
{{- end -}}
15+
{{- if .Values.fullnameOverride }}
16+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
17+
{{- else }}
18+
{{- $name := default .Chart.Name .Values.nameOverride }}
19+
{{- if contains $name .Release.Name }}
20+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
21+
{{- else }}
22+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
23+
{{- end }}
24+
{{- end }}
25+
{{- end }}
2626

2727
{{/*
2828
Create chart name and version as used by the chart label.
2929
*/}}
3030
{{- define "alertmanager.chart" -}}
31-
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
32-
{{- end -}}
31+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
32+
{{- end }}
3333

3434
{{/*
3535
Common labels
3636
*/}}
3737
{{- define "alertmanager.labels" -}}
3838
helm.sh/chart: {{ include "alertmanager.chart" . }}
3939
{{ include "alertmanager.selectorLabels" . }}
40-
{{- if .Chart.AppVersion }}
41-
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
40+
{{- with .Chart.AppVersion }}
41+
app.kubernetes.io/version: {{ . | quote }}
4242
{{- end }}
4343
app.kubernetes.io/managed-by: {{ .Release.Service }}
44-
{{- end -}}
44+
{{- end }}
4545

4646
{{/*
4747
Selector labels
4848
*/}}
4949
{{- define "alertmanager.selectorLabels" -}}
5050
app.kubernetes.io/name: {{ include "alertmanager.name" . }}
5151
app.kubernetes.io/instance: {{ .Release.Name }}
52-
{{- end -}}
52+
{{- end }}
5353

5454
{{/*
5555
Create the name of the service account to use
5656
*/}}
5757
{{- define "alertmanager.serviceAccountName" -}}
58-
{{- if .Values.serviceAccount.create -}}
59-
{{ default (include "alertmanager.fullname" .) .Values.serviceAccount.name }}
60-
{{- else -}}
61-
{{ default "default" .Values.serviceAccount.name }}
62-
{{- end -}}
63-
{{- end -}}
58+
{{- if .Values.serviceAccount.create }}
59+
{{- default (include "alertmanager.fullname" .) .Values.serviceAccount.name }}
60+
{{- else }}
61+
{{- default "default" .Values.serviceAccount.name }}
62+
{{- end }}
63+
{{- end }}
64+
65+
{{/*
66+
Define Ingress apiVersion
67+
*/}}
68+
{{- define "alertmanager.ingress.apiVersion" -}}
69+
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion }}
70+
{{- printf "networking.k8s.io/v1" }}
71+
{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion }}
72+
{{- printf "networking.k8s.io/v1beta1" }}
73+
{{- else }}
74+
{{- printf "extensions/v1beta1" }}
75+
{{- end }}
76+
{{- end }}
77+
78+
{{/*
79+
Define Pdb apiVersion
80+
*/}}
81+
{{- define "alertmanager.pdb.apiVersion" -}}
82+
{{- if $.Capabilities.APIVersions.Has "policy/v1/PodDisruptionBudget" }}
83+
{{- printf "policy/v1" }}
84+
{{- else }}
85+
{{- printf "policy/v1beta1" }}
86+
{{- end }}
87+
{{- end }}

charts/alertmanager/templates/ingress.yaml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
{{- if .Values.ingress.enabled -}}
2-
{{- $fullName := include "alertmanager.fullname" . -}}
3-
{{- $svcPort := .Values.service.port -}}
1+
{{- if .Values.ingress.enabled }}
2+
{{- $fullName := include "alertmanager.fullname" . }}
3+
{{- $svcPort := .Values.service.port }}
44
{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
5-
{{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
6-
{{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}}
7-
{{- end }}
5+
{{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
6+
{{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}}
87
{{- end }}
9-
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
10-
apiVersion: networking.k8s.io/v1
11-
{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
12-
apiVersion: networking.k8s.io/v1beta1
13-
{{- else -}}
14-
apiVersion: extensions/v1beta1
158
{{- end }}
9+
apiVersion: {{ include "alertmanager.ingress.apiVersion" . }}
1610
kind: Ingress
1711
metadata:
1812
name: {{ $fullName }}
Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
{{- if .Values.podDisruptionBudget -}}
2-
{{ if $.Capabilities.APIVersions.Has "policy/v1/PodDisruptionBudget" -}}
3-
apiVersion: policy/v1
4-
{{- else -}}
5-
apiVersion: policy/v1beta1
6-
{{- end }}
1+
{{- if .Values.podDisruptionBudget }}
2+
apiVersion: {{ include "alertmanager.pdb.apiVersion" . }}
73
kind: PodDisruptionBudget
84
metadata:
9-
name: {{ template "alertmanager.fullname" . }}
5+
name: {{ include "alertmanager.fullname" . }}
106
labels:
117
{{- include "alertmanager.labels" . | nindent 4 }}
128
spec:
139
selector:
1410
matchLabels:
1511
{{- include "alertmanager.selectorLabels" . | nindent 6 }}
16-
{{ toYaml .Values.podDisruptionBudget | indent 2 }}
17-
{{- end -}}
12+
{{- toYaml .Values.podDisruptionBudget | indent 2 }}
13+
{{- end }}

charts/alertmanager/templates/serviceaccount.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if .Values.serviceAccount.create -}}
1+
{{- if .Values.serviceAccount.create }}
22
apiVersion: v1
33
kind: ServiceAccount
44
metadata:
@@ -9,4 +9,4 @@ metadata:
99
annotations:
1010
{{- toYaml . | nindent 4 }}
1111
{{- end }}
12-
{{- end -}}
12+
{{- end }}

charts/alertmanager/templates/services.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ metadata:
44
name: {{ include "alertmanager.fullname" . }}
55
labels:
66
{{- include "alertmanager.labels" . | nindent 4 }}
7-
{{- if .Values.service.annotations }}
7+
{{- with .Values.service.annotations }}
88
annotations:
9-
{{- toYaml .Values.service.annotations | nindent 4 }}
10-
{{- end }}
9+
{{- toYaml . | nindent 4 }}
10+
{{- end }}
1111
spec:
1212
type: {{ .Values.service.type }}
13-
{{- if .Values.service.loadBalancerIP }}
14-
loadBalancerIP: {{ .Values.service.loadBalancerIP }}
15-
{{- end }}
16-
{{- if .Values.service.loadBalancerSourceRanges }}
13+
{{- with .Values.service.loadBalancerIP }}
14+
loadBalancerIP: {{ . }}
15+
{{- end }}
16+
{{- with .Values.service.loadBalancerSourceRanges }}
1717
loadBalancerSourceRanges:
18-
{{- range $cidr := .Values.service.loadBalancerSourceRanges }}
18+
{{- range $cidr := . }}
1919
- {{ $cidr }}
2020
{{- end }}
21-
{{- end }}
21+
{{- end }}
2222
ports:
2323
- port: {{ .Values.service.port }}
2424
targetPort: http

charts/alertmanager/templates/statefulset.yaml

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
{{- $svcClusterPort := .Values.service.clusterPort -}}
1+
{{- $svcClusterPort := .Values.service.clusterPort }}
22
apiVersion: apps/v1
33
kind: StatefulSet
44
metadata:
55
name: {{ include "alertmanager.fullname" . }}
66
labels:
77
{{- include "alertmanager.labels" . | nindent 4 }}
8-
{{- if .Values.statefulSet.annotations }}
8+
{{- with .Values.statefulSet.annotations }}
99
annotations:
10-
{{ toYaml .Values.statefulSet.annotations | nindent 4 }}
11-
{{- end }}
10+
{{- toYaml . | nindent 4 }}
11+
{{- end }}
1212
spec:
1313
replicas: {{ .Values.replicaCount }}
1414
selector:
@@ -19,44 +19,44 @@ spec:
1919
metadata:
2020
labels:
2121
{{- include "alertmanager.selectorLabels" . | nindent 8 }}
22-
{{- if .Values.podLabels }}
23-
{{ toYaml .Values.podLabels | nindent 8 }}
24-
{{- end }}
22+
{{- with .Values.podLabels }}
23+
{{- toYaml . | nindent 8 }}
24+
{{- end }}
2525
annotations:
26-
{{- if not .Values.configmapReload.enabled }}
26+
{{- if not .Values.configmapReload.enabled }}
2727
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
28-
{{- end }}
29-
{{- if .Values.podAnnotations }}
30-
{{- toYaml .Values.podAnnotations | nindent 8 }}
31-
{{- end }}
28+
{{- end }}
29+
{{- with .Values.podAnnotations }}
30+
{{- toYaml . | nindent 8 }}
31+
{{- end }}
3232
spec:
33-
{{- with .Values.imagePullSecrets }}
33+
{{- with .Values.imagePullSecrets }}
3434
imagePullSecrets:
3535
{{- toYaml . | nindent 8 }}
36-
{{- end }}
36+
{{- end }}
3737
serviceAccountName: {{ include "alertmanager.serviceAccountName" . }}
38-
{{- with .Values.dnsConfig }}
38+
{{- with .Values.dnsConfig }}
3939
dnsConfig:
4040
{{- toYaml . | nindent 8 }}
41-
{{- end }}
42-
{{- with .Values.nodeSelector }}
41+
{{- end }}
42+
{{- with .Values.nodeSelector }}
4343
nodeSelector:
4444
{{- toYaml . | nindent 8 }}
4545
{{- end }}
46-
{{- if or .Values.podAntiAffinity .Values.affinity }}
46+
{{- if or .Values.podAntiAffinity .Values.affinity }}
4747
affinity:
48-
{{- end }}
49-
{{- if .Values.affinity }}
50-
{{- toYaml .Values.affinity | nindent 8 }}
51-
{{- end }}
52-
{{- if eq .Values.podAntiAffinity "hard" }}
48+
{{- end }}
49+
{{- with .Values.affinity }}
50+
{{- toYaml . | nindent 8 }}
51+
{{- end }}
52+
{{- if eq .Values.podAntiAffinity "hard" }}
5353
podAntiAffinity:
5454
requiredDuringSchedulingIgnoredDuringExecution:
5555
- topologyKey: {{ .Values.podAntiAffinityTopologyKey }}
5656
labelSelector:
5757
matchExpressions:
5858
- {key: app.kubernetes.io/name, operator: In, values: [{{ include "alertmanager.name" . }}]}
59-
{{- else if eq .Values.podAntiAffinity "soft" }}
59+
{{- else if eq .Values.podAntiAffinity "soft" }}
6060
podAntiAffinity:
6161
preferredDuringSchedulingIgnoredDuringExecution:
6262
- weight: 100
@@ -65,14 +65,15 @@ spec:
6565
labelSelector:
6666
matchExpressions:
6767
- {key: app.kubernetes.io/name, operator: In, values: [{{ include "alertmanager.name" . }}]}
68-
{{- end }}
69-
{{- with .Values.topologySpreadConstraints }}
70-
topologySpreadConstraints: {{- toYaml . | nindent 8 }}
71-
{{- end }}
72-
{{- with .Values.tolerations }}
68+
{{- end }}
69+
{{- with .Values.topologySpreadConstraints }}
70+
topologySpreadConstraints:
71+
{{- toYaml . | nindent 8 }}
72+
{{- end }}
73+
{{- with .Values.tolerations }}
7374
tolerations:
7475
{{- toYaml . | nindent 8 }}
75-
{{- end }}
76+
{{- end }}
7677
securityContext:
7778
{{- toYaml .Values.podSecurityContext | nindent 8 }}
7879
containers:
@@ -85,9 +86,9 @@ spec:
8586
- --webhook-url=http://127.0.0.1:{{ .Values.service.port }}/-/reload
8687
resources:
8788
{{- toYaml .Values.configmapReload.resources | nindent 12 }}
88-
{{- if .Values.configmapReload.containerPort }}
89+
{{- with .Values.configmapReload.containerPort }}
8990
ports:
90-
- containerPort: {{ .Values.configmapReload.containerPort }}
91+
- containerPort: {{ . }}
9192
{{- end }}
9293
volumeMounts:
9394
- name: config
@@ -104,10 +105,10 @@ spec:
104105
fieldRef:
105106
apiVersion: v1
106107
fieldPath: status.podIP
107-
{{- if .Values.command }}
108+
{{- with .Values.command }}
108109
command:
109-
{{- toYaml .Values.command | nindent 12 }}
110-
{{- end }}
110+
{{- toYaml . | nindent 12 }}
111+
{{- end }}
111112
args:
112113
- --storage.path=/alertmanager
113114
- --config.file=/etc/alertmanager/alertmanager.yml
@@ -166,7 +167,7 @@ spec:
166167
optional: {{ . }}
167168
{{- end }}
168169
{{- end }}
169-
{{- if .Values.persistence.enabled }}
170+
{{- if .Values.persistence.enabled }}
170171
volumeClaimTemplates:
171172
- metadata:
172173
name: storage
@@ -183,7 +184,7 @@ spec:
183184
storageClassName: {{ .Values.persistence.storageClass }}
184185
{{- end }}
185186
{{- end }}
186-
{{- else }}
187+
{{- else }}
187188
- name: storage
188189
emptyDir: {}
189-
{{- end -}}
190+
{{- end }}

0 commit comments

Comments
 (0)