Skip to content

Commit 8eb52e1

Browse files
authored
Merge pull request #461 from wozniakjan/fix_snapshot_subpath
bugfix: correct snapshot path when using share parameter
2 parents dc621b8 + cb330e6 commit 8eb52e1

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

pkg/nfs/controllerserver.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,10 @@ type nfsSnapshot struct {
7878
src string
7979
}
8080

81-
func (snap nfsSnapshot) archiveSubPath() string {
82-
return snap.uuid
83-
}
84-
8581
func (snap nfsSnapshot) archiveName() string {
8682
return fmt.Sprintf("%v.tar.gz", snap.src)
8783
}
8884

89-
func (snap nfsSnapshot) archivePath() string {
90-
return filepath.Join(snap.archiveSubPath(), snap.archiveName())
91-
}
92-
9385
// Ordering of elements in the CSI volume id.
9486
// ID is of the form {server}/{baseDir}/{subDir}.
9587
// TODO: This volume id format limits baseDir and
@@ -331,7 +323,7 @@ func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
331323
klog.Warningf("failed to unmount snapshot nfs server: %v", err)
332324
}
333325
}()
334-
snapInternalVolPath := filepath.Join(getInternalVolumePath(cs.Driver.workingMountDir, snapVol), snapshot.archiveSubPath())
326+
snapInternalVolPath := getInternalVolumePath(cs.Driver.workingMountDir, snapVol)
335327
if err = os.MkdirAll(snapInternalVolPath, 0777); err != nil {
336328
return nil, status.Errorf(codes.Internal, "failed to make subdirectory: %v", err)
337329
}
@@ -409,7 +401,7 @@ func (cs *ControllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS
409401
}()
410402

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

505497
// untar snapshot archive to dst path
506-
snapPath := filepath.Join(getInternalVolumePath(cs.Driver.workingMountDir, snapVol), snap.archivePath())
498+
snapPath := filepath.Join(getInternalVolumePath(cs.Driver.workingMountDir, snapVol), snap.archiveName())
507499
dstPath := getInternalVolumePath(cs.Driver.workingMountDir, dstVol)
508500
klog.V(2).Infof("copy volume from snapshot %v -> %v", snapPath, dstPath)
509501
out, err := exec.Command("tar", "-xzvf", snapPath, "-C", dstPath).CombinedOutput()
@@ -803,7 +795,7 @@ func volumeFromSnapshot(snap *nfsSnapshot) *nfsVolume {
803795
id: snap.id,
804796
server: snap.server,
805797
baseDir: snap.baseDir,
806-
subDir: snap.baseDir,
798+
subDir: snap.uuid,
807799
uuid: snap.uuid,
808800
}
809801
}

pkg/nfs/controllerserver_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,10 +742,10 @@ func TestCopyVolume(t *testing.T) {
742742
uuid: "dst-pv-name",
743743
},
744744
prepare: func() error {
745-
if err := os.MkdirAll("/tmp/snapshot-name/share/snapshot-name/", 0777); err != nil {
745+
if err := os.MkdirAll("/tmp/snapshot-name/snapshot-name", 0777); err != nil {
746746
return err
747747
}
748-
file, err := os.Create("/tmp/snapshot-name/share/snapshot-name/src-pv-name.tar.gz")
748+
file, err := os.Create("/tmp/snapshot-name/snapshot-name/src-pv-name.tar.gz")
749749
if err != nil {
750750
return err
751751
}

0 commit comments

Comments
 (0)