Skip to content

Commit b864ecf

Browse files
authored
Merge pull request #545 from aramase/os-removeall
fix: windows targetpath cleanup as part of node unpublish
2 parents 66ecd75 + 312c85f commit b864ecf

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

docker/cloudbuild.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# See https://cloud.google.com/cloud-build/docs/build-config
22

33
# this must be specified in seconds. If omitted, defaults to 600s (10 mins)
4+
# setting it to 3600s to accommodate multi-os image builds.
45
timeout: 3600s
56
# this prevents errors if you don't use both _GIT_TAG and _PULL_BASE_REF,
67
# or any new substitutions added in the future.

pkg/secrets-store/nodeserver.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"errors"
2222
"fmt"
2323
"os"
24+
"path/filepath"
25+
"runtime"
2426

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

230+
// for windows as the target path is not a mount point, we need to explicitly remove the contents from the
231+
// dir to be able to cleanup the target path.
232+
if runtime.GOOS == "windows" {
233+
files, err := filepath.Glob(filepath.Join(targetPath, "*"))
234+
if err != nil {
235+
klog.ErrorS(err, "failed to get files from target path", "targetPath", targetPath)
236+
return nil, status.Error(codes.Internal, err.Error())
237+
}
238+
for _, file := range files {
239+
if err = os.RemoveAll(file); err != nil {
240+
klog.ErrorS(err, "failed to delete file from target path", "targetPath", targetPath, "file", file)
241+
}
242+
}
243+
}
244+
228245
err = mount.CleanupMountPoint(targetPath, ns.mounter, false)
229246
if err != nil && !os.IsNotExist(err) {
230247
klog.ErrorS(err, "failed to clean and unmount target path", "targetPath", targetPath)

0 commit comments

Comments
 (0)