Skip to content

Commit

Permalink
[alertmanager] support to auto set replicas by node num
Browse files Browse the repository at this point in the history
Signed-off-by: junot <[email protected]>
  • Loading branch information
junotx committed Apr 2, 2024
1 parent 2f5a122 commit b29d6d0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion charts/alertmanager/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ icon: https://raw.githubusercontent.com/prometheus/prometheus.github.io/master/a
sources:
- https://github.com/prometheus/alertmanager
type: application
version: 1.8.3
version: 1.8.4
appVersion: v0.26.0
kubeVersion: ">=1.19.0-0"
keywords:
Expand Down
19 changes: 19 additions & 0 deletions charts/alertmanager/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,22 @@ labelNameLengthLimit: {{ . }}
labelValueLengthLimit: {{ . }}
{{- end }}
{{- end }}

{{- define "alertmanager.replicas" -}}
{{- $replicas := 0 -}}
{{ if .Values.replicaAutoSet }}
{{- $nodeList := lookup "v1" "Node" "" "" -}}
{{- if $nodeList }}
{{- if lt (len $nodeList.items) 3 -}}
{{- $replicas = 1 -}}
{{- else -}}
{{- $replicas = 3 -}}
{{- end -}}
{{- else }}
{{- $replicas = .Values.replicaCount -}}
{{- end -}}
{{- else -}}
{{- $replicas = .Values.replicaCount -}}
{{- end -}}
{{- $replicas -}}
{{- end -}}
2 changes: 1 addition & 1 deletion charts/alertmanager/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ metadata:
{{- end }}
namespace: {{ include "alertmanager.namespace" . }}
spec:
replicas: {{ .Values.replicaCount }}
replicas: {{ include "alertmanager.replicas" . }}
minReadySeconds: {{ .Values.minReadySeconds }}
revisionHistoryLimit: {{ .Values.revisionHistoryLimit }}
selector:
Expand Down
3 changes: 3 additions & 0 deletions charts/alertmanager/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,9 @@
},
"type": "object"
},
"replicaAutoSet": {
"type": "boolean"
},
"replicaCount": {
"type": "integer"
},
Expand Down
5 changes: 5 additions & 0 deletions charts/alertmanager/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
global:
imagePullSecrets: []

# The alertmanager replica count.
# If you want to control it by yourself, please firstly configure the replicaAutoSet item as false.
replicaCount: 1
# If true, will ignore the upper replicaCount iterm and auto set alertmanager replica count by the node num:
# set the alertmanager replica count as 1 when the node num < 3, or set as 3.
replicaAutoSet: true

# Number of old history to retain to allow rollback
# Default Kubernetes value is set to 10
Expand Down

0 comments on commit b29d6d0

Please sign in to comment.