Skip to content

Commit e6ccf34

Browse files
authored
Merge pull request #268 from wanjunlei/release-2.5
cherry pick from master
2 parents ca3ee81 + becde0b commit e6ccf34

File tree

17 files changed

+234
-133
lines changed

17 files changed

+234
-133
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#
2+
# Copyright 2022 The Notification-Manager Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
name: WorkFlow for Building sidecar image
18+
19+
on:
20+
push:
21+
branches:
22+
- 'master'
23+
paths:
24+
- '.github/workflows/push-sidecar-image.yaml'
25+
- 'sidecar/kubesphere/4.0.0/backend.go'
26+
- 'sidecar/kubesphere/4.0.0/Dockerfile'
27+
- 'sidecar/kubesphere/4.0.0/main.go'
28+
- 'sidecar/kubesphere/4.0.0/Makefile'
29+
- 'sidecar/kubesphere/4.0.0/go.sum'
30+
- 'sidecar/kubesphere/4.0.0/go.mod'
31+
32+
env:
33+
REPO_OP: 'kubesphere'
34+
35+
jobs:
36+
build:
37+
runs-on: ubuntu-latest
38+
timeout-minutes: 30
39+
name: Build Operator Image
40+
steps:
41+
- name: Install Go
42+
uses: actions/setup-go@v2
43+
with:
44+
go-version: 1.20.x
45+
46+
- uses: actions/cache@v2
47+
with:
48+
path: ~/go/pkg/mod
49+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
50+
51+
- name: Checkout code
52+
uses: actions/checkout@v2
53+
with:
54+
fetch-depth: 0
55+
56+
- name: Set up QEMU
57+
id: qemu
58+
uses: docker/setup-qemu-action@v1
59+
with:
60+
image: tonistiigi/binfmt:latest
61+
platforms: all
62+
63+
- name: Login to Docker Hub
64+
uses: docker/login-action@v1
65+
with:
66+
username: ${{ secrets.REGISTRY_USER }}
67+
password: ${{ secrets.REGISTRY_PASSWORD }}
68+
69+
- name: Set up Docker Buildx
70+
id: buildx
71+
uses: docker/setup-buildx-action@v1
72+
73+
- name: Build and Push image
74+
run: |
75+
cd sidecar/kubesphere/4.0.0 && make

config/samples/template.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ data:
55
{{ define "nm.default.message.cn" }}{{ if ne (len .Status) 0 }}[{{ .Status | translate }}] {{ end }}{{ .MessageCN }}{{ end }}
66
77
{{ define "nm.default.subject" }}{{ if eq (len .Alerts) 1 }}{{ range .Alerts }}{{ template "nm.default.message" . }}{{ end }}{{ else }}{{ .Alerts | len }} {{ if ne (len .Status) 0 }}{{ .Status }} {{ end }}alerts{{ if gt (len .GroupLabels.SortedPairs) 0 }} for {{ range .GroupLabels.SortedPairs }}{{ .Name | translate }}={{ .Value }} {{ end }}{{ end }}{{ end }}{{ end }}
8-
{{ define "nm.subject" }}{{ .Alerts | len }} {{ if ne (len .Status) 0 }}{{ .Status }} {{ end }}alerts{{ if gt (len .CommonLabels.SortedPairs) 0 }} for {{ range .CommonLabels.SortedPairs }}{{ .Name | translate }}={{ .Value }} {{ end }}{{ end }}{{ end }}
9-
8+
{{ define "nm.subject" -}}{{- $rawStatus := .Status -}}{{- $severity := index .CommonLabels "severity" -}}{{- $status := "" -}}{{- if eq $rawStatus "firing" -}}{{- $status = "FIRING" -}}{{- else if eq $rawStatus "resolved" -}}{{- $status = "RESOLVED" -}}{{- else -}}{{- $status = "UNKNOWN" -}}{{- end -}}{{- $numAlerts := len .Alerts -}}{{- if eq $numAlerts 0 -}}Show nothing{{- else if eq $numAlerts 1 -}}{{- range .Alerts -}}{{- $alertType := .Labels.alerttype -}}{{- $alertName := .Labels.alertname -}}{{- $cluster := .Labels.cluster -}}{{- $node := .Labels.node -}}{{- $pod := .Labels.pod -}}{{- $namespace := .Labels.namespace -}}{{- $output := printf "[%s]" $status -}}{{- if $severity -}}{{- $output = printf "%s | severity=%s" $output $severity -}}{{- end -}}{{- if $alertType -}}{{- $output = printf "%s | alerttype=%s" $output $alertType -}}{{- end -}}{{- if $alertName -}}{{- $output = printf "%s | alertname=%s" $output $alertName -}}{{- end -}}{{- if $cluster -}}{{- $output = printf "%s | cluster=%s" $output $cluster -}}{{- end -}}{{- if $node -}}{{- $output = printf "%s | node=%s" $output $node -}}{{- end -}}{{- if $namespace -}}{{- $output = printf "%s | namespace=%s" $output $namespace -}}{{- end -}}{{- if $pod -}}{{- $output = printf "%s | pod=%s" $output $pod -}}{{- end -}}{{- $output -}}{{- end -}}{{- else -}}{{- $alertType := index .GroupLabels "alerttype" -}}{{- $alertName := index .GroupLabels "alertname" -}}{{- $cluster := index .GroupLabels "cluster" -}}{{- $namespace := index .GroupLabels "namespace" -}}{{- $node := index .GroupLabels "node" -}}{{- $output := printf "[%s]" $status -}}{{- if $severity -}}{{- $output = printf "%s | severity=%s" $output $severity -}}{{- end -}}{{- if $alertType -}}{{- $output = printf "%s | alerttype=%s" $output $alertType -}}{{- end -}}{{- if $alertName -}}{{- $output = printf "%s | alertname=%s" $output $alertName -}}{{- end -}}{{- if $cluster -}}{{- $output = printf "%s | cluster=%s" $output $cluster -}}{{- end -}}{{- if $namespace -}}{{- $output = printf "%s | namespace=%s" $output $namespace -}}{{- end -}}{{- if $node -}}{{- $output = printf "%s | node=%s" $output $node -}}{{- end -}}{{- $output -}}{{- end -}}{{- end -}}
109
{{ define "nm.default.text" }}{{ range .Alerts }}{{ template "nm.default.message" . }}
1110
{{ range .Labels.SortedPairs }} {{ .Name | translate }}: {{ .Value }}
1211
{{ end }}{{ range .Annotations.SortedPairs.Filter "runbook_url" "message" "summary" "summary_cn" }} {{ .Name | translate }}: {{ .Value }}

docs/crds/silence.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Overview
44

5-
`slience` CRD is used to define policies to mute notifications for a given time. A silence is configured based on a label selector.
5+
`Silence` CRD is used to define policies to mute notifications for a given time. A silence is configured based on a label selector.
66
If the incoming alert matches the label selector of an active silence, no notifications will be sent out for that alert.
77

88
`Silence` can be categorized into 2 types `global` and `tenant` by label like `type = global`, `type = tenant` :

go.mod

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/aws/aws-sdk-go-v2/config v1.15.7
1010
github.com/aws/aws-sdk-go-v2/credentials v1.12.2
1111
github.com/aws/aws-sdk-go-v2/service/sns v1.17.6
12+
github.com/duke-git/lancet/v2 v2.2.9
1213
github.com/emicklei/go-restful v2.16.0+incompatible
1314
github.com/go-chi/chi v4.0.3+incompatible
1415
github.com/go-kit/kit v0.9.0
@@ -54,7 +55,6 @@ require (
5455
github.com/beorn7/perks v1.0.1 // indirect
5556
github.com/cespare/xxhash/v2 v2.2.0 // indirect
5657
github.com/davecgh/go-spew v1.1.1 // indirect
57-
github.com/duke-git/lancet/v2 v2.2.9 // indirect
5858
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
5959
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
6060
github.com/fsnotify/fsnotify v1.6.0 // indirect
@@ -89,16 +89,16 @@ require (
8989
go.uber.org/atomic v1.10.0 // indirect
9090
go.uber.org/multierr v1.11.0 // indirect
9191
go.uber.org/zap v1.24.0 // indirect
92-
golang.org/x/net v0.17.0 // indirect
92+
golang.org/x/net v0.23.0 // indirect
9393
golang.org/x/oauth2 v0.8.0 // indirect
94-
golang.org/x/sys v0.13.0 // indirect
95-
golang.org/x/term v0.13.0 // indirect
96-
golang.org/x/text v0.13.0 // indirect
94+
golang.org/x/sys v0.18.0 // indirect
95+
golang.org/x/term v0.18.0 // indirect
96+
golang.org/x/text v0.14.0 // indirect
9797
golang.org/x/time v0.3.0 // indirect
9898
golang.org/x/tools v0.12.0 // indirect
9999
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
100100
google.golang.org/appengine v1.6.7 // indirect
101-
google.golang.org/protobuf v1.30.0 // indirect
101+
google.golang.org/protobuf v1.33.0 // indirect
102102
gopkg.in/inf.v0 v0.9.1 // indirect
103103
gopkg.in/ini.v1 v1.56.0 // indirect
104104
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect

go.sum

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
252252
golang.org/x/crypto v0.0.0-20191219195013-becbf705a915/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
253253
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
254254
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
255+
golang.org/x/exp v0.0.0-20221208152030-732eee02a75a h1:4iLhBPcpqFmylhnkbY3W0ONLUYYkDAW9xMFLfxgsvCw=
255256
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
256257
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
257258
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
@@ -266,8 +267,8 @@ golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/
266267
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
267268
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
268269
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
269-
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
270-
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
270+
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
271+
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
271272
golang.org/x/oauth2 v0.8.0 h1:6dkIjl3j3LtZ/O3sTgZTMsLKSftL/B8Zgq4huOIIUu8=
272273
golang.org/x/oauth2 v0.8.0/go.mod h1:yr7u4HXZRm1R1kBWqr/xKNqewf0plRYoB7sla+BCIXE=
273274
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -291,16 +292,16 @@ golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7w
291292
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
292293
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
293294
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
294-
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
295-
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
295+
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
296+
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
296297
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
297-
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
298-
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
298+
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
299+
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
299300
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
300301
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
301302
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
302-
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
303-
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
303+
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
304+
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
304305
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
305306
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
306307
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@@ -330,8 +331,8 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi
330331
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
331332
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
332333
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
333-
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
334-
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
334+
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
335+
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
335336
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
336337
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
337338
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

helm/templates/notificationmanagers.yaml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ spec:
2424
{{- toYaml .Values.notificationmanager.receivers | nindent 4 }}
2525
defaultConfigSelector:
2626
{{- toYaml .Values.notificationmanager.defaultConfigSelector | nindent 4 }}
27-
{{- if .Values.timezone }}
28-
env:
29-
- name: TZ
30-
value: {{ .Values.timezone }}
31-
{{- end }}
3227
volumeMounts:
3328
{{- toYaml .Values.notificationmanager.volumeMounts | nindent 4 }}
3429
volumes:
@@ -60,4 +55,6 @@ spec:
6055
annotations:
6156
{{- toYaml .Values.notificationmanager.annotations | nindent 4 }}
6257
labels:
63-
{{- toYaml .Values.notificationmanager.labels | nindent 4 }}
58+
{{- toYaml .Values.notificationmanager.labels | nindent 4 }}
59+
env:
60+
{{- toYaml .Values.notificationmanager.env | nindent 4 }}

helm/templates/template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ data:
55
{{ "{{ define \"nm.default.message.cn\" }}{{ if ne (len .Status) 0 }}[{{ .Status | translate }}] {{ end }}{{ .MessageCN }}{{ end }}" }}
66
77
{{ "{{ define \"nm.default.subject\" }}{{ if eq (len .Alerts) 1 }}{{ range .Alerts }}{{ template \"nm.default.message\" . }}{{ end }}{{ else }}{{ .Alerts | len }} {{ if ne (len .Status) 0 }}{{ .Status }} {{ end }}alerts{{ if gt (len .GroupLabels.SortedPairs) 0 }} for {{ range .GroupLabels.SortedPairs }}{{ .Name | translate }}={{ .Value }} {{ end }}{{ end }}{{ end }}{{ end }}" }}
8-
{{ "{{ define \"nm.subject\" }}{{ .Alerts | len }} {{ if ne (len .Status) 0 }}{{ .Status }} {{ end }}alerts{{ if gt (len .CommonLabels.SortedPairs) 0 }} for {{ range .CommonLabels.SortedPairs }}{{ .Name | translate }}={{ .Value }} {{ end }}{{ end }}{{ end }}" }}
8+
{{ "{{ define \"nm.subject\" -}}{{- $rawStatus := .Status -}}{{- $severity := index .CommonLabels \"severity\" -}}{{- $status := \"\" -}}{{- if eq $rawStatus \"firing\" -}}{{- $status = \"FIRING\" -}}{{- else if eq $rawStatus \"resolved\" -}}{{- $status = \"RESOLVED\" -}}{{- else -}}{{- $status = \"UNKNOWN\" -}}{{- end -}}{{- $numAlerts := len .Alerts -}}{{- if eq $numAlerts 0 -}}Show nothing{{- else if eq $numAlerts 1 -}}{{- range .Alerts -}}{{- $alertType := .Labels.alerttype -}}{{- $alertName := .Labels.alertname -}}{{- $cluster := .Labels.cluster -}}{{- $node := .Labels.node -}}{{- $pod := .Labels.pod -}}{{- $namespace := .Labels.namespace -}}{{- $output := printf \"[%s]\" $status -}}{{- if $severity -}}{{- $output = printf \"%s | severity=%s\" $output $severity -}}{{- end -}}{{- if $alertType -}}{{- $output = printf \"%s | alerttype=%s\" $output $alertType -}}{{- end -}}{{- if $alertName -}}{{- $output = printf \"%s | alertname=%s\" $output $alertName -}}{{- end -}}{{- if $cluster -}}{{- $output = printf \"%s | cluster=%s\" $output $cluster -}}{{- end -}}{{- if $node -}}{{- $output = printf \"%s | node=%s\" $output $node -}}{{- end -}}{{- if $namespace -}}{{- $output = printf \"%s | namespace=%s\" $output $namespace -}}{{- end -}}{{- if $pod -}}{{- $output = printf \"%s | pod=%s\" $output $pod -}}{{- end -}}{{- $output -}}{{- end -}}{{- else -}}{{- $alertType := index .GroupLabels \"alerttype\" -}}{{- $alertName := index .GroupLabels \"alertname\" -}}{{- $cluster := index .GroupLabels \"cluster\" -}}{{- $namespace := index .GroupLabels \"namespace\" -}}{{- $node := index .GroupLabels \"node\" -}}{{- $output := printf \"[%s]\" $status -}}{{- if $severity -}}{{- $output = printf \"%s | severity=%s\" $output $severity -}}{{- end -}}{{- if $alertType -}}{{- $output = printf \"%s | alerttype=%s\" $output $alertType -}}{{- end -}}{{- if $alertName -}}{{- $output = printf \"%s | alertname=%s\" $output $alertName -}}{{- end -}}{{- if $cluster -}}{{- $output = printf \"%s | cluster=%s\" $output $cluster -}}{{- end -}}{{- if $namespace -}}{{- $output = printf \"%s | namespace=%s\" $output $namespace -}}{{- end -}}{{- if $node -}}{{- $output = printf \"%s | node=%s\" $output $node -}}{{- end -}}{{- $output -}}{{- end -}}{{- end -}}" }}
99
1010
{{ "{{ define \"nm.default.text\" }}{{ range .Alerts }}{{ template \"nm.default.message\" . }}" }}
1111
{{ "{{ range .Labels.SortedPairs }} {{ .Name | translate }}: {{ .Value }}" }}

pkg/constants/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const (
2626
DiscordContent = "content"
2727
DiscordEmbed = "embed"
2828

29+
Cluster = "cluster"
2930
Namespace = "namespace"
3031

3132
AlertFiring = "firing"

pkg/controller/controller.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ func (c *Controller) receiverChanged(t *task) {
505505
_ = level.Info(c.logger).Log("msg", "Receiver changed", "op", t.op, "name", receiver.Name)
506506
}
507507

508-
func (c *Controller) tenantIDFromNs(namespace string) ([]string, error) {
508+
func (c *Controller) tenantIDFromNs(cluster, namespace string) ([]string, error) {
509509
tenantIDs := make([]string, 0)
510510
// Use namespace as TenantID directly if tenantSidecar not provided.
511511
if !c.tenantSidecar {
@@ -514,7 +514,8 @@ func (c *Controller) tenantIDFromNs(namespace string) ([]string, error) {
514514
}
515515

516516
p := make(map[string]string)
517-
p["namespace"] = namespace
517+
p[constants.Cluster] = cluster
518+
p[constants.Namespace] = namespace
518519
u, err := utils.UrlWithParameters(tenantSidecarURL, p)
519520
if err != nil {
520521
return nil, err
@@ -536,7 +537,7 @@ func (c *Controller) tenantIDFromNs(namespace string) ([]string, error) {
536537
return nil, err
537538
}
538539

539-
_ = level.Debug(c.logger).Log("msg", "get tenants from namespace", "namespace", namespace, "tenant", utils.ArrayToString(res, ","))
540+
_ = level.Debug(c.logger).Log("msg", "get tenants from namespace", "cluster", cluster, "namespace", namespace, "tenant", utils.ArrayToString(res, ","))
540541

541542
return res, nil
542543
}
@@ -580,13 +581,13 @@ func getMatchedConfig(r internal.Receiver, configs map[string]map[string]interna
580581
}
581582
}
582583

583-
func (c *Controller) RcvsFromNs(namespace *string) []internal.Receiver {
584+
func (c *Controller) RcvsFromNs(cluster string, namespace *string) []internal.Receiver {
584585

585586
// Global receiver should receive all notifications.
586587
tenants := []string{globalTenantID}
587588
if namespace != nil && len(*namespace) > 0 {
588589
// Get all tenants which need to receive the notifications in this namespace.
589-
tenantIDs, err := c.tenantIDFromNs(*namespace)
590+
tenantIDs, err := c.tenantIDFromNs(cluster, *namespace)
590591
if err != nil {
591592
_ = level.Error(c.logger).Log("msg", "get tenantID error", "err", err, "namespace", *namespace)
592593
} else {

pkg/route/router.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package route
22

33
import (
44
"context"
5+
"fmt"
6+
"strings"
57

68
"github.com/go-kit/kit/log"
79
"github.com/go-kit/kit/log/level"
@@ -51,25 +53,30 @@ func (s *routeStage) Exec(ctx context.Context, l log.Logger, data interface{}) (
5153
return ctx, nil, err
5254
}
5355

54-
// Grouping alerts by namespace
56+
// Grouping alerts by cluster and namespace
5557
alertMap := make(map[string][]*template.Alert)
5658
for _, alert := range input {
5759
ns := alert.Labels[constants.Namespace]
58-
as := alertMap[ns]
60+
cluster := alert.Labels[constants.Cluster]
61+
key := fmt.Sprintf("%s|%s", cluster, ns)
62+
as := alertMap[key]
5963
as = append(as, alert)
60-
alertMap[ns] = as
64+
alertMap[key] = as
6165
}
6266

6367
m := make(map[string]*packet)
6468
routePolicy := s.notifierCtl.GetRoutePolicy()
65-
for ns, alerts := range alertMap {
69+
for key, alerts := range alertMap {
6670
flag := false
71+
pair := strings.Split(key, "|")
72+
cluster := pair[0]
73+
ns := pair[1]
6774
var tenantRcvs []internal.Receiver
6875
for _, alert := range alerts {
6976
rcvs := s.rcvsFromRouter(alert, routers)
7077
if routePolicy == RouterPolicyAll || (routePolicy == RouterFirst && len(rcvs) == 0) {
7178
if len(tenantRcvs) == 0 && !flag {
72-
tenantRcvs = s.notifierCtl.RcvsFromNs(&ns)
79+
tenantRcvs = s.notifierCtl.RcvsFromNs(cluster, &ns)
7380
flag = true
7481
}
7582
rcvs = append(rcvs, tenantRcvs...)

0 commit comments

Comments
 (0)