Skip to content

Commit

Permalink
simplify notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
slamdev committed May 25, 2020
1 parent 3c4f23f commit 9c1a4c1
Showing 1 changed file with 2 additions and 36 deletions.
38 changes: 2 additions & 36 deletions pkg/notifier/notifier.go
Original file line number Diff line number Diff line change
@@ -1,45 +1,11 @@
package notifier

import (
"fmt"
"github.com/fluxcd/flux/pkg/event"
"github.com/sirupsen/logrus"
"strings"
)

func notify(e event.Event) {
switch e.Type {
case event.EventSync:
processSyncEvent(e)
break
case event.EventCommit:
processCommitEvent(e)
default:
logrus.WithField("event", e).Error("unknown event type")
}
logrus.WithField("event-obj", e).
WithField("event-str", e.String()).
Debug("received event")
}

func processCommitEvent(e event.Event) {
metadata := e.Metadata.(*event.CommitEventMetadata)
logrus.WithField(e.Type, e.ServiceIDs).
WithField("spec", metadata.Spec.Spec).
Info("received event")
}

func processSyncEvent(e event.Event) {
metadata := e.Metadata.(*event.SyncEventMetadata)
logrus.WithField(e.Type, e.ServiceIDs).
WithField("errors", formatErrors(metadata.Errors)).
Info("received event")
}

func formatErrors(errors []event.ResourceError) string {
list := make([]string, len(errors))
for i := range errors {
list[i] = fmt.Sprintf("%s: %s", errors[i].ID, errors[i].Error)
}
return strings.Join(list, ",")
logrus.WithField("event", e.String()).Info("received event")
logrus.WithField("event", e).Debug("received event")
}

0 comments on commit 9c1a4c1

Please sign in to comment.