Skip to content

Commit

Permalink
Filter event metadata based on the object group
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
  • Loading branch information
stefanprodan committed Mar 23, 2022
1 parent f715f9a commit df09960
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions internal/server/event_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,29 @@ func redactTokenFromError(err error, token string) error {
// TODO: move the metadata filtering function to fluxcd/pkg/runtime/events
// cleanupMetadata removes metadata entries which are not used for alerting
func cleanupMetadata(event *events.Event) {
excludeList := []string{"checksum"}

group := event.InvolvedObject.GetObjectKind().GroupVersionKind().Group
meta := make(map[string]string)
excludeList := []string{fmt.Sprintf("%s/checksum", group)}
if event.Metadata != nil && len(event.Metadata) > 0 {
for key := range event.Metadata {
for key, val := range event.Metadata {
for _, k := range excludeList {
if strings.ToLower(k) == strings.ToLower(key) {
delete(event.Metadata, key)
break
}
}
// filter meta based on group prefix
if strings.HasPrefix(key, group) {
newKey := strings.TrimPrefix(key, fmt.Sprintf("%s/", group))
meta[newKey] = val
}
// for backwards compatibility include the revision without a group prefix
revisionKey := "revision"
if key == revisionKey {
meta[revisionKey] = val
}
}
}

event.Metadata = meta
}

0 comments on commit df09960

Please sign in to comment.