1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

fix: fetch only adopted ephemeral report (#10148)

Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com>
This commit is contained in:
Vishal Choudhary 2024-04-30 20:47:24 +05:30 committed by GitHub
parent c9d821ee72
commit e66a550560
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -202,7 +202,7 @@ func (c *controller) createVapMap() (sets.Set[string], error) {
return results, nil
}
func (c *controller) findEphemeralReports(ctx context.Context, namespace, name string) ([]kyvernov1alpha2.ReportInterface, error) {
func (c *controller) findOwnedEphemeralReports(ctx context.Context, namespace, name string) ([]kyvernov1alpha2.ReportInterface, error) {
selector, err := reportutils.SelectorResourceUidEquals(types.UID(name))
if err != nil {
return nil, err
@ -219,8 +219,10 @@ func (c *controller) findEphemeralReports(ctx context.Context, namespace, name s
return nil, err
}
for _, report := range reports.Items {
report := report
results = append(results, &report)
if len(report.OwnerReferences) != 0 {
report := report
results = append(results, &report)
}
}
} else {
reports, err := c.client.ReportsV1().EphemeralReports(namespace).List(ctx, metav1.ListOptions{
@ -233,8 +235,10 @@ func (c *controller) findEphemeralReports(ctx context.Context, namespace, name s
return nil, err
}
for _, report := range reports.Items {
report := report
results = append(results, &report)
if len(report.OwnerReferences) != 0 {
report := report
results = append(results, &report)
}
}
}
return results, nil
@ -383,11 +387,11 @@ func (c *controller) backReconcile(ctx context.Context, logger logr.Logger, _, n
if err != nil {
return err
}
if report == nil {
if report != nil {
reports = append(reports, report)
}
// get ephemeral reports
ephemeralReports, err := c.findEphemeralReports(ctx, namespace, name)
ephemeralReports, err := c.findOwnedEphemeralReports(ctx, namespace, name)
if err != nil {
if !apierrors.IsNotFound(err) {
return err