Skip to content

Commit c09aea3

Browse files
k8s-stack: added ability to use VMAlertmanagerConfig instead of plain Secret. Fixes #1968
1 parent 3d7ca44 commit c09aea3

File tree

5 files changed

+100
-77
lines changed

5 files changed

+100
-77
lines changed

charts/victoria-metrics-k8s-stack/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Next release
22

3-
- TODO
3+
- Added .Values.alertmanager.useManagedConfig to switch storing Alertmanager config in VMAlertmanagerConfig CR instead of k8s Secret. See [this issue](https://github.com/VictoriaMetrics/helm-charts/issues/1968).
44

55
## 0.35.6
66

charts/victoria-metrics-k8s-stack/README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,6 @@ Change the values according to the need of the environment in ``victoria-metrics
515515
- name: blackhole
516516
route:
517517
receiver: blackhole
518-
templates:
519-
- /etc/vm/configs/**/*.tmpl
520518
</code>
521519
</pre>
522520
</td>
@@ -613,6 +611,17 @@ selectAllByDefault: true
613611
</pre>
614612
</td>
615613
<td><p>Extra alert templates</p>
614+
</td>
615+
</tr>
616+
<tr>
617+
<td>alertmanager.useManagedConfig</td>
618+
<td>bool</td>
619+
<td><pre class="helm-vars-default-value language-yaml" lang="">
620+
<code class="language-yaml">false
621+
</code>
622+
</pre>
623+
</td>
624+
<td><p>enable storing .Values.alertmanager.config in VMAlertmanagerConfig instead of k8s Secret</p>
616625
</td>
617626
</tr>
618627
<tr>

charts/victoria-metrics-k8s-stack/templates/_helpers.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190
{{- $Values := (.helm).Values | default .Values }}
191191
{{- $fullname := include "vm.managed.fullname" . -}}
192192
{{- $spec := $Values.alertmanager.spec -}}
193-
{{- if and (not $Values.alertmanager.spec.configRawYaml) (not $Values.alertmanager.spec.configSecret) -}}
193+
{{- if and (not $spec.configRawYaml) (not $spec.configSecret) (not $Values.alertmanager.useManagedConfig) -}}
194194
{{- $_ := set $spec "configSecret" $fullname -}}
195195
{{- end -}}
196196
{{- $templates := default list -}}

charts/victoria-metrics-k8s-stack/templates/victoria-metrics-operator/alertmanager/vmalertmanager.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,18 @@
55
{{- if and $app.spec.configRawYaml $app.config }}
66
{{- fail "ERROR: Both .Values.alertmanager.spec.configRawYaml and .Values.alertmanager.config are set, but only one is allowed." }}
77
{{- end }}
8+
{{- $fullname := include "vm.cr.fullname" $ctx }}
89
{{- if and (not $app.spec.configSecret) (not $app.spec.configRawYaml) }}
10+
{{- if $app.useManagedConfig }}
11+
---
12+
apiVersion: operator.victoriametrics.com/v1beta1
13+
kind: VMAlertmanagerConfig
14+
metadata:
15+
name: {{ $fullname }}
16+
namespace: {{ $ns }}
17+
labels: {{ include "vm.labels" $ctx | nindent 4 }}
18+
spec: {{ toYaml .Values.alertmanager.config | nindent 2 }}
19+
{{- else }}
920
---
1021
apiVersion: v1
1122
kind: Secret
@@ -15,6 +26,9 @@ metadata:
1526
labels: {{ include "vm.labels" $ctx | nindent 4 }}
1627
stringData:
1728
alertmanager.yaml: |{{ toYaml .Values.alertmanager.config | nindent 4 }}
29+
templates:
30+
- "/etc/vm/configs/**/*.tmpl"
31+
{{- end }}
1832
{{- end }}
1933
---
2034
apiVersion: operator.victoriametrics.com/v1beta1
@@ -23,7 +37,7 @@ metadata:
2337
{{- with .Values.alertmanager.annotations }}
2438
annotations: {{ toYaml . | nindent 4 }}
2539
{{- end }}
26-
name: {{ include "vm.cr.fullname" $ctx }}
40+
name: {{ $fullname }}
2741
namespace: {{ $ns }}
2842
labels: {{ include "vm.labels" $ctx | nindent 4 }}
2943
spec: {{ include "vm.alertmanager.spec" $ctx | nindent 2 }}

charts/victoria-metrics-k8s-stack/values.yaml

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -514,33 +514,33 @@ alertmanager:
514514

515515
# -- (string) If this one defined, it will be used for alertmanager configuration and config parameter will be ignored
516516
configSecret: ""
517+
# -- enable storing .Values.alertmanager.config in VMAlertmanagerConfig instead of k8s Secret
518+
useManagedConfig: false
517519
# -- (object) Alertmanager configuration
518520
config:
519-
templates:
520-
- "/etc/vm/configs/**/*.tmpl"
521521
route:
522-
# group_by: ["alertgroup", "job"]
523-
# group_wait: 30s
524-
# group_interval: 5m
525-
# repeat_interval: 12h
526522
receiver: "blackhole"
527-
## routes:
528-
###################################################
529-
## Duplicate code_owner routes to teams
530-
## These will send alerts to team channels but continue
531-
## processing through the rest of the tree to handled by on-call
532-
# - matchers:
533-
# - code_owner_channel!=""
534-
# - severity=~"info|warning|critical"
535-
# group_by: ["code_owner_channel", "alertgroup", "job"]
536-
# receiver: slack-code-owners
537-
# ###################################################
538-
# ## Standard on-call routes
539-
# - matchers:
540-
# - severity=~"info|warning|critical"
541-
# receiver: slack-monitoring
542-
# continue: true
543-
523+
# group_by: ["alertgroup", "job"]
524+
# group_wait: 30s
525+
# group_interval: 5m
526+
# repeat_interval: 12h
527+
# routes:
528+
#
529+
# # Duplicate code_owner routes to teams
530+
# # These will send alerts to team channels but continue
531+
# # processing through the rest of the tree to handled by on-call
532+
# - matchers:
533+
# - code_owner_channel!=""
534+
# - severity=~"info|warning|critical"
535+
# group_by: ["code_owner_channel", "alertgroup", "job"]
536+
# receiver: slack-code-owners
537+
#
538+
# # Standard on-call routes
539+
# - matchers:
540+
# - severity=~"info|warning|critical"
541+
# receiver: slack-monitoring
542+
# continue: true
543+
#
544544
# inhibit_rules:
545545
# - target_matchers:
546546
# - severity=~"warning|info"
@@ -568,55 +568,55 @@ alertmanager:
568568

569569
receivers:
570570
- name: blackhole
571-
# - name: "slack-monitoring"
572-
# slack_configs:
573-
# - channel: "#channel"
574-
# send_resolved: true
575-
# title: '{{ template "slack.monzo.title" . }}'
576-
# icon_emoji: '{{ template "slack.monzo.icon_emoji" . }}'
577-
# color: '{{ template "slack.monzo.color" . }}'
578-
# text: '{{ template "slack.monzo.text" . }}'
579-
# actions:
580-
# - type: button
581-
# text: "Runbook :green_book:"
582-
# url: "{{ (index .Alerts 0).Annotations.runbook_url }}"
583-
# - type: button
584-
# text: "Query :mag:"
585-
# url: "{{ (index .Alerts 0).GeneratorURL }}"
586-
# - type: button
587-
# text: "Dashboard :grafana:"
588-
# url: "{{ (index .Alerts 0).Annotations.dashboard }}"
589-
# - type: button
590-
# text: "Silence :no_bell:"
591-
# url: '{{ template "__alert_silence_link" . }}'
592-
# - type: button
593-
# text: '{{ template "slack.monzo.link_button_text" . }}'
594-
# url: "{{ .CommonAnnotations.link_url }}"
595-
# - name: slack-code-owners
596-
# slack_configs:
597-
# - channel: "#{{ .CommonLabels.code_owner_channel }}"
598-
# send_resolved: true
599-
# title: '{{ template "slack.monzo.title" . }}'
600-
# icon_emoji: '{{ template "slack.monzo.icon_emoji" . }}'
601-
# color: '{{ template "slack.monzo.color" . }}'
602-
# text: '{{ template "slack.monzo.text" . }}'
603-
# actions:
604-
# - type: button
605-
# text: "Runbook :green_book:"
606-
# url: "{{ (index .Alerts 0).Annotations.runbook }}"
607-
# - type: button
608-
# text: "Query :mag:"
609-
# url: "{{ (index .Alerts 0).GeneratorURL }}"
610-
# - type: button
611-
# text: "Dashboard :grafana:"
612-
# url: "{{ (index .Alerts 0).Annotations.dashboard }}"
613-
# - type: button
614-
# text: "Silence :no_bell:"
615-
# url: '{{ template "__alert_silence_link" . }}'
616-
# - type: button
617-
# text: '{{ template "slack.monzo.link_button_text" . }}'
618-
# url: "{{ .CommonAnnotations.link_url }}"
619-
#
571+
# - name: "slack-monitoring"
572+
# slack_configs:
573+
# - channel: "#channel"
574+
# send_resolved: true
575+
# title: '{{ template "slack.monzo.title" . }}'
576+
# icon_emoji: '{{ template "slack.monzo.icon_emoji" . }}'
577+
# color: '{{ template "slack.monzo.color" . }}'
578+
# text: '{{ template "slack.monzo.text" . }}'
579+
# actions:
580+
# - type: button
581+
# text: "Runbook :green_book:"
582+
# url: "{{ (index .Alerts 0).Annotations.runbook_url }}"
583+
# - type: button
584+
# text: "Query :mag:"
585+
# url: "{{ (index .Alerts 0).GeneratorURL }}"
586+
# - type: button
587+
# text: "Dashboard :grafana:"
588+
# url: "{{ (index .Alerts 0).Annotations.dashboard }}"
589+
# - type: button
590+
# text: "Silence :no_bell:"
591+
# url: '{{ template "__alert_silence_link" . }}'
592+
# - type: button
593+
# text: '{{ template "slack.monzo.link_button_text" . }}'
594+
# url: "{{ .CommonAnnotations.link_url }}"
595+
# - name: slack-code-owners
596+
# slack_configs:
597+
# - channel: "#{{ .CommonLabels.code_owner_channel }}"
598+
# send_resolved: true
599+
# title: '{{ template "slack.monzo.title" . }}'
600+
# icon_emoji: '{{ template "slack.monzo.icon_emoji" . }}'
601+
# color: '{{ template "slack.monzo.color" . }}'
602+
# text: '{{ template "slack.monzo.text" . }}'
603+
# actions:
604+
# - type: button
605+
# text: "Runbook :green_book:"
606+
# url: "{{ (index .Alerts 0).Annotations.runbook }}"
607+
# - type: button
608+
# text: "Query :mag:"
609+
# url: "{{ (index .Alerts 0).GeneratorURL }}"
610+
# - type: button
611+
# text: "Dashboard :grafana:"
612+
# url: "{{ (index .Alerts 0).Annotations.dashboard }}"
613+
# - type: button
614+
# text: "Silence :no_bell:"
615+
# url: '{{ template "__alert_silence_link" . }}'
616+
# - type: button
617+
# text: '{{ template "slack.monzo.link_button_text" . }}'
618+
# url: "{{ .CommonAnnotations.link_url }}"
619+
#
620620
# -- Better alert templates for [slack source](https://gist.github.com/milesbxf/e2744fc90e9c41b47aa47925f8ff6512)
621621
monzoTemplate:
622622
enabled: true

0 commit comments

Comments
 (0)