From 2aca2659233fd85493a308604acc1a6b01e50680 Mon Sep 17 00:00:00 2001 From: Yin Da Date: Thu, 17 Nov 2022 12:01:01 +0800 Subject: [PATCH] Fix: add ignore namespace for list managed cluster Signed-off-by: Yin Da --- pkg/apis/cluster/v1alpha1/client.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/apis/cluster/v1alpha1/client.go b/pkg/apis/cluster/v1alpha1/client.go index 0482b82..2b8df1a 100644 --- a/pkg/apis/cluster/v1alpha1/client.go +++ b/pkg/apis/cluster/v1alpha1/client.go @@ -110,7 +110,7 @@ func (c *clusterClient) List(ctx context.Context, options ...client.ListOption) } managedClusters := &ocmclusterv1.ManagedClusterList{} - err = c.Client.List(ctx, managedClusters, clusterSelector{Selector: opts.LabelSelector, RequireCredentialType: false}) + err = c.Client.List(ctx, managedClusters, clusterSelector{Selector: opts.LabelSelector, RequireCredentialType: false, IgnoreNamespace: true}) if err != nil && !meta.IsNoMatchError(err) && !runtime.IsNotRegisteredError(err) { return nil, err } @@ -148,6 +148,7 @@ func (c *clusterClient) List(ctx context.Context, options ...client.ListOption) type clusterSelector struct { Selector labels.Selector RequireCredentialType bool + IgnoreNamespace bool } // ApplyToList applies this configuration to the given list options. @@ -165,5 +166,7 @@ func (m clusterSelector) ApplyToList(opts *client.ListOptions) { r, _ := labels.NewRequirement(clustergatewaycommon.LabelKeyClusterCredentialType, selection.Exists, nil) opts.LabelSelector = opts.LabelSelector.Add(*r) } - opts.Namespace = StorageNamespace + if !m.IgnoreNamespace { + opts.Namespace = StorageNamespace + } }