Skip to content

Commit

Permalink
Merge pull request #31 from Somefive/fix/add-ignore-namespace-for-lis…
Browse files Browse the repository at this point in the history
…t-managed-cluster

Fix: add ignore namespace for list managed cluster
  • Loading branch information
Somefive committed Nov 18, 2022
2 parents 8026c15 + 2aca265 commit d67ab30
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pkg/apis/cluster/v1alpha1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand All @@ -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
}
}

0 comments on commit d67ab30

Please sign in to comment.