mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-28 02:18:15 +00:00
fix: clean background scan reports (#4908)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
33b5bb2a8a
commit
7cef1c00d9
1 changed files with 14 additions and 0 deletions
|
@ -355,7 +355,21 @@ func (c *controller) reconcile(ctx context.Context, logger logr.Logger, key, nam
|
|||
// try to find resource from the cache
|
||||
uid := types.UID(name)
|
||||
resource, gvk, exists := c.metadataCache.GetResourceHash(uid)
|
||||
// if the resource is not present it means we shouldn't have a report for it
|
||||
// we can delete the report, we will recreate one if the resource come back
|
||||
if !exists {
|
||||
report, err := c.getMeta(namespace, name)
|
||||
if err != nil {
|
||||
if !apierrors.IsNotFound(err) {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if report.GetNamespace() == "" {
|
||||
return c.kyvernoClient.KyvernoV1alpha2().ClusterBackgroundScanReports().Delete(ctx, report.GetName(), metav1.DeleteOptions{})
|
||||
} else {
|
||||
return c.kyvernoClient.KyvernoV1alpha2().BackgroundScanReports(report.GetNamespace()).Delete(ctx, report.GetName(), metav1.DeleteOptions{})
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
// try to find report from the cache
|
||||
|
|
Loading…
Add table
Reference in a new issue