From 43531c23895408c5f96f95a6450fcc08078d3e8e Mon Sep 17 00:00:00 2001 From: Rewant Soni Date: Thu, 5 Dec 2024 17:54:21 +0530 Subject: [PATCH] controllers: read the storageclusterpeer name from annotation instead of listing the storageclusterpeer, read the name from the annotation on storage-client-mapping config Signed-off-by: Rewant Soni --- controllers/mirroring/mirroring_controller.go | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/controllers/mirroring/mirroring_controller.go b/controllers/mirroring/mirroring_controller.go index 00588b15da..6f5374aa8b 100644 --- a/controllers/mirroring/mirroring_controller.go +++ b/controllers/mirroring/mirroring_controller.go @@ -45,9 +45,10 @@ import ( const ( // internalKey is a special key for storage-client-mapping to establish mirroring between blockPools for internal mode - internalKey = "internal" - mirroringFinalizer = "ocs.openshift.io/mirroring" - clientIDIndexName = "clientID" + internalKey = "internal" + mirroringFinalizer = "ocs.openshift.io/mirroring" + clientIDIndexName = "clientID" + storageClusterPeerAnnotationKey = "ocs.openshift.io/storage-cluster-peer" ) // MirroringReconciler reconciles a Mirroring fields for Ceph Object(s) @@ -184,20 +185,18 @@ func (r *MirroringReconciler) reconcilePhases(clientMappingConfig *corev1.Config } // Fetch the StorageClusterPeer instance - storageClusterPeerList := &ocsv1.StorageClusterPeerList{} - if err := r.list( - storageClusterPeerList, - client.InNamespace(clientMappingConfig.Namespace), - client.Limit(2), - ); err != nil { + if clientMappingConfig.GetAnnotations()[storageClusterPeerAnnotationKey] == "" { + return ctrl.Result{}, fmt.Errorf("storageClusterPeer reference not found") + } + + storageClusterPeer := &ocsv1.StorageClusterPeer{} + storageClusterPeer.Name = clientMappingConfig.GetAnnotations()[storageClusterPeerAnnotationKey] + storageClusterPeer.Namespace = clientMappingConfig.Namespace + + if err := r.get(storageClusterPeer); err != nil { r.log.Error(err, "Failed to get StorageClusterPeer.") return ctrl.Result{}, err } - if len(storageClusterPeerList.Items) != 1 { - return ctrl.Result{}, fmt.Errorf("expected 1 StorageClusterPeer but got %d", len(storageClusterPeerList.Items)) - } - - storageClusterPeer := &storageClusterPeerList.Items[0] if storageClusterPeer.Status.State != ocsv1.StorageClusterPeerStatePeered || storageClusterPeer.Status.PeerInfo == nil ||