feat: notify ReconciliationSucceeded only after modification
This commit is contained in:
parent
4234eee583
commit
6b035f4deb
1 changed files with 38 additions and 19 deletions
|
@ -9,20 +9,26 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type fluxInvolvedObject struct {
|
||||||
|
Kind string `json:"kind"`
|
||||||
|
Namespace string `json:"namespace"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
UID string `json:"uid"`
|
||||||
|
APIVersion string `json:"apiVersion"`
|
||||||
|
ResourceVersion string `json:"resourceVersion"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f fluxInvolvedObject) String() string {
|
||||||
|
return strings.ToLower(f.Kind) + "/" + f.Namespace + "." + f.Name
|
||||||
|
}
|
||||||
|
|
||||||
type FluxNotification struct {
|
type FluxNotification struct {
|
||||||
InvolvedObject struct {
|
InvolvedObject fluxInvolvedObject `json:"involvedObject"`
|
||||||
Kind string `json:"kind"`
|
Severity string `json:"severity"`
|
||||||
Namespace string `json:"namespace"`
|
Timestamp time.Time `json:"timestamp"`
|
||||||
Name string `json:"name"`
|
Message string `json:"message"`
|
||||||
UID string `json:"uid"`
|
Reason string `json:"reason"`
|
||||||
APIVersion string `json:"apiVersion"`
|
Metadata struct {
|
||||||
ResourceVersion string `json:"resourceVersion"`
|
|
||||||
} `json:"involvedObject"`
|
|
||||||
Severity string `json:"severity"`
|
|
||||||
Timestamp time.Time `json:"timestamp"`
|
|
||||||
Message string `json:"message"`
|
|
||||||
Reason string `json:"reason"`
|
|
||||||
Metadata struct {
|
|
||||||
CommitStatus string `json:"commit_status"`
|
CommitStatus string `json:"commit_status"`
|
||||||
Revision string `json:"revision"`
|
Revision string `json:"revision"`
|
||||||
Summary string `json:"summary"`
|
Summary string `json:"summary"`
|
||||||
|
@ -31,10 +37,15 @@ type FluxNotification struct {
|
||||||
ReportingInstance string `json:"reportingInstance"`
|
ReportingInstance string `json:"reportingInstance"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type FluxHandler struct{}
|
type FluxHandler struct {
|
||||||
|
// Register all modifications of reconciliations
|
||||||
|
reconciliations map[string]bool
|
||||||
|
}
|
||||||
|
|
||||||
func NewFluxHandler() FluxHandler {
|
func NewFluxHandler() FluxHandler {
|
||||||
return FluxHandler{}
|
return FluxHandler{
|
||||||
|
reconciliations: make(map[string]bool),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f FluxHandler) FormatNotification(r io.Reader) (Notification, error) {
|
func (f FluxHandler) FormatNotification(r io.Reader) (Notification, error) {
|
||||||
|
@ -47,13 +58,21 @@ func (f FluxHandler) FormatNotification(r io.Reader) (Notification, error) {
|
||||||
return Notification{}, err
|
return Notification{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
obj := not.InvolvedObject.String()
|
||||||
if not.Reason == "ReconciliationSucceeded" {
|
if not.Reason == "ReconciliationSucceeded" {
|
||||||
// Filter out spammy ReconciliationSucceeded notification
|
if ok := f.reconciliations[obj]; !ok {
|
||||||
return Notification{}, nil
|
// Filter out spammy ReconciliationSucceeded notification
|
||||||
|
return Notification{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// we will print the object so skip it next time it spam
|
||||||
|
f.reconciliations[obj] = false
|
||||||
|
} else {
|
||||||
|
// object has been modified, we can print it next time
|
||||||
|
f.reconciliations[obj] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
title := fmt.Sprintf("[%s] %s %s/%s.%s", not.Severity, not.Reason,
|
title := fmt.Sprintf("[%s] %s %s", not.Severity, not.Reason, obj)
|
||||||
strings.ToLower(not.InvolvedObject.Kind), not.InvolvedObject.Namespace, not.InvolvedObject.Name)
|
|
||||||
body := not.Message + "\n\n**revision**\n" + not.Metadata.Revision
|
body := not.Message + "\n\n**revision**\n" + not.Metadata.Revision
|
||||||
|
|
||||||
l.Debug("flux notification", slog.Group("notification",
|
l.Debug("flux notification", slog.Group("notification",
|
||||||
|
|
Loading…
Reference in a new issue