From 7007f0155d7d786ad79d0159d538132a38aba50c 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 continue reconcile for local resources even if the peer site is down Signed-off-by: Rewant Soni (cherry picked from commit e7121c8e4068615d2df0fb1621f5233bf469a07c) --- controllers/mirroring/mirroring_controller.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/controllers/mirroring/mirroring_controller.go b/controllers/mirroring/mirroring_controller.go index 6f5374aa8b..74a5880831 100644 --- a/controllers/mirroring/mirroring_controller.go +++ b/controllers/mirroring/mirroring_controller.go @@ -16,8 +16,6 @@ package mirroring import ( "context" "fmt" - "golang.org/x/exp/maps" - "k8s.io/utils/ptr" "slices" "time" @@ -29,10 +27,12 @@ import ( "github.com/go-logr/logr" rookCephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" + "golang.org/x/exp/maps" corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" + "k8s.io/utils/ptr" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/builder" "sigs.k8s.io/controller-runtime/pkg/client" @@ -209,13 +209,15 @@ func (r *MirroringReconciler) reconcilePhases(clientMappingConfig *corev1.Config return ctrl.Result{RequeueAfter: 3 * time.Second}, nil } + errorOccurred := false + 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) + r.log.Error(err, "failed to create a new provider client") + errorOccurred = true + } else if ocsClient != nil { + defer ocsClient.Close() } - defer ocsClient.Close() - - errorOccurred := false if errored := r.reconcileRbdMirror(clientMappingConfig, shouldMirror); errored { errorOccurred = true @@ -321,7 +323,7 @@ func (r *MirroringReconciler) reconcileBlockPoolMirroring( blockPoolByName[cephBlockPool.Name] = cephBlockPool } - if len(blockPoolByName) > 0 { + if len(blockPoolByName) > 0 && ocsClient != nil { // fetch BlockPoolsInfo response, err := ocsClient.GetBlockPoolsInfo( r.ctx, @@ -479,7 +481,7 @@ func (r *MirroringReconciler) reconcileRadosNamespaceMirroring( peerClientIDs = append(peerClientIDs, peerClientID) } - if len(peerClientIDs) > 0 { + if len(peerClientIDs) > 0 && ocsClient != nil { response, err := ocsClient.GetStorageClientsInfo( r.ctx, storageClusterPeer.Status.PeerInfo.StorageClusterUid,