Skip to content

fix: correct snapshot path when using share parameter #461

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

Merged
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
16 changes: 4 additions & 12 deletions pkg/nfs/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,10 @@ type nfsSnapshot struct {
src string
}

func (snap nfsSnapshot) archiveSubPath() string {
return snap.uuid
}

func (snap nfsSnapshot) archiveName() string {
return fmt.Sprintf("%v.tar.gz", snap.src)
}

func (snap nfsSnapshot) archivePath() string {
return filepath.Join(snap.archiveSubPath(), snap.archiveName())
}

// Ordering of elements in the CSI volume id.
// ID is of the form {server}/{baseDir}/{subDir}.
// TODO: This volume id format limits baseDir and
Expand Down Expand Up @@ -331,7 +323,7 @@ func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
klog.Warningf("failed to unmount snapshot nfs server: %v", err)
}
}()
snapInternalVolPath := filepath.Join(getInternalVolumePath(cs.Driver.workingMountDir, snapVol), snapshot.archiveSubPath())
snapInternalVolPath := getInternalVolumePath(cs.Driver.workingMountDir, snapVol)
if err = os.MkdirAll(snapInternalVolPath, 0777); err != nil {
return nil, status.Errorf(codes.Internal, "failed to make subdirectory: %v", err)
}
Expand Down Expand Up @@ -409,7 +401,7 @@ func (cs *ControllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS
}()

// delete snapshot archive
internalVolumePath := filepath.Join(getInternalVolumePath(cs.Driver.workingMountDir, vol), snap.archiveSubPath())
internalVolumePath := getInternalVolumePath(cs.Driver.workingMountDir, vol)
klog.V(2).Infof("Removing snapshot archive at %v", internalVolumePath)
if err = os.RemoveAll(internalVolumePath); err != nil {
return nil, status.Errorf(codes.Internal, "failed to delete subdirectory: %v", err.Error())
Expand Down Expand Up @@ -503,7 +495,7 @@ func (cs *ControllerServer) copyFromSnapshot(ctx context.Context, req *csi.Creat
}()

// untar snapshot archive to dst path
snapPath := filepath.Join(getInternalVolumePath(cs.Driver.workingMountDir, snapVol), snap.archivePath())
snapPath := filepath.Join(getInternalVolumePath(cs.Driver.workingMountDir, snapVol), snap.archiveName())
dstPath := getInternalVolumePath(cs.Driver.workingMountDir, dstVol)
klog.V(2).Infof("copy volume from snapshot %v -> %v", snapPath, dstPath)
out, err := exec.Command("tar", "-xzvf", snapPath, "-C", dstPath).CombinedOutput()
Expand Down Expand Up @@ -803,7 +795,7 @@ func volumeFromSnapshot(snap *nfsSnapshot) *nfsVolume {
id: snap.id,
server: snap.server,
baseDir: snap.baseDir,
subDir: snap.baseDir,
subDir: snap.uuid,
uuid: snap.uuid,
}
}
4 changes: 2 additions & 2 deletions pkg/nfs/controllerserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,10 +742,10 @@ func TestCopyVolume(t *testing.T) {
uuid: "dst-pv-name",
},
prepare: func() error {
if err := os.MkdirAll("/tmp/snapshot-name/share/snapshot-name/", 0777); err != nil {
if err := os.MkdirAll("/tmp/snapshot-name/snapshot-name", 0777); err != nil {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have been more careful when writing unit tests, this case was clearly showing the bug reported by #459 and I just didn't realize it during #430

return err
}
file, err := os.Create("/tmp/snapshot-name/share/snapshot-name/src-pv-name.tar.gz")
file, err := os.Create("/tmp/snapshot-name/snapshot-name/src-pv-name.tar.gz")
if err != nil {
return err
}
Expand Down