diff --git a/pkg/util/filesystem/defaultfs.go b/pkg/util/filesystem/defaultfs.go index ef99bd3bc46..0dfd11fb435 100644 --- a/pkg/util/filesystem/defaultfs.go +++ b/pkg/util/filesystem/defaultfs.go @@ -90,7 +90,7 @@ func MkdirAllWithPathCheck(path string, perm os.FileMode) error { // 1. for Unix/Linux OS, check if the path is directory. // 2. for windows NTFS, check if the path is symlink instead of directory. if dir.IsDir() || - (runtime.GOOS == "windows" && (dir.Mode()&os.ModeSymlink != 0)) { + (runtime.GOOS == "windows" && (dir.Mode()&os.ModeSymlink != 0 || dir.Mode()&os.ModeIrregular != 0)) { return nil } return fmt.Errorf("path %v exists but is not a directory", path) diff --git a/pkg/volume/util/fs/fs_windows.go b/pkg/volume/util/fs/fs_windows.go index 6e138514a6a..3e654d3fd3d 100644 --- a/pkg/volume/util/fs/fs_windows.go +++ b/pkg/volume/util/fs/fs_windows.go @@ -85,6 +85,11 @@ func diskUsage(currPath string, info os.FileInfo) (int64, error) { return size, nil } + // go1.23 behavior change: https://github.com/golang/go/issues/63703#issuecomment-2535941458 + if info.Mode()&os.ModeIrregular != 0 { + return size, nil + } + size += info.Size() if !info.IsDir() { diff --git a/pkg/volume/util/subpath/subpath_windows.go b/pkg/volume/util/subpath/subpath_windows.go index 3746f3b5450..14b52a365fc 100644 --- a/pkg/volume/util/subpath/subpath_windows.go +++ b/pkg/volume/util/subpath/subpath_windows.go @@ -201,6 +201,12 @@ func lockAndCheckSubPathWithoutSymlink(volumePath, subPath string) ([]uintptr, e break } + // go1.23 behavior change: https://github.com/golang/go/issues/63703#issuecomment-2535941458 + if stat.Mode()&os.ModeIrregular != 0 { + errorResult = fmt.Errorf("subpath %q is an unexpected irregular file after EvalSymlinks", currentFullPath) + break + } + if !mount.PathWithinBase(currentFullPath, volumePath) { errorResult = fmt.Errorf("SubPath %q not within volume path %q", currentFullPath, volumePath) break @@ -335,6 +341,10 @@ func doSafeMakeDir(pathname string, base string, perm os.FileMode) error { if stat.Mode()&os.ModeSymlink != 0 { return fmt.Errorf("subpath %q is an unexpected symlink after Mkdir", currentPath) } + // go1.23 behavior change: https://github.com/golang/go/issues/63703#issuecomment-2535941458 + if stat.Mode()&os.ModeIrregular != 0 { + return fmt.Errorf("subpath %q is an unexpected irregular file after Mkdir", currentPath) + } } return nil diff --git a/pkg/volume/util/volumepathhandler/volume_path_handler.go b/pkg/volume/util/volumepathhandler/volume_path_handler.go index e632843d1e1..fa0b24a18d8 100644 --- a/pkg/volume/util/volumepathhandler/volume_path_handler.go +++ b/pkg/volume/util/volumepathhandler/volume_path_handler.go @@ -20,6 +20,7 @@ import ( "fmt" "os" "path/filepath" + "runtime" "k8s.io/klog/v2" "k8s.io/mount-utils" @@ -232,7 +233,7 @@ func (v VolumePathHandler) RemoveMapPath(mapPath string) error { return nil } -// IsSymlinkExist returns true if specified file exists and the type is symbolik link. +// IsSymlinkExist returns true if specified file exists and the type is symbolik link or irregular file on Windows. // If file doesn't exist, or file exists but not symbolic link, return false with no error. // On other cases, return false with error from Lstat(). func (v VolumePathHandler) IsSymlinkExist(mapPath string) (bool, error) { @@ -249,6 +250,10 @@ func (v VolumePathHandler) IsSymlinkExist(mapPath string) (bool, error) { if fi.Mode()&os.ModeSymlink == os.ModeSymlink { return true, nil } + // go1.23 behavior change: https://github.com/golang/go/issues/63703#issuecomment-2535941458 + if (runtime.GOOS == "windows") && (fi.Mode()&os.ModeIrregular != 0) { + return true, nil + } // If file exits but it's not symbolic link, return false and no error return false, nil }