Skip to content

Commit

Permalink
Rename SelectDestCopyMethod func
Browse files Browse the repository at this point in the history
Signed-off-by: Benamar Mekhissi <[email protected]>
  • Loading branch information
Benamar Mekhissi authored and DF Build Team committed Oct 28, 2023
1 parent 1d0f7ec commit 9b2e0fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
24 changes: 12 additions & 12 deletions controllers/volsync/vshandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ func (v *VSHandler) ReconcileRD(
return nil, err
}

copyMethod, dstPVC, err := v.SelectDestCopyMethod(rdSpec)
dstPVC, err := v.PrecreateDestPVCIfEnabled(rdSpec)
if err != nil {
return nil, err
}

var rd *volsyncv1alpha1.ReplicationDestination

rd, err = v.createOrUpdateRD(rdSpec, pskSecretName, copyMethod, dstPVC)
rd, err = v.createOrUpdateRD(rdSpec, pskSecretName, dstPVC)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -167,7 +167,7 @@ func rdStatusReady(rd *volsyncv1alpha1.ReplicationDestination, log logr.Logger)

func (v *VSHandler) createOrUpdateRD(
rdSpec ramendrv1alpha1.VolSyncReplicationDestinationSpec, pskSecretName string,
copyMethod volsyncv1alpha1.CopyMethodType, dstPVC *string) (*volsyncv1alpha1.ReplicationDestination, error,
dstPVC *string) (*volsyncv1alpha1.ReplicationDestination, error,
) {
l := v.log.WithValues("rdSpec", rdSpec)

Expand Down Expand Up @@ -204,7 +204,7 @@ func (v *VSHandler) createOrUpdateRD(
KeySecret: &pskSecretName,

ReplicationDestinationVolumeOptions: volsyncv1alpha1.ReplicationDestinationVolumeOptions{
CopyMethod: copyMethod,
CopyMethod: volsyncv1alpha1.CopyMethodSnapshot,
Capacity: rdSpec.ProtectedPVC.Resources.Requests.Storage(),
StorageClassName: rdSpec.ProtectedPVC.StorageClassName,
AccessModes: pvcAccessModes,
Expand Down Expand Up @@ -1592,37 +1592,37 @@ func (v *VSHandler) IsRDDataProtected(pvcName string) (bool, error) {
return isLatestImageReady(latestImage), nil
}

func (v *VSHandler) SelectDestCopyMethod(rdSpec ramendrv1alpha1.VolSyncReplicationDestinationSpec,
) (volsyncv1alpha1.CopyMethodType, *string, error) {
func (v *VSHandler) PrecreateDestPVCIfEnabled(rdSpec ramendrv1alpha1.VolSyncReplicationDestinationSpec,
) (*string, error) {
if !v.IsCopyMethodDirect() {
v.log.Info("Using default copyMethod of Snapshot")

return volsyncv1alpha1.CopyMethodSnapshot, nil, nil // use default copyMethod
return nil, nil // use default copyMethod
}

// IF using CopyMethodDirect, then ensure that the PVC exists, otherwise, create it.
err := v.EnsurePVCforDirectCopy(v.ctx, rdSpec)
if err != nil {
return "", nil, err
return nil, err
}

// PVC must not be in-use before creating the RD
inUse, err := v.isPVCInUseByNonRDPod(rdSpec.ProtectedPVC.Name)
if err != nil {
return "", nil, err
return nil, err
}

// It is possible that the PVC becomes in-use at this point (if an app using this PVC is also deployed
// on this cluster). That race condition will be ignored. That would be a user error to deploy the
// same app in the same namespace and on the destination cluster...
if inUse {
return "", nil, fmt.Errorf("pvc %v is mounted by others. Checking later", rdSpec.ProtectedPVC.Name)
return nil, fmt.Errorf("pvc %v is mounted by others. Checking later", rdSpec.ProtectedPVC.Name)
}

v.log.Info(fmt.Sprintf("Using copyMethod of Direct with App PVC %s", rdSpec.ProtectedPVC.Name))
v.log.Info(fmt.Sprintf("Using App PVC %s for syncing directly to it", rdSpec.ProtectedPVC.Name))
// Using the application PVC for syncing from source to destination and save a snapshot
// everytime a sync is successful
return volsyncv1alpha1.CopyMethodSnapshot, &rdSpec.ProtectedPVC.Name, nil
return &rdSpec.ProtectedPVC.Name, nil
}

func (v *VSHandler) IsCopyMethodDirect() bool {
Expand Down
5 changes: 2 additions & 3 deletions controllers/volsync/vshandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,11 +655,10 @@ var _ = Describe("VolSync_Handler", func() {
vsHandler = volsync.NewVSHandler(ctx, k8sClient, logger, owner, asyncSpec, "none", "Direct")
})

It("SelectDestCopyMethod() should return CopyMethod Snapshot and App PVC name", func() {
cpyMethod, dstPVC, err := vsHandler.SelectDestCopyMethod(rdSpec)
It("PrecreateDestPVCIfEnabled() should return CopyMethod Snapshot and App PVC name", func() {
dstPVC, err := vsHandler.PrecreateDestPVCIfEnabled(rdSpec)
Expect(err).NotTo(HaveOccurred())

Expect(cpyMethod).To(Equal(volsyncv1alpha1.CopyMethodSnapshot))
Expect(*dstPVC).To(Equal(rdSpec.ProtectedPVC.Name))
pvc := &corev1.PersistentVolumeClaim{}
Eventually(func() error {
Expand Down

0 comments on commit 9b2e0fb

Please sign in to comment.