@@ -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