From 48fc87a663c9cc5b2f5a56ddcde925c0602da64d Mon Sep 17 00:00:00 2001 From: Takumi Sue <23391543+mikutas@users.noreply.github.com> Date: Wed, 6 Mar 2024 00:19:02 +0900 Subject: [PATCH] Fix trying to list cluster-level resources (#1004) when namespace specified close #984 --- pkg/kube/resources.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/kube/resources.go b/pkg/kube/resources.go index 585067612..e2d43954b 100644 --- a/pkg/kube/resources.go +++ b/pkg/kube/resources.go @@ -336,6 +336,10 @@ func CreateResourceProviderFromAPI(ctx context.Context, kube kubernetes.Interfac logrus.Warnf("Error retrieving mapping of Kind %s because of error: %v", kind, err) return nil, err } + if c.Namespace != "" && mapping.Scope.Name() != meta.RESTScopeNameNamespace { + logrus.Infof("Skipping %s because of auditing specific namespace", mapping.GroupVersionKind) + continue + } logrus.Info("Loading " + kind) objects, err := dynamic.Resource(mapping.Resource).Namespace(c.Namespace).List(ctx, metav1.ListOptions{})