From 301eb2d90956562897e436acffc896f3de938ba9 Mon Sep 17 00:00:00 2001 From: Danil-Grigorev Date: Fri, 6 Dec 2024 15:36:07 +0100 Subject: [PATCH] Use MatchingFields as And logic Signed-off-by: Danil-Grigorev --- .../controllers/topology/cluster/cluster_controller.go | 8 ++++---- internal/webhooks/clusterclass.go | 9 ++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/internal/controllers/topology/cluster/cluster_controller.go b/internal/controllers/topology/cluster/cluster_controller.go index 2d50afa7a050..a3eebd539d92 100644 --- a/internal/controllers/topology/cluster/cluster_controller.go +++ b/internal/controllers/topology/cluster/cluster_controller.go @@ -492,10 +492,10 @@ func (r *Reconciler) clusterClassToCluster(ctx context.Context, o client.Object) if err := r.Client.List( ctx, clusterList, - client.MatchingFieldsSelector{Selector: fields.AndSelectors( - fields.OneTermEqualSelector(index.ClusterClassNameField, clusterClass.Name), - fields.OneTermEqualSelector(index.ClusterClassNamespaceField, clusterClass.Namespace), - )}, + client.MatchingFields{ + index.ClusterClassNameField: clusterClass.Name, + index.ClusterClassNamespaceField: clusterClass.Namespace, + }, ); err != nil { return nil } diff --git a/internal/webhooks/clusterclass.go b/internal/webhooks/clusterclass.go index d89394051356..ab0e842e0400 100644 --- a/internal/webhooks/clusterclass.go +++ b/internal/webhooks/clusterclass.go @@ -25,7 +25,6 @@ import ( corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/validation" @@ -380,10 +379,10 @@ func (webhook *ClusterClass) classNamesFromMPWorkerClass(w clusterv1.WorkersClas func (webhook *ClusterClass) getClustersUsingClusterClass(ctx context.Context, clusterClass *clusterv1.ClusterClass) ([]clusterv1.Cluster, error) { clusters := &clusterv1.ClusterList{} err := webhook.Client.List(ctx, clusters, - client.MatchingFieldsSelector{Selector: fields.AndSelectors( - fields.OneTermEqualSelector(index.ClusterClassNameField, clusterClass.Name), - fields.OneTermEqualSelector(index.ClusterClassNamespaceField, clusterClass.Namespace), - )}, + client.MatchingFields{ + index.ClusterClassNameField: clusterClass.Name, + index.ClusterClassNamespaceField: clusterClass.Namespace, + }, ) if err != nil { return nil, err