Skip to content

Commit

Permalink
Merge pull request #545 from aramase/os-removeall
Browse files Browse the repository at this point in the history
fix: windows targetpath cleanup as part of node unpublish
  • Loading branch information
k8s-ci-robot committed May 17, 2021
2 parents 66ecd75 + 312c85f commit b864ecf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions docker/cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# See https://cloud.google.com/cloud-build/docs/build-config

# this must be specified in seconds. If omitted, defaults to 600s (10 mins)
# setting it to 3600s to accommodate multi-os image builds.
timeout: 3600s
# this prevents errors if you don't use both _GIT_TAG and _PULL_BASE_REF,
# or any new substitutions added in the future.
Expand Down
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 b864ecf

Please sign in to comment.