From 603f70a53e53cb9cf7c916808b027f5208407869 Mon Sep 17 00:00:00 2001 From: Frank Jogeleit Date: Fri, 17 Nov 2023 09:28:33 +0100 Subject: [PATCH] map scope to result resources Signed-off-by: Frank Jogeleit --- pkg/kubernetes/queue.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/kubernetes/queue.go b/pkg/kubernetes/queue.go index 787192c0..fd937152 100644 --- a/pkg/kubernetes/queue.go +++ b/pkg/kubernetes/queue.go @@ -96,7 +96,7 @@ func (q *Queue) processNextItem() bool { defer q.lock.Unlock() q.cache.Delete(key) }() - q.debouncer.Add(report.LifecycleEvent{Type: report.Deleted, PolicyReport: polr}) + q.debouncer.Add(report.LifecycleEvent{Type: report.Deleted, PolicyReport: mapResource(polr)}) return true } @@ -120,6 +120,19 @@ func (q *Queue) processNextItem() bool { return true } +// each result needs to know its resource it belongs to, to generate internal unique IDs +func mapResource(polr pr.ReportInterface) pr.ReportInterface { + for _, r := range polr.GetResults() { + scope := polr.GetScope() + + if len(r.Resources) == 0 && scope != nil { + r.Resources = append(r.Resources, *scope) + } + } + + return polr +} + func (q *Queue) handleErr(err error, key interface{}) { if err == nil { q.queue.Forget(key)