mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
Merge pull request #130187 from mansikulkarni96/129084
fix: Sweep and fix stat, lstat, evalsymlink usage for go1.23 on Windows
This commit is contained in:
commit
ef54ac803b
2
go.mod
2
go.mod
@ -10,8 +10,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
bitbucket.org/bertimus9/systemstat v0.5.0
|
||||
github.com/JeffAshton/win_pdh v0.0.0-20161109143554-76bb4ee9f0ab
|
||||
|
2
go.work
2
go.work
@ -4,8 +4,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
use (
|
||||
.
|
||||
./staging/src/k8s.io/api
|
||||
|
@ -202,15 +202,12 @@ func (m *ManagerImpl) CleanupPluginDirectory(dir string) error {
|
||||
if filePath == m.checkpointFile() {
|
||||
continue
|
||||
}
|
||||
// TODO: Until the bug - https://github.com/golang/go/issues/33357 is fixed, os.stat wouldn't return the
|
||||
// right mode(socket) on windows. Hence deleting the file, without checking whether
|
||||
// its a socket, on windows.
|
||||
stat, err := os.Lstat(filePath)
|
||||
stat, err := os.Stat(filePath)
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "Failed to stat file", "path", filePath)
|
||||
continue
|
||||
}
|
||||
if stat.IsDir() {
|
||||
if stat.IsDir() || stat.Mode()&os.ModeSocket == 0 {
|
||||
continue
|
||||
}
|
||||
err = os.RemoveAll(filePath)
|
||||
|
@ -46,20 +46,21 @@ const (
|
||||
// Note that due to the retry logic inside, it could take up to 4 seconds
|
||||
// to determine whether or not the file path supplied is a Unix domain socket
|
||||
func IsUnixDomainSocket(filePath string) (bool, error) {
|
||||
// Due to the absence of golang support for os.ModeSocket in Windows (https://github.com/golang/go/issues/33357)
|
||||
// we need to dial the file and check if we receive an error to determine if a file is Unix Domain Socket file.
|
||||
|
||||
// Note that querrying for the Reparse Points (https://docs.microsoft.com/en-us/windows/win32/fileio/reparse-points)
|
||||
// for the file (using FSCTL_GET_REPARSE_POINT) and checking for reparse tag: reparseTagSocket
|
||||
// does NOT work in 1809 if the socket file is created within a bind mounted directory by a container
|
||||
// and the FSCTL is issued in the host by the kubelet.
|
||||
|
||||
// If the file does not exist, it cannot be a Unix domain socket.
|
||||
if _, err := os.Stat(filePath); os.IsNotExist(err) {
|
||||
if info, err := os.Stat(filePath); os.IsNotExist(err) {
|
||||
return false, fmt.Errorf("File %s not found. Err: %v", filePath, err)
|
||||
} else if err == nil && info.Mode()&os.ModeSocket != 0 { // Use os.ModeSocket (introduced in Go 1.23 on Windows)
|
||||
klog.V(6).InfoS("File identified as a Unix domain socket", "filePath", filePath)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
klog.V(6).InfoS("Function IsUnixDomainSocket starts", "filePath", filePath)
|
||||
// Due to the absence of golang support for os.ModeSocket in Windows (https://github.com/golang/go/issues/33357)
|
||||
// we need to dial the file and check if we receive an error to determine if a file is Unix Domain Socket file.
|
||||
// As detailed in https://github.com/kubernetes/kubernetes/issues/104584 we cannot rely
|
||||
// on the Unix Domain socket working on the very first try, hence the potential need to
|
||||
// dial multiple times
|
||||
|
@ -29,7 +29,6 @@ import (
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/kubernetes/pkg/util/filesystem"
|
||||
"k8s.io/mount-utils"
|
||||
utilpath "k8s.io/utils/path"
|
||||
)
|
||||
@ -103,14 +102,6 @@ func isSystemCannotAccessErr(err error) bool {
|
||||
func (hu *(HostUtil)) GetFileType(pathname string) (FileType, error) {
|
||||
filetype, err := getFileType(pathname)
|
||||
|
||||
// os.Stat will return a 1920 error (windows.ERROR_CANT_ACCESS_FILE) if we use it on a Unix Socket
|
||||
// on Windows. In this case, we need to use a different method to check if it's a Unix Socket.
|
||||
if err == errUnknownFileType || isSystemCannotAccessErr(err) {
|
||||
if isSocket, errSocket := filesystem.IsUnixDomainSocket(pathname); errSocket == nil && isSocket {
|
||||
return FileTypeSocket, nil
|
||||
}
|
||||
}
|
||||
|
||||
return filetype, err
|
||||
}
|
||||
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/gogo/protobuf v1.3.2
|
||||
k8s.io/apimachinery v0.0.0
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/emicklei/go-restful/v3 v3.11.0
|
||||
github.com/fxamacker/cbor/v2 v2.7.0
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
|
||||
github.com/davecgh/go-spew v1.1.1
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/blang/semver/v4 v4.0.0
|
||||
github.com/coreos/go-oidc v2.3.0+incompatible
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/google/gnostic-models v0.6.9
|
||||
github.com/google/go-cmp v0.6.0
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/go-logr/logr v1.4.2
|
||||
github.com/gogo/protobuf v1.3.2
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/google/go-cmp v0.6.0
|
||||
github.com/spf13/cobra v1.8.1
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/stretchr/testify v1.9.0
|
||||
gopkg.in/go-jose/go-jose.v2 v2.6.3
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/gogo/protobuf v1.3.2
|
||||
github.com/google/gnostic-models v0.6.9
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/blang/semver/v4 v4.0.0
|
||||
github.com/go-logr/logr v1.4.2
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/google/go-cmp v0.6.0
|
||||
github.com/stretchr/testify v1.9.0
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/spf13/pflag v1.0.5
|
||||
github.com/stretchr/testify v1.9.0
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/gogo/protobuf v1.3.2
|
||||
github.com/stretchr/testify v1.9.0
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/Microsoft/go-winio v0.6.2
|
||||
github.com/fsnotify/fsnotify v1.7.0
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/stretchr/testify v1.9.0
|
||||
k8s.io/api v0.0.0
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/blang/semver/v4 v4.0.0
|
||||
github.com/google/cel-go v0.23.2
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/google/go-cmp v0.6.0
|
||||
github.com/stretchr/testify v1.9.0
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/gogo/protobuf v1.3.2
|
||||
google.golang.org/grpc v1.65.0
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/gogo/protobuf v1.3.2
|
||||
google.golang.org/grpc v1.65.0
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/emicklei/go-restful/v3 v3.11.0
|
||||
github.com/gogo/protobuf v1.3.2
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
k8s.io/apimachinery v0.0.0
|
||||
k8s.io/cloud-provider v0.0.0
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
k8s.io/apimachinery v0.0.0
|
||||
k8s.io/component-base v0.0.0
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/google/go-cmp v0.6.0
|
||||
k8s.io/api v0.0.0
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/MakeNowJust/heredoc v1.0.0
|
||||
github.com/chai2010/gettext-go v1.0.2
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/emicklei/go-restful/v3 v3.11.0
|
||||
github.com/gogo/protobuf v1.3.2
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/gogo/protobuf v1.3.2
|
||||
github.com/stretchr/testify v1.9.0
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/moby/sys/mountinfo v0.7.2
|
||||
github.com/stretchr/testify v1.9.0
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/blang/semver/v4 v4.0.0
|
||||
github.com/google/go-cmp v0.6.0
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/google/gofuzz v1.2.0
|
||||
github.com/spf13/cobra v1.8.1
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
github.com/spf13/cobra v1.8.1
|
||||
github.com/spf13/pflag v1.0.5
|
||||
|
@ -6,8 +6,6 @@ go 1.23.0
|
||||
|
||||
godebug default=go1.23
|
||||
|
||||
godebug winsymlink=0
|
||||
|
||||
require (
|
||||
golang.org/x/time v0.7.0
|
||||
k8s.io/api v0.0.0
|
||||
|
@ -77,12 +77,15 @@ func getFilePerm(path string) (os.FileMode, error) {
|
||||
// NOTE(claudiub): Symlinks have different permissions which might not match the target's.
|
||||
// We want to evaluate the permissions of the target's not the symlink's.
|
||||
info, err := os.Lstat(path)
|
||||
if err == nil && info.Mode()&os.ModeSymlink != 0 {
|
||||
evaluated, err := filepath.EvalSymlinks(path)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
if err == nil {
|
||||
// go1.23 behavior change: https://github.com/golang/go/issues/63703#issuecomment-2535941458
|
||||
if info.Mode()&os.ModeSymlink != 0 || info.Mode()&os.ModeIrregular != 0 {
|
||||
evaluated, err := filepath.EvalSymlinks(path)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
path = evaluated
|
||||
}
|
||||
path = evaluated
|
||||
}
|
||||
|
||||
cmd := exec.Command("powershell.exe", "-NonInteractive", "./filePermissions.ps1",
|
||||
|
Loading…
Reference in New Issue
Block a user