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:
parent
d63da674fd
commit
eef59c479c
2 changed files with 17 additions and 0 deletions
|
@ -31,6 +31,10 @@ type Notification struct {
|
||||||
auth Auth
|
auth Auth
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n Notification) IsEmpty() bool {
|
||||||
|
return n.Title == "" && n.Body == ""
|
||||||
|
}
|
||||||
|
|
||||||
func (n Notification) Send(base string) error {
|
func (n Notification) Send(base string) error {
|
||||||
req, err := http.NewRequest("POST", base+"/"+n.topic, strings.NewReader(n.Body))
|
req, err := http.NewRequest("POST", base+"/"+n.topic, strings.NewReader(n.Body))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -133,6 +137,13 @@ func (b Bridge) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
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.topic = b.topic
|
||||||
not.auth = b.auth
|
not.auth = b.auth
|
||||||
if err = not.Send(b.baseURL); err != nil {
|
if err = not.Send(b.baseURL); err != nil {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO: use skaffold to see why the revision is not present
|
||||||
type FluxNotification struct {
|
type FluxNotification struct {
|
||||||
InvolvedObject struct {
|
InvolvedObject struct {
|
||||||
APIVersion string `json:"apiVersion"`
|
APIVersion string `json:"apiVersion"`
|
||||||
|
@ -44,6 +45,11 @@ func (f FluxHandler) FormatNotification(r io.Reader) (Notification, error) {
|
||||||
return Notification{}, err
|
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,
|
title := fmt.Sprintf("[%s] %s %s/%s.%s", not.Severity, not.Reason,
|
||||||
strings.ToLower(not.InvolvedObject.Kind), not.InvolvedObject.Namespace, not.InvolvedObject.Name)
|
strings.ToLower(not.InvolvedObject.Kind), not.InvolvedObject.Namespace, not.InvolvedObject.Name)
|
||||||
body := not.Message + "\n\n**revision**\n" + not.Metadata.KustomizeToolkitFluxcdIoRevision
|
body := not.Message + "\n\n**revision**\n" + not.Metadata.KustomizeToolkitFluxcdIoRevision
|
||||||
|
|
Loading…
Reference in a new issue