From eef59c479ccfb623de449826fef56efe59822e0c Mon Sep 17 00:00:00 2001 From: Bastien Riviere Date: Sun, 3 Sep 2023 12:19:34 +0200 Subject: [PATCH] feat(flux): filter out ReconciliationSucceeded These notification are too spammy. We may need to add logic to handle in progress reconciliations. --- bridge/bridge.go | 11 +++++++++++ bridge/flux.go | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/bridge/bridge.go b/bridge/bridge.go index 68d1e7a..f9842bc 100644 --- a/bridge/bridge.go +++ b/bridge/bridge.go @@ -31,6 +31,10 @@ type Notification struct { auth Auth } +func (n Notification) IsEmpty() bool { + return n.Title == "" && n.Body == "" +} + func (n Notification) Send(base string) error { req, err := http.NewRequest("POST", base+"/"+n.topic, strings.NewReader(n.Body)) if err != nil { @@ -133,6 +137,13 @@ func (b Bridge) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } + // If notification is empty, that means it should be ignored. + // TODO: maybe return an error instead of empty notification + if not.IsEmpty() { + w.WriteHeader(http.StatusOK) + return + } + not.topic = b.topic not.auth = b.auth if err = not.Send(b.baseURL); err != nil { diff --git a/bridge/flux.go b/bridge/flux.go index e87fd3b..655a92d 100644 --- a/bridge/flux.go +++ b/bridge/flux.go @@ -9,6 +9,7 @@ import ( "time" ) +// TODO: use skaffold to see why the revision is not present type FluxNotification struct { InvolvedObject struct { APIVersion string `json:"apiVersion"` @@ -44,6 +45,11 @@ func (f FluxHandler) FormatNotification(r io.Reader) (Notification, error) { return Notification{}, err } + if not.Reason == "ReconciliationSucceeded" { + // Filter out spammy ReconciliationSucceeded notification + return Notification{}, nil + } + title := fmt.Sprintf("[%s] %s %s/%s.%s", not.Severity, not.Reason, strings.ToLower(not.InvolvedObject.Kind), not.InvolvedObject.Namespace, not.InvolvedObject.Name) body := not.Message + "\n\n**revision**\n" + not.Metadata.KustomizeToolkitFluxcdIoRevision