Skip to content

Commit

Permalink
fix: windows targetpath cleanup as part of node unpublish
Browse files Browse the repository at this point in the history
Signed-off-by: Anish Ramasekar <anish.ramasekar@gmail.com>
  • Loading branch information
aramase committed May 17, 2021
1 parent 66ecd75 commit 152dfc3
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/secrets-store/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"errors"
"fmt"
"os"
"path/filepath"
"runtime"

csicommon "sigs.k8s.io/secrets-store-csi-driver/pkg/csi-common"
internalerrors "sigs.k8s.io/secrets-store-csi-driver/pkg/errors"
Expand Down Expand Up @@ -225,6 +227,21 @@ func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
return &csi.NodeUnpublishVolumeResponse{}, nil
}

// for windows as the target path is not a mount point, we need to explicitly remove the contents from the
// dir to be able to cleanup the target path.
if runtime.GOOS == "windows" {
files, err := filepath.Glob(filepath.Join(targetPath, "*"))
if err != nil {
klog.ErrorS(err, "failed to get files from target path", "targetPath", targetPath)
return nil, status.Error(codes.Internal, err.Error())
}
for _, file := range files {
if err = os.RemoveAll(file); err != nil {
klog.ErrorS(err, "failed to delete file from target path", "targetPath", targetPath, "file", file)
}
}
}

err = mount.CleanupMountPoint(targetPath, ns.mounter, false)
if err != nil && !os.IsNotExist(err) {
klog.ErrorS(err, "failed to clean and unmount target path", "targetPath", targetPath)
Expand Down

0 comments on commit 152dfc3

Please sign in to comment.