From 894bd0279866180be456a4e72465facd940c3375 Mon Sep 17 00:00:00 2001 From: Maxim Patlasov Date: Wed, 4 Sep 2024 15:38:47 +0200 Subject: [PATCH] fix: chmod volume dir before deletion os.RemoveAll() fails if at least one subdir doesn't have write permissions. See https://github.com/kubernetes-csi/csi-driver-smb/issues/834. --- pkg/smb/controllerserver.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/smb/controllerserver.go b/pkg/smb/controllerserver.go index 377b21f8b40..3d2c61eb591 100644 --- a/pkg/smb/controllerserver.go +++ b/pkg/smb/controllerserver.go @@ -19,6 +19,7 @@ package smb import ( "context" "fmt" + "io/fs" "os" "os/exec" "path/filepath" @@ -223,6 +224,14 @@ func (d *Driver) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest) return nil, status.Errorf(codes.Internal, "archive subdirectory(%s, %s) failed with %v", internalVolumePath, archivedInternalVolumePath, err.Error()) } } else { + if _, err2 := os.Lstat(internalVolumePath); err2 == nil { + err2 := filepath.WalkDir(internalVolumePath, func(path string, di fs.DirEntry, err error) error { + return os.Chmod(path, 0777) + }) + if err2 != nil { + klog.Errorf("failed to chmod subdirectory: %v", err2) + } + } klog.V(2).Infof("Removing subdirectory at %v", internalVolumePath) if err = os.RemoveAll(internalVolumePath); err != nil { return nil, status.Errorf(codes.Internal, "failed to delete subdirectory: %v", err.Error())