Skip to content

Commit 9495027

Browse files
authored
Merge pull request #602 from andyzhangx/fix-archive-subdir
fix: delete volume failure in archive mode when subDir contains /
2 parents dce3f89 + 96ddd19 commit 9495027

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

pkg/nfs/controllerserver.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,13 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
244244

245245
if strings.EqualFold(nfsVol.onDelete, archive) {
246246
archivedInternalVolumePath := filepath.Join(getInternalMountPath(cs.Driver.workingMountDir, nfsVol), "archived-"+nfsVol.subDir)
247+
if strings.Contains(nfsVol.subDir, "/") {
248+
parentDir := filepath.Dir(archivedInternalVolumePath)
249+
klog.V(2).Infof("DeleteVolume: subdirectory(%s) contains '/', make sure the parent directory(%s) exists", nfsVol.subDir, parentDir)
250+
if err = os.MkdirAll(parentDir, 0777); err != nil {
251+
return nil, status.Errorf(codes.Internal, "create parent directory(%s) of %s failed with %v", parentDir, archivedInternalVolumePath, err.Error())
252+
}
253+
}
247254

248255
// archive subdirectory under base-dir
249256
klog.V(2).Infof("archiving subdirectory %s --> %s", internalVolumePath, archivedInternalVolumePath)

test/e2e/dynamic_provisioning_test.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
351351
test.Run(ctx, cs, ns)
352352
})
353353

354-
ginkgo.It("should create a volume on demand with archive subdir on delete [nfs.csi.k8s.io]", func(ctx ginkgo.SpecContext) {
354+
ginkgo.It("should create a volume on demand with archive on delete [nfs.csi.k8s.io]", func(ctx ginkgo.SpecContext) {
355355
pods := []testsuites.PodDetails{
356356
{
357357
Cmd: "echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data",
@@ -373,4 +373,27 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
373373
}
374374
test.Run(ctx, cs, ns)
375375
})
376+
377+
ginkgo.It("should create a volume on demand with archive subdir on delete [nfs.csi.k8s.io]", func(ctx ginkgo.SpecContext) {
378+
pods := []testsuites.PodDetails{
379+
{
380+
Cmd: "echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data",
381+
Volumes: []testsuites.VolumeDetails{
382+
{
383+
ClaimSize: "10Gi",
384+
VolumeMount: testsuites.VolumeMountDetails{
385+
NameGenerate: "test-volume-",
386+
MountPathGenerate: "/mnt/test-",
387+
},
388+
},
389+
},
390+
},
391+
}
392+
test := testsuites.DynamicallyProvisionedCmdVolumeTest{
393+
CSIDriver: testDriver,
394+
Pods: pods,
395+
StorageClassParameters: archiveSubDirStorageClassParameters,
396+
}
397+
test.Run(ctx, cs, ns)
398+
})
376399
})

test/e2e/e2e_suite_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ var (
8383
"mountPermissions": "0755",
8484
"onDelete": "archive",
8585
}
86+
archiveSubDirStorageClassParameters = map[string]string{
87+
"server": nfsServerAddress,
88+
"share": nfsShare,
89+
"subDir": "${pvc.metadata.namespace}/${pvc.metadata.name}",
90+
"csi.storage.k8s.io/provisioner-secret-name": "mount-options",
91+
"csi.storage.k8s.io/provisioner-secret-namespace": "default",
92+
"mountPermissions": "0755",
93+
"onDelete": "archive",
94+
}
8695
controllerServer *nfs.ControllerServer
8796
)
8897

0 commit comments

Comments
 (0)