mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-28 02:18:15 +00:00
fix: deletion of reports not belonging to kyverno (#5194)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
0e1d2cae05
commit
076f2c3c49
2 changed files with 15 additions and 2 deletions
|
@ -7,6 +7,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
||||
kyvernov1alpha2 "github.com/kyverno/kyverno/api/kyverno/v1alpha2"
|
||||
policyreportv1alpha2 "github.com/kyverno/kyverno/api/policyreport/v1alpha2"
|
||||
"github.com/kyverno/kyverno/pkg/autogen"
|
||||
|
@ -298,7 +299,9 @@ func (c *controller) getPolicyReports(ctx context.Context, namespace string) ([]
|
|||
return nil, err
|
||||
}
|
||||
for i := range list.Items {
|
||||
reports = append(reports, &list.Items[i])
|
||||
if controllerutils.CheckLabel(&list.Items[i], kyvernov1.LabelAppManagedBy, kyvernov1.ValueKyvernoApp) {
|
||||
reports = append(reports, &list.Items[i])
|
||||
}
|
||||
}
|
||||
} else {
|
||||
list, err := c.client.Wgpolicyk8sV1alpha2().PolicyReports(namespace).List(ctx, metav1.ListOptions{})
|
||||
|
@ -306,7 +309,9 @@ func (c *controller) getPolicyReports(ctx context.Context, namespace string) ([]
|
|||
return nil, err
|
||||
}
|
||||
for i := range list.Items {
|
||||
reports = append(reports, &list.Items[i])
|
||||
if controllerutils.CheckLabel(&list.Items[i], kyvernov1.LabelAppManagedBy, kyvernov1.ValueKyvernoApp) {
|
||||
reports = append(reports, &list.Items[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
return reports, nil
|
||||
|
|
|
@ -15,6 +15,14 @@ func SetLabel(obj metav1.Object, key, value string) map[string]string {
|
|||
return labels
|
||||
}
|
||||
|
||||
func CheckLabel(obj metav1.Object, key, value string) bool {
|
||||
labels := obj.GetLabels()
|
||||
if labels == nil {
|
||||
return false
|
||||
}
|
||||
return labels[key] == value
|
||||
}
|
||||
|
||||
func SetAnnotation(obj metav1.Object, key, value string) {
|
||||
annotations := obj.GetAnnotations()
|
||||
if annotations == nil {
|
||||
|
|
Loading…
Add table
Reference in a new issue