use the unstructured list instead of interface type
@@ -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,20 +64,11 @@ 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 {
+ for _, r := range list.Items {
if pc.match(r, rule) {
resourceMap[string(r.GetUID())] = r
}
}
- }
// skip resources to be filtered
excludeResources(resourceMap, rule.ExcludeResources.ResourceDescription, pc.configHandler, log)
