Skip to content

Commit

Permalink
Merge pull request #7201 from Lyndon-Li/issue-fix-7189
Browse files Browse the repository at this point in the history
Issue 7189: generic restore - don't assume the first volume as the restore volume
  • Loading branch information
Lyndon-Li authored Dec 12, 2023
2 parents 2bd9bf2 + cf7d27c commit 5f14628
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/7201-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)

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")
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)
}
}

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
}
}

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

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
}

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

0 comments on commit 5f14628

Please sign in to comment.