Skip to content

Commit

Permalink
Merge pull request #235 from wanjunlei/master
Browse files Browse the repository at this point in the history
add receiver name to the notifications
  • Loading branch information
benjaminhuo authored Jan 2, 2024
2 parents 566adb0 + b4a5ebd commit d662f44
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 11 deletions.
8 changes: 8 additions & 0 deletions helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{/*namespace*/}}
{{- define "nm.namespaceOverride" -}}
{{- if .Values.namespaceOverride -}}
{{- .Values.namespaceOverride -}}
{{- else -}}
{{- .Release.Namespace -}}
{{- end -}}
{{- end -}}
6 changes: 3 additions & 3 deletions helm/templates/clusterrolebindings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ roleRef:
subjects:
- kind: ServiceAccount
name: notification-manager-sa
namespace: {{ .Release.Namespace }}
namespace: {{ include "nm.namespaceOverride" . }}

---
apiVersion: rbac.authorization.k8s.io/v1
Expand All @@ -23,7 +23,7 @@ roleRef:
subjects:
- kind: ServiceAccount
name: notification-manager-sa
namespace: {{ .Release.Namespace }}
namespace: {{ include "nm.namespaceOverride" . }}

{{- if .Values.kubesphere.enabled }}
{{- if or (eq .Values.kubesphere.version "v3.1.0") (eq .Values.kubesphere.version "v3.2.0") }}
Expand All @@ -39,6 +39,6 @@ roleRef:
subjects:
- kind: ServiceAccount
name: notification-manager-sa
namespace: {{ .Release.Namespace }}
namespace: {{ include "nm.namespaceOverride" . }}
{{- end}}
{{- end}}
10 changes: 9 additions & 1 deletion helm/templates/notificationmanagers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,19 @@ spec:
{{- if .Values.kubesphere.enabled }}
sidecars:
tenant:
{{- if .Values.kubesphere.image }}
image: {{ .Values.kubesphere.image }}
{{- else }}
image: kubesphere/notification-tenant-sidecar:{{ .Values.kubesphere.version }}
{{- end }}
name: tenant
type: kubesphere
{{- end }}
template:
{{- toYaml .Values.notificationmanager.template | nindent 4 }}
groupLabels:
{{- toYaml .Values.notificationmanager.groupLabels | nindent 4 }}
{{- toYaml .Values.notificationmanager.groupLabels | nindent 4 }}
annotations:
{{- toYaml .Values.notificationmanager.annotations | nindent 4 }}
labels:
{{- toYaml .Values.notificationmanager.labels | nindent 4 }}
1 change: 1 addition & 0 deletions helm/templates/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ metadata:
labels:
control-plane: controller-manager
name: notification-manager-operator
namespace: {{ include "nm.namespaceOverride" . }}
spec:
replicas: 1
selector:
Expand Down
3 changes: 2 additions & 1 deletion helm/templates/rolebindings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: notification-manager-leader-election-rolebinding
namespace: {{ include "nm.namespaceOverride" . }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: notification-manager-leader-election-role
subjects:
- kind: ServiceAccount
name: notification-manager-sa
namespace: {{ .Release.Namespace }}
namespace: {{ include "nm.namespaceOverride" . }}

1 change: 1 addition & 0 deletions helm/templates/roles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: notification-manager-leader-election-role
namespace: {{ include "nm.namespaceOverride" . }}
rules:
- apiGroups:
- ""
Expand Down
1 change: 1 addition & 0 deletions helm/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ apiVersion: v1
kind: ServiceAccount
metadata:
name: notification-manager-sa
namespace: {{ include "nm.namespaceOverride" . }}

2 changes: 2 additions & 0 deletions helm/templates/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ metadata:
labels:
control-plane: controller-manager
name: notification-manager-controller-metrics
namespace: {{ include "nm.namespaceOverride" . }}
spec:
ports:
- name: https
Expand All @@ -19,6 +20,7 @@ apiVersion: v1
kind: Service
metadata:
name: notification-manager-webhook
namespace: {{ include "nm.namespaceOverride" . }}
spec:
ports:
- port: 443
Expand Down
2 changes: 2 additions & 0 deletions helm/templates/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,5 @@ data:
kind: ConfigMap
metadata:
name: notification-manager-template
namespace: {{ include "nm.namespaceOverride" . }}

12 changes: 7 additions & 5 deletions helm/templates/validating.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{{- $name := include "nm.namespaceOverride" . }}
{{- $ca := genCA "webhook-ca" 36500 -}}
{{- $dns := cat "notification-manager-webhook." .Release.Namespace ".svc" | nospace -}}
{{- $dns := cat "notification-manager-webhook." $name ".svc" | nospace -}}
{{- $cert := genSignedCert "notification-manager-webhook" (list) (list $dns) 36500 $ca -}}
apiVersion: v1
data:
Expand All @@ -8,6 +9,7 @@ data:
kind: Secret
metadata:
name: notification-manager-webhook-server-cert
namespace: {{ include "nm.namespaceOverride" . }}
type: kubernetes.io/tls

---
Expand All @@ -22,7 +24,7 @@ webhooks:
caBundle: {{ $ca.Cert | b64enc }}
service:
name: notification-manager-webhook
namespace: {{ .Release.Namespace }}
namespace: {{ include "nm.namespaceOverride" . }}
path: /validate-notification-kubesphere-io-v2beta2-config
failurePolicy: Fail
name: vconfig.notification.kubesphere.io
Expand All @@ -43,7 +45,7 @@ webhooks:
caBundle: {{ $ca.Cert | b64enc }}
service:
name: notification-manager-webhook
namespace: {{ .Release.Namespace }}
namespace: {{ include "nm.namespaceOverride" . }}
path: /validate-notification-kubesphere-io-v2beta2-receiver
failurePolicy: Fail
name: vreceiver.notification.kubesphere.io
Expand All @@ -64,7 +66,7 @@ webhooks:
caBundle: {{ $ca.Cert | b64enc }}
service:
name: notification-manager-webhook
namespace: {{ .Release.Namespace }}
namespace: {{ include "nm.namespaceOverride" . }}
path: /validate-notification-kubesphere-io-v2beta2-router
failurePolicy: Fail
name: vrouter.notification.kubesphere.io
Expand All @@ -85,7 +87,7 @@ webhooks:
caBundle: {{ $ca.Cert | b64enc }}
service:
name: notification-manager-webhook
namespace: {{ .Release.Namespace }}
namespace: {{ include "nm.namespaceOverride" . }}
path: /validate-notification-kubesphere-io-v2beta2-silence
failurePolicy: Fail
name: vsilence.notification.kubesphere.io
Expand Down
40 changes: 40 additions & 0 deletions helm/templates/zh-cn.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apiVersion: v1
data:
zh-cn: |
- name: zh-cn
dictionary:
alert: "告警"
alerts: "告警"
firing: "触发中"
resolved: "已解决"
alertname: "告警名称"
alerttype: "告警类型"
cluster: "集群"
namespace: "项目"
severity: "告警级别"
container: "容器"
pod: "容器组"
service: "服务"
deployment: "部署"
job: "任务"
daemonset: "守护进程集"
statefulset: "有状态副本集"
instance: "实例"
resource: "资源"
user: "用户"
verb: "操作"
group: "用户组"
requestReceivedTimestamp: "请求接收时间"
role: "角色"
host_ip: "主机IP"
node: "节点"
rule_id: "告警规则"
owner_kind: "目标类型"
workload: "工作负载"
rule_group: "规则组"
rule_level: "规则级别"
name: "名称"
kind: ConfigMap
metadata:
name: zh-cn
namespace: {{ include "nm.namespaceOverride" . }}
9 changes: 8 additions & 1 deletion helm/values.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespaceOverride: ""

kubesphere:
enabled: fase
enabled: false
# supported version: v3.1.0, v3.2.0
version: v3.2.0

Expand Down Expand Up @@ -78,8 +80,13 @@ notificationmanager:
- alertname
- namespace
template:
language: English
languagePack:
- name: zh-cn
namespace: kubesphere-monitoring-system
text:
name: notification-manager-template
namespace: kubesphere-monitoring-system
env:
- name: TZ
value: Asia/Shanghai
2 changes: 2 additions & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const (
AlertSummary = "summary"
AlertSummaryCN = "summaryCn"

ReceiverName = "receiver"

Verify = "verify"
Notification = "notification"

Expand Down
9 changes: 9 additions & 0 deletions pkg/notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func (s *notifyStage) Exec(ctx context.Context, l log.Logger, data interface{})
for k, v := range input {
receiver := k
ds := v
s.addExtensionLabels(receiver, ds)
nf, err := factories[receiver.GetType()](l, receiver, s.notifierCtl)
if err != nil {
e := err
Expand All @@ -118,3 +119,11 @@ func (s *notifyStage) Exec(ctx context.Context, l log.Logger, data interface{})

return ctx, alertMap, group.Wait()
}

func (s *notifyStage) addExtensionLabels(receiver internal.Receiver, data []*template.Data) {
for _, d := range data {
for _, alert := range d.Alerts {
alert.Labels[constants.ReceiverName] = receiver.GetName()
}
}
}

0 comments on commit d662f44

Please sign in to comment.