From 4907864f4f6770693e5fbbd7ec3ac2d7e1a9468d Mon Sep 17 00:00:00 2001 From: Rewant Soni Date: Tue, 7 Jan 2025 23:19:43 +0530 Subject: [PATCH] controllers: allow failover to complete when peer site is down For failover to complete, we need to reconcile the rbdMirror CR. ocs-client creation was blocking reconcile of rbdMirror, hence move creation of ocs-client to where it is required Signed-off-by: Rewant Soni --- controllers/mirroring/mirroring_controller.go | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/controllers/mirroring/mirroring_controller.go b/controllers/mirroring/mirroring_controller.go index 6f5374aa8b..61325f50ac 100644 --- a/controllers/mirroring/mirroring_controller.go +++ b/controllers/mirroring/mirroring_controller.go @@ -209,12 +209,6 @@ func (r *MirroringReconciler) reconcilePhases(clientMappingConfig *corev1.Config return ctrl.Result{RequeueAfter: 3 * time.Second}, nil } - ocsClient, err := providerClient.NewProviderClient(r.ctx, storageClusterPeer.Spec.ApiEndpoint, util.OcsClientTimeout) - if err != nil { - return ctrl.Result{}, fmt.Errorf("failed to create a new provider client: %v", err) - } - defer ocsClient.Close() - errorOccurred := false if errored := r.reconcileRbdMirror(clientMappingConfig, shouldMirror); errored { @@ -222,7 +216,6 @@ func (r *MirroringReconciler) reconcilePhases(clientMappingConfig *corev1.Config } if errored := r.reconcileBlockPoolMirroring( - ocsClient, clientMappingConfig, storageClusterPeer, shouldMirror, @@ -231,7 +224,6 @@ func (r *MirroringReconciler) reconcilePhases(clientMappingConfig *corev1.Config } if errored := r.reconcileRadosNamespaceMirroring( - ocsClient, clientMappingConfig, storageClusterPeer, shouldMirror, @@ -296,7 +288,6 @@ func (r *MirroringReconciler) reconcileRbdMirror(clientMappingConfig *corev1.Con } func (r *MirroringReconciler) reconcileBlockPoolMirroring( - ocsClient *providerClient.OCSProviderClient, clientMappingConfig *corev1.ConfigMap, storageClusterPeer *ocsv1.StorageClusterPeer, shouldMirror bool, @@ -322,6 +313,13 @@ func (r *MirroringReconciler) reconcileBlockPoolMirroring( } if len(blockPoolByName) > 0 { + ocsClient, err := r.newProviderClient(storageClusterPeer) + if err != nil { + errorOccurred = true + r.log.Error(err, "failed to create providerClient") + return errorOccurred + } + defer ocsClient.Close() // fetch BlockPoolsInfo response, err := ocsClient.GetBlockPoolsInfo( r.ctx, @@ -430,7 +428,6 @@ func (r *MirroringReconciler) reconcileBlockPoolMirroring( } func (r *MirroringReconciler) reconcileRadosNamespaceMirroring( - ocsClient *providerClient.OCSProviderClient, clientMappingConfig *corev1.ConfigMap, storageClusterPeer *ocsv1.StorageClusterPeer, shouldMirror bool, @@ -480,6 +477,13 @@ func (r *MirroringReconciler) reconcileRadosNamespaceMirroring( } if len(peerClientIDs) > 0 { + ocsClient, err := r.newProviderClient(storageClusterPeer) + if err != nil { + errorOccurred = true + r.log.Error(err, "failed to create providerClient") + return errorOccurred + } + defer ocsClient.Close() response, err := ocsClient.GetStorageClientsInfo( r.ctx, storageClusterPeer.Status.PeerInfo.StorageClusterUid, @@ -548,6 +552,14 @@ func (r *MirroringReconciler) reconcileRadosNamespaceMirroring( return errorOccurred } +func (r *MirroringReconciler) newProviderClient(storageClusterPeer *ocsv1.StorageClusterPeer) (*providerClient.OCSProviderClient, error) { + ocsClient, err := providerClient.NewProviderClient(r.ctx, storageClusterPeer.Spec.ApiEndpoint, util.OcsClientTimeout) + if err != nil { + return nil, err + } + return ocsClient, nil +} + func (r *MirroringReconciler) get(obj client.Object) error { return r.Client.Get(r.ctx, client.ObjectKeyFromObject(obj), obj) }