From c25f5366e7453cce2b6817c75b1e9f315d04f254 Mon Sep 17 00:00:00 2001 From: yati1998 Date: Thu, 15 Dec 2022 21:12:20 +0530 Subject: [PATCH] replication: reduce RPC calls when VR state is primary Avoid extra RPC calls as request will be requested again for updating the LastSyncTime in the status. The image need to be promoted only one time not always during the reconcile. fixes: #250 Co-authored-by: Madhu Rajanna Signed-off-by: yati1998 --- .../volumereplication_controller.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/controllers/replication.storage/volumereplication_controller.go b/controllers/replication.storage/volumereplication_controller.go index a85f07d8a..a80ad38e5 100644 --- a/controllers/replication.storage/volumereplication_controller.go +++ b/controllers/replication.storage/volumereplication_controller.go @@ -273,7 +273,24 @@ func (r *VolumeReplicationReconciler) Reconcile(ctx context.Context, req ctrl.Re switch instance.Spec.ReplicationState { case replicationv1alpha1.Primary: - replicationErr = r.markVolumeAsPrimary(vr) + // Avoid extra RPC calls as request will be requested again for + // updating the LastSyncTime in the status. The image need to be + // promoted only one time not always during the reconcile. + if instance.Status.State != replicationv1alpha1.PrimaryState { + // enable replication only if its not primary + if err = r.enableReplication(vr); err != nil { + logger.Error(err, "failed to enable replication") + setFailureCondition(instance) + msg := replication.GetMessageFromError(err) + uErr := r.updateReplicationStatus(instance, logger, getCurrentReplicationState(instance), msg) + if uErr != nil { + logger.Error(uErr, "failed to update volumeReplication status", "VRName", instance.Name) + } + + return reconcile.Result{}, err + } + replicationErr = r.markVolumeAsPrimary(vr) + } case replicationv1alpha1.Secondary: // For the first time, mark the volume as secondary and requeue the