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,