From fc53e3ce096f6ad849dd4b14157cb0bd3ea6ce07 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Tue, 16 Nov 2021 11:46:47 +0530 Subject: [PATCH 1/2] ctrl: EnableReplication only for primary state call EnableVolumeReplication only if the request is to mark the image as primary Signed-off-by: Madhu Rajanna --- controllers/volumereplication_controller.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/controllers/volumereplication_controller.go b/controllers/volumereplication_controller.go index a1eb21a6..ef5551f7 100644 --- a/controllers/volumereplication_controller.go +++ b/controllers/volumereplication_controller.go @@ -199,19 +199,21 @@ func (r *VolumeReplicationReconciler) Reconcile(ctx context.Context, req ctrl.Re return reconcile.Result{}, err } - // enable replication on every reconcile - if err = r.enableReplication(logger, volumeHandle, replicationHandle, parameters, secret); err != nil { - logger.Error(err, "failed to enable replication") - setFailureCondition(instance) - _ = r.updateReplicationStatus(instance, logger, getCurrentReplicationState(instance), err.Error()) - return reconcile.Result{}, err - } - var replicationErr error var requeueForResync bool switch instance.Spec.ReplicationState { case replicationv1alpha1.Primary: + // Send EnableVolumeReplication request only if the request is new or a + // failed requeue request. + if instance.Status.State == "" || instance.Status.State == replicationv1alpha1.UnknownState { + if err = r.enableReplication(logger, volumeHandle, replicationHandle, parameters, secret); err != nil { + logger.Error(err, "failed to enable replication") + setFailureCondition(instance) + _ = r.updateReplicationStatus(instance, logger, getCurrentReplicationState(instance), err.Error()) + return reconcile.Result{}, err + } + } replicationErr = r.markVolumeAsPrimary(instance, logger, volumeHandle, replicationHandle, parameters, secret) case replicationv1alpha1.Secondary: From 8caf81af5c5c3a234eccc6d1da349ce6d71debae Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Tue, 16 Nov 2021 12:00:04 +0530 Subject: [PATCH 2/2] ctrl: Demote volume if the state is primary Demote the volume only once if the instance state is primary. Signed-off-by: Madhu Rajanna --- controllers/volumereplication_controller.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/controllers/volumereplication_controller.go b/controllers/volumereplication_controller.go index ef5551f7..db7a7caf 100644 --- a/controllers/volumereplication_controller.go +++ b/controllers/volumereplication_controller.go @@ -237,11 +237,8 @@ func (r *VolumeReplicationReconciler) Reconcile(ctx context.Context, req ctrl.Re }, nil } } else { - replicationErr = r.markVolumeAsSecondary(instance, logger, volumeHandle, replicationHandle, parameters, secret) - // resync volume if successfully marked Secondary - if replicationErr == nil { - requeueForResync, replicationErr = r.resyncVolume(instance, logger, volumeHandle, replicationHandle, parameters, secret) - } + // resync volume as the volume is already marked Secondary + requeueForResync, replicationErr = r.resyncVolume(instance, logger, volumeHandle, replicationHandle, parameters, secret) } case replicationv1alpha1.Resync: