Skip to content

Commit

Permalink
issue 7189: generic restore - don't assume the first volume as the re…
Browse files Browse the repository at this point in the history
…store volume

Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
  • Loading branch information
Lyndon-Li committed Dec 12, 2023
1 parent 06d12de commit 5e71b38
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/7203-Lyndon-Li
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix issue #7189, data mover generic restore - don't assume the first volume as the restore volume
20 changes: 17 additions & 3 deletions pkg/exposer/generic_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (e *genericRestoreExposer) Expose(ctx context.Context, ownerObject corev1.O
func (e *genericRestoreExposer) GetExposed(ctx context.Context, ownerObject corev1.ObjectReference, nodeClient client.Client, nodeName string, timeout time.Duration) (*ExposeResult, error) {
restorePodName := ownerObject.Name
restorePVCName := ownerObject.Name
volumeName := string(ownerObject.UID)

Check warning on line 117 in pkg/exposer/generic_restore.go

View check run for this annotation

Codecov / codecov/patch

pkg/exposer/generic_restore.go#L117

Added line #L117 was not covered by tests

curLog := e.log.WithFields(logrus.Fields{
"owner": ownerObject.Name,
Expand All @@ -127,10 +128,10 @@ func (e *genericRestoreExposer) GetExposed(ctx context.Context, ownerObject core
}, pod)
if err != nil {
if apierrors.IsNotFound(err) {
curLog.WithField("backup pod", restorePodName).Debug("Backup pod is not running in the current node")
curLog.WithField("restore pod", restorePodName).Debug("Restore pod is not running in the current node")

Check warning on line 131 in pkg/exposer/generic_restore.go

View check run for this annotation

Codecov / codecov/patch

pkg/exposer/generic_restore.go#L131

Added line #L131 was not covered by tests
return nil, nil
} else {
return nil, errors.Wrapf(err, "error to get backup pod %s", restorePodName)
return nil, errors.Wrapf(err, "error to get restore pod %s", restorePodName)

Check warning on line 134 in pkg/exposer/generic_restore.go

View check run for this annotation

Codecov / codecov/patch

pkg/exposer/generic_restore.go#L134

Added line #L134 was not covered by tests
}
}

Expand All @@ -143,7 +144,20 @@ func (e *genericRestoreExposer) GetExposed(ctx context.Context, ownerObject core

curLog.WithField("restore pvc", restorePVCName).Info("Restore PVC is bound")

return &ExposeResult{ByPod: ExposeByPod{HostingPod: pod, VolumeName: pod.Spec.Volumes[0].Name}}, nil
i := 0
for i = 0; i < len(pod.Spec.Volumes); i++ {
if pod.Spec.Volumes[i].Name == volumeName {
break

Check warning on line 150 in pkg/exposer/generic_restore.go

View check run for this annotation

Codecov / codecov/patch

pkg/exposer/generic_restore.go#L147-L150

Added lines #L147 - L150 were not covered by tests
}
}

if i == len(pod.Spec.Volumes) {
return nil, errors.Errorf("restore pod %s doesn't have the expected restore volume", pod.Name)
}

Check warning on line 156 in pkg/exposer/generic_restore.go

View check run for this annotation

Codecov / codecov/patch

pkg/exposer/generic_restore.go#L154-L156

Added lines #L154 - L156 were not covered by tests

curLog.WithField("pod", pod.Name).Infof("Restore volume is found in pod at index %v", i)

return &ExposeResult{ByPod: ExposeByPod{HostingPod: pod, VolumeName: volumeName}}, nil

Check warning on line 160 in pkg/exposer/generic_restore.go

View check run for this annotation

Codecov / codecov/patch

pkg/exposer/generic_restore.go#L158-L160

Added lines #L158 - L160 were not covered by tests
}

func (e *genericRestoreExposer) CleanUp(ctx context.Context, ownerObject corev1.ObjectReference) {
Expand Down

0 comments on commit 5e71b38

Please sign in to comment.