1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

use the unstructured list instead of interface type (#4210)

Signed-off-by: prateekpandey14 <prateek.pandey@nirmata.com>
This commit is contained in:
Prateek Pandey 2022-07-12 20:37:40 +05:30 committed by GitHub
parent 3e2894b6fa
commit c0cc4b781c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -42,7 +42,7 @@ func MergeResources(a, b map[string]unstructured.Unstructured) {
}
}
func (pc *PolicyController) getResourceList(kind, namespace string, labelSelector *metav1.LabelSelector, log logr.Logger) interface{} {
func (pc *PolicyController) getResourceList(kind, namespace string, labelSelector *metav1.LabelSelector, log logr.Logger) *unstructured.UnstructuredList {
resourceList, err := pc.client.ListResource("", kind, namespace, labelSelector)
if err != nil {
log.Error(err, "failed to list resources", "kind", kind, "namespace", namespace)
@ -64,18 +64,9 @@ func (pc *PolicyController) getResourcesPerNamespace(kind string, namespace stri
}
list := pc.getResourceList(kind, namespace, rule.MatchResources.Selector, log)
switch typedList := list.(type) {
case []*unstructured.Unstructured:
for _, r := range typedList {
if pc.match(*r, rule) {
resourceMap[string(r.GetUID())] = *r
}
}
case *unstructured.UnstructuredList:
for _, r := range typedList.Items {
if pc.match(r, rule) {
resourceMap[string(r.GetUID())] = r
}
for _, r := range list.Items {
if pc.match(r, rule) {
resourceMap[string(r.GetUID())] = r
}
}