Skip to content

Commit

Permalink
chore: try to do a lookup by namespace, kind & name when invovled object
Browse files Browse the repository at this point in the history
UID is not a valid UUID
  • Loading branch information
adityathebe committed Jun 21, 2024
1 parent 81c67ae commit a852c7e
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions scrapers/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/google/uuid"
"github.com/samber/lo"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
Expand Down Expand Up @@ -289,18 +290,25 @@ func ExtractResults(ctx api.ScrapeContext, config v1.Kubernetes, objs []*unstruc
continue
}

if _, err := uuid.Parse(string(event.InvolvedObject.UID)); err != nil {
ctx.Logger.V(3).Infof("skipping event (reason=%s, message=%s) because the involved object ID is not a valid UUID: %s", event.Reason, event.Message, event.InvolvedObject.UID)
continue
}

if config.Event.Exclusions.Filter(event) {
ctx.Logger.V(4).Infof("excluding event object %s/%s/%s: %s",
event.InvolvedObject.Namespace, event.InvolvedObject.Name,
event.InvolvedObject.Kind, event.Reason)
continue
}

if _, err := uuid.Parse(string(event.InvolvedObject.UID)); err != nil {
ids, err := db.FindConfigIDsByNamespaceNameClass(ctx.DutyContext(), event.InvolvedObject.Namespace, event.InvolvedObject.Name, event.InvolvedObject.Kind)
if err != nil {
return results.Errorf(err, "failed to get config IDs for object %s/%s/%s", event.InvolvedObject.Namespace, event.InvolvedObject.Name, event.InvolvedObject.Kind)
} else if len(ids) == 0 {
ctx.Logger.V(3).Infof("skipping event (reason=%s, message=%s) because the involved object ID is not a valid UUID: %s", event.Reason, event.Message, event.InvolvedObject.UID)
continue
}

event.InvolvedObject.UID = types.UID(ids[0].String())
}

change := getChangeFromEvent(event, config.Event.SeverityKeywords)
if change != nil {
changeTypExclusion, changeSeverityExclusion, err := getObjectChangeExclusionAnnotations(ctx, string(event.InvolvedObject.UID), objChangeExclusionByType, objChangeExclusionBySeverity)
Expand Down

0 comments on commit a852c7e

Please sign in to comment.