Skip to content

Commit

Permalink
controllers: disable mirroring when peer cluster is down
Browse files Browse the repository at this point in the history
allow the mirroring to be disabled when the peer site is down

Signed-off-by: Rewant Soni <[email protected]>
  • Loading branch information
rewantsoni committed Jan 9, 2025
1 parent a8aa21c commit 5ae3c91
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions controllers/mirroring/mirroring_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,13 @@ 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 {
errorOccurred = true
}

if errored := r.reconcileBlockPoolMirroring(
ocsClient,
clientMappingConfig,
storageClusterPeer,
shouldMirror,
Expand All @@ -231,7 +224,6 @@ func (r *MirroringReconciler) reconcilePhases(clientMappingConfig *corev1.Config
}

if errored := r.reconcileRadosNamespaceMirroring(
ocsClient,
clientMappingConfig,
storageClusterPeer,
shouldMirror,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -430,7 +428,6 @@ func (r *MirroringReconciler) reconcileBlockPoolMirroring(
}

func (r *MirroringReconciler) reconcileRadosNamespaceMirroring(
ocsClient *providerClient.OCSProviderClient,
clientMappingConfig *corev1.ConfigMap,
storageClusterPeer *ocsv1.StorageClusterPeer,
shouldMirror bool,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 5ae3c91

Please sign in to comment.