Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter event metadata based on the object group #350

Merged
merged 1 commit into from
Mar 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions internal/server/event_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,35 @@ 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
excludeList := []string{fmt.Sprintf("%s/checksum", group)}

meta := make(map[string]string)

if event.Metadata != nil && len(event.Metadata) > 0 {
for key := range event.Metadata {
for _, k := range excludeList {
if strings.ToLower(k) == strings.ToLower(key) {
delete(event.Metadata, key)
break
}
// For backwards compatibility, include the revision without a group prefix
revisionKey := "revision"
if rev, ok := event.Metadata[revisionKey]; ok {
meta[revisionKey] = rev
}

// Filter other meta based on group prefix, while filtering out excludes
for key, val := range event.Metadata {
if strings.HasPrefix(key, group) && !inList(excludeList, key) {
newKey := strings.TrimPrefix(key, fmt.Sprintf("%s/", group))
meta[newKey] = val
}
}
}

event.Metadata = meta
}

func inList(l []string, i string) bool {
for _, v := range l {
if strings.ToLower(v) == strings.ToLower(i) {
return true
}
}
return false
}