Skip to content

Commit

Permalink
fix bug the template generate notification error
Browse files Browse the repository at this point in the history
Signed-off-by: wanjunlei <wanjunlei@kubesphere.io>
  • Loading branch information
wanjunlei committed May 13, 2022
1 parent 216b5ec commit c14f9e5
Show file tree
Hide file tree
Showing 11 changed files with 7,031 additions and 9,806 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ manifests: controller-gen
cd config/manager && kustomize edit set image controller=${IMG} && cd ../../
kustomize build config/default | sed -e '/creationTimestamp/d' > config/bundle.yaml
kustomize build config/samples | sed -e '/creationTimestamp/d' > config/samples/bundle.yaml
cp -r ./config/crd/bases/* ./helm/crds/
kustomize build config/helm | sed -e '/creationTimestamp/d' > helm/crds/bundle.yaml

# Run go fmt against code
fmt:
Expand Down
16 changes: 16 additions & 0 deletions config/helm/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Adds namespace to all resources.
namespace: kubesphere-monitoring-system

# Value of this field is prepended to the
# names of all resources, e.g. a deployment named
# "wordpress" becomes "alices-wordpress".
# Note that it should also match with the prefix (text before '-') of the namespace
# field above.
namePrefix: notification-manager-

# Labels to add to all resources and selectors.
#commonLabels:
# someName: someValue

bases:
- ../crd
7,001 changes: 7,001 additions & 0 deletions helm/crds/bundle.yaml

Large diffs are not rendered by default.

1,066 changes: 0 additions & 1,066 deletions helm/crds/notification.kubesphere.io_configs.yaml

This file was deleted.

6,181 changes: 0 additions & 6,181 deletions helm/crds/notification.kubesphere.io_notificationmanagers.yaml

This file was deleted.

2,263 changes: 0 additions & 2,263 deletions helm/crds/notification.kubesphere.io_receivers.yaml

This file was deleted.

169 changes: 0 additions & 169 deletions helm/crds/notification.kubesphere.io_routers.yaml

This file was deleted.

119 changes: 0 additions & 119 deletions helm/crds/notification.kubesphere.io_silences.yaml

This file was deleted.

7 changes: 4 additions & 3 deletions helm/templates/notificationmanagers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ spec:
{{- toYaml .Values.notificationmanager.defaultSecretNamespace | nindent 4 }}
{{- if eq .Values.kubesphere true }}
sidecars:
image: kubesphere/notification-tenant-sidecar:v3.2.0
name: tenant
type: kubesphere
tenant:
image: kubesphere/notification-tenant-sidecar:v3.2.0
name: tenant
type: kubesphere
{{- end}}
template:
{{- toYaml .Values.notificationmanager.template | nindent 4 }}
Expand Down
4 changes: 2 additions & 2 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const (
AlertResolved = "resolved"

AlertName = "alertname"
AlertType = "alertype"
AlertTime = "alertime"
AlertType = "alerttype"
AlertTime = "alerttime"
AlertMessage = "message"
AlertSummary = "summary"
AlertSummaryCN = "summaryCn"
Expand Down
9 changes: 7 additions & 2 deletions pkg/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,13 @@ func (t *Template) Html(name string, data *Data) (string, error) {

// Delete all `space`, `LF`, `CR` at the end of string.
func cleanSuffix(s string) string {

for {
l := len(s)
if l == 0 {
return s
}

if byte(s[l-1]) == 10 || byte(s[l-1]) == 13 || byte(s[l-1]) == 32 {
s = s[:l-1]
} else {
Expand Down Expand Up @@ -225,14 +230,14 @@ func (t *Template) Split(data *Data, maxSize int, templateName string, subjectTe
for i := 0; i < len(data.Alerts); i++ {

d.Alerts = append(d.Alerts, data.Alerts[i])
msg, err := t.Text(templateName, d.Format())
msg, err := t.Text(t.transform(templateName), d.Format())
if err != nil {
return nil, nil, err
}

subject := ""
if subjectTemplateName != "" {
subject, err = t.Text(templateName, d)
subject, err = t.Text(t.transform(subjectTemplateName), d)
if err != nil {
return nil, nil, err
}
Expand Down

0 comments on commit c14f9e5

Please sign in to comment.