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

fix: add config data to kubernetes events for post processing #1091

Merged
merged 1 commit into from
Oct 18, 2024
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
12 changes: 12 additions & 0 deletions scrapers/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/Jeffail/gabs/v2"
"github.com/flanksource/commons/collections"
"github.com/flanksource/commons/logger"
"github.com/flanksource/duty/models"
"github.com/google/uuid"
"github.com/samber/lo"
Expand Down Expand Up @@ -220,13 +221,23 @@ func ExtractResults(ctx *KubernetesContext, objs []*unstructured.Unstructured) v
continue
}

var configData map[string]any
if uid, err := ctx.FindInvolvedConfigID(event); err != nil {
results.Errorf(err, "")
continue
} else if uid == uuid.Nil {
continue
} else {
event.InvolvedObject.UID = types.UID(uid.String())
confObj, err := ctx.TempCache().Get(ctx.ScrapeContext, uid.String())
if err != nil {
// TODO: Should this gointo results.Errorf
logger.Warnf("unable to find config[%s] related to event: %v", uid, err)
}
if confObj != nil && confObj.Config != nil {
// Also, this won't work for resources we ignore
configData, _ = confObj.ConfigJSONStringMap()
}
}

change := getChangeFromEvent(event, ctx.config.Event.SeverityKeywords)
Expand All @@ -241,6 +252,7 @@ func ExtractResults(ctx *KubernetesContext, objs []*unstructured.Unstructured) v
changeResults = append(changeResults, v1.ScrapeResult{
BaseScraper: ctx.config.BaseScraper,
Changes: []v1.ChangeResult{*change},
Config: configData,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yashmehrotra why did we add config to changes? we have a config == nil check to distinguish between results that carry config item vs results with only changes.

seeing a lot of errors during extractAttributes because all changes results have an empty ID.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adityathebe We have change transformations and exclusions which depend on config being there in cel env

Can you create an issue for the error and assign it to me ? I'll add a check to handle those

})
}

Expand Down
Loading