feat(flux): filter out ReconciliationSucceeded

These notification are too spammy. We may need to add logic
to handle in progress reconciliations.
This commit is contained in:
Bastien Riviere 2023-09-03 12:19:34 +02:00
parent d63da674fd
commit eef59c479c
Signed by: babariviere
GPG key ID: 4E5F0839249F162E
2 changed files with 17 additions and 0 deletions

View file

@ -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 {

View file

@ -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