diff --git a/pkg/kor/clusterroles.go b/pkg/kor/clusterroles.go index 8c2fbd4f..ee3dd6dc 100644 --- a/pkg/kor/clusterroles.go +++ b/pkg/kor/clusterroles.go @@ -44,9 +44,6 @@ func retrieveUsedClusterRoles(clientset kubernetes.Interface, filterOpts *filter usedClusterRoles := make(map[string]bool) for _, rb := range roleBindingsAllNameSpaces { - if pass, _ := filter.Run(filterOpts); pass { - continue - } usedClusterRoles[rb.RoleRef.Name] = true if rb.RoleRef.Kind == "ClusterRole" { usedClusterRoles[rb.RoleRef.Name] = true @@ -61,9 +58,6 @@ func retrieveUsedClusterRoles(clientset kubernetes.Interface, filterOpts *filter } for _, crb := range clusterRoleBindings.Items { - if pass, _ := filter.Run(filterOpts); pass { - continue - } usedClusterRoles[crb.RoleRef.Name] = true } diff --git a/pkg/kor/finalizers.go b/pkg/kor/finalizers.go index ac6cab59..7c80598a 100644 --- a/pkg/kor/finalizers.go +++ b/pkg/kor/finalizers.go @@ -47,7 +47,7 @@ func retrievePendingDeletionResources(resourceTypes []*metav1.APIResourceList, d continue } for _, item := range resourceList.Items { - if pass, _ := filter.Run(filterOpts); pass { + if pass, _ := filter.SetObject(&item).Run(filterOpts); pass { continue } if CheckFinalizers(item.GetFinalizers(), item.GetDeletionTimestamp()) { diff --git a/pkg/kor/ingresses.go b/pkg/kor/ingresses.go index 47dba188..f73b070d 100644 --- a/pkg/kor/ingresses.go +++ b/pkg/kor/ingresses.go @@ -36,7 +36,7 @@ func retrieveUsedIngress(clientset kubernetes.Interface, namespace string, filte usedIngresses := []string{} for _, ingress := range ingresses.Items { - if pass, _ := filter.Run(filterOpts); pass { + if pass, _ := filter.SetObject(&ingress).Run(filterOpts); pass { continue } diff --git a/pkg/kor/replicaset.go b/pkg/kor/replicaset.go index 6040be4d..1dab7985 100644 --- a/pkg/kor/replicaset.go +++ b/pkg/kor/replicaset.go @@ -22,7 +22,7 @@ func processNamespaceReplicaSets(clientset kubernetes.Interface, namespace strin var unusedReplicaSetNames []ResourceInfo for _, replicaSet := range replicaSetList.Items { - if pass, _ := filter.Run(filterOpts); pass { + if pass, _ := filter.SetObject(&replicaSet).Run(filterOpts); pass { continue } diff --git a/pkg/kor/roles.go b/pkg/kor/roles.go index 638ed712..3fe837ad 100644 --- a/pkg/kor/roles.go +++ b/pkg/kor/roles.go @@ -18,7 +18,7 @@ import ( //go:embed exceptions/roles/roles.json var rolesConfig []byte -func retrieveUsedRoles(clientset kubernetes.Interface, namespace string, filterOpts *filters.Options) ([]string, error) { +func retrieveUsedRoles(clientset kubernetes.Interface, namespace string) ([]string, error) { // Get a list of all role bindings in the specified namespace roleBindings, err := clientset.RbacV1().RoleBindings(namespace).List(context.TODO(), metav1.ListOptions{}) if err != nil { @@ -27,10 +27,6 @@ func retrieveUsedRoles(clientset kubernetes.Interface, namespace string, filterO usedRoles := make(map[string]bool) for _, rb := range roleBindings.Items { - if pass, _ := filter.Run(filterOpts); pass { - continue - } - usedRoles[rb.RoleRef.Name] = true } @@ -78,7 +74,7 @@ func retrieveRoleNames(clientset kubernetes.Interface, namespace string, filterO } func processNamespaceRoles(clientset kubernetes.Interface, namespace string, filterOpts *filters.Options) ([]ResourceInfo, error) { - usedRoles, err := retrieveUsedRoles(clientset, namespace, filterOpts) + usedRoles, err := retrieveUsedRoles(clientset, namespace) if err != nil { return nil, err } diff --git a/pkg/kor/roles_test.go b/pkg/kor/roles_test.go index b847f33d..05143bf0 100644 --- a/pkg/kor/roles_test.go +++ b/pkg/kor/roles_test.go @@ -63,7 +63,7 @@ func createTestRoles(t *testing.T) *fake.Clientset { func TestRetrieveUsedRoles(t *testing.T) { clientset := createTestRoles(t) - usedRoles, err := retrieveUsedRoles(clientset, testNamespace, &filters.Options{}) + usedRoles, err := retrieveUsedRoles(clientset, testNamespace) if err != nil { t.Errorf("Expected no error, got %v", err) } diff --git a/pkg/kor/services.go b/pkg/kor/services.go index 4efc1ca2..13e09036 100644 --- a/pkg/kor/services.go +++ b/pkg/kor/services.go @@ -31,7 +31,7 @@ func processNamespaceServices(clientset kubernetes.Interface, namespace string, var endpointsWithoutSubsets []ResourceInfo for _, endpoints := range endpointsList.Items { - if pass, _ := filter.Run(filterOpts); pass { + if pass, _ := filter.SetObject(&endpoints).Run(filterOpts); pass { continue } diff --git a/pkg/kor/statefulsets.go b/pkg/kor/statefulsets.go index 29b86ef9..0bc88415 100644 --- a/pkg/kor/statefulsets.go +++ b/pkg/kor/statefulsets.go @@ -22,7 +22,7 @@ func processNamespaceStatefulSets(clientset kubernetes.Interface, namespace stri var statefulSetsWithoutReplicas []ResourceInfo for _, statefulSet := range statefulSetsList.Items { - if pass, _ := filter.Run(filterOpts); pass { + if pass, _ := filter.SetObject(&statefulSet).Run(filterOpts); pass { continue }