Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 7189: generic restore - don't assume the first volume as the restore volume #7201

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
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
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) 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 @@
}, 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 @@

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
Loading