Merge pull request #770 from andyzhangx/remove-parent-dir
fix: remove parent dir in DeleteVolume
This commit is contained in:
commit
096163569b
@ -291,9 +291,15 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
|
||||
}
|
||||
klog.V(2).Infof("archived subdirectory %s --> %s", internalVolumePath, archivedInternalVolumePath)
|
||||
} else {
|
||||
rootDir := getRootDir(nfsVol.subDir)
|
||||
if rootDir != "" {
|
||||
rootDir = filepath.Join(getInternalMountPath(cs.Driver.workingMountDir, nfsVol), rootDir)
|
||||
} else {
|
||||
rootDir = internalVolumePath
|
||||
}
|
||||
// delete subdirectory under base-dir
|
||||
klog.V(2).Infof("removing subdirectory at %v", internalVolumePath)
|
||||
if err = os.RemoveAll(internalVolumePath); err != nil {
|
||||
klog.V(2).Infof("removing subdirectory at %v on internalVolumePath %s", rootDir, internalVolumePath)
|
||||
if err = os.RemoveAll(rootDir); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "delete subdirectory(%s) failed with %v", internalVolumePath, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -215,3 +215,9 @@ func waitForPathNotExistWithTimeout(path string, timeout time.Duration) error {
|
||||
time.Sleep(500 * time.Microsecond)
|
||||
}
|
||||
}
|
||||
|
||||
// getRootDir returns the root directory of the given directory
|
||||
func getRootDir(path string) string {
|
||||
parts := strings.Split(path, "/")
|
||||
return parts[0]
|
||||
}
|
||||
|
||||
@ -387,3 +387,44 @@ func TestWaitForPathNotExistWithTimeout(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetRootPath(t *testing.T) {
|
||||
tests := []struct {
|
||||
desc string
|
||||
dir string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
desc: "empty path",
|
||||
dir: "",
|
||||
expected: "",
|
||||
},
|
||||
{
|
||||
desc: "root path",
|
||||
dir: "/",
|
||||
expected: "",
|
||||
},
|
||||
{
|
||||
desc: "subdir path",
|
||||
dir: "/subdir",
|
||||
expected: "",
|
||||
},
|
||||
{
|
||||
desc: "subdir path without leading slash",
|
||||
dir: "subdir",
|
||||
expected: "subdir",
|
||||
},
|
||||
{
|
||||
desc: "multiple subdir path without leading slash",
|
||||
dir: "subdir/subdir2",
|
||||
expected: "subdir",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
result := getRootDir(test.dir)
|
||||
if result != test.expected {
|
||||
t.Errorf("Unexpected result: %s, expected: %s", result, test.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ var (
|
||||
subDirStorageClassParameters = map[string]string{
|
||||
"server": nfsServerAddress,
|
||||
"share": nfsShare,
|
||||
"subDir": "subDirectory-${pvc.metadata.namespace}",
|
||||
"subDir": "${pvc.metadata.namespace}/${pvc.metadata.name}",
|
||||
"csi.storage.k8s.io/provisioner-secret-name": "mount-options",
|
||||
"csi.storage.k8s.io/provisioner-secret-namespace": "default",
|
||||
"mountPermissions": "0755",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user