Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Avoid calling EnableReplication and markVolumeAsSecondary repeatedly #126

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions controllers/volumereplication_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -235,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:
Expand Down