Skip to content

Commit ef54ac8

Browse files
authored
Merge pull request kubernetes#130187 from mansikulkarni96/129084
fix: Sweep and fix stat, lstat, evalsymlink usage for go1.23 on Windows
2 parents 4032177 + 1f642c7 commit ef54ac8

File tree

37 files changed

+16
-90
lines changed

37 files changed

+16
-90
lines changed

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ go 1.23.0
1010

1111
godebug default=go1.23
1212

13-
godebug winsymlink=0
14-
1513
require (
1614
bitbucket.org/bertimus9/systemstat v0.5.0
1715
github.com/JeffAshton/win_pdh v0.0.0-20161109143554-76bb4ee9f0ab

go.work

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ go 1.23.0
44

55
godebug default=go1.23
66

7-
godebug winsymlink=0
8-
97
use (
108
.
119
./staging/src/k8s.io/api

pkg/kubelet/cm/devicemanager/manager.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,12 @@ func (m *ManagerImpl) CleanupPluginDirectory(dir string) error {
202202
if filePath == m.checkpointFile() {
203203
continue
204204
}
205-
// TODO: Until the bug - https://github.com/golang/go/issues/33357 is fixed, os.stat wouldn't return the
206-
// right mode(socket) on windows. Hence deleting the file, without checking whether
207-
// its a socket, on windows.
208-
stat, err := os.Lstat(filePath)
205+
stat, err := os.Stat(filePath)
209206
if err != nil {
210207
klog.ErrorS(err, "Failed to stat file", "path", filePath)
211208
continue
212209
}
213-
if stat.IsDir() {
210+
if stat.IsDir() || stat.Mode()&os.ModeSocket == 0 {
214211
continue
215212
}
216213
err = os.RemoveAll(filePath)

pkg/util/filesystem/util_windows.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,21 @@ const (
4646
// Note that due to the retry logic inside, it could take up to 4 seconds
4747
// to determine whether or not the file path supplied is a Unix domain socket
4848
func IsUnixDomainSocket(filePath string) (bool, error) {
49-
// Due to the absence of golang support for os.ModeSocket in Windows (https://github.com/golang/go/issues/33357)
50-
// we need to dial the file and check if we receive an error to determine if a file is Unix Domain Socket file.
51-
5249
// Note that querrying for the Reparse Points (https://docs.microsoft.com/en-us/windows/win32/fileio/reparse-points)
5350
// for the file (using FSCTL_GET_REPARSE_POINT) and checking for reparse tag: reparseTagSocket
5451
// does NOT work in 1809 if the socket file is created within a bind mounted directory by a container
5552
// and the FSCTL is issued in the host by the kubelet.
5653

5754
// If the file does not exist, it cannot be a Unix domain socket.
58-
if _, err := os.Stat(filePath); os.IsNotExist(err) {
55+
if info, err := os.Stat(filePath); os.IsNotExist(err) {
5956
return false, fmt.Errorf("File %s not found. Err: %v", filePath, err)
57+
} else if err == nil && info.Mode()&os.ModeSocket != 0 { // Use os.ModeSocket (introduced in Go 1.23 on Windows)
58+
klog.V(6).InfoS("File identified as a Unix domain socket", "filePath", filePath)
59+
return true, nil
6060
}
61-
6261
klog.V(6).InfoS("Function IsUnixDomainSocket starts", "filePath", filePath)
62+
// Due to the absence of golang support for os.ModeSocket in Windows (https://github.com/golang/go/issues/33357)
63+
// we need to dial the file and check if we receive an error to determine if a file is Unix Domain Socket file.
6364
// As detailed in https://github.com/kubernetes/kubernetes/issues/104584 we cannot rely
6465
// on the Unix Domain socket working on the very first try, hence the potential need to
6566
// dial multiple times

pkg/volume/util/hostutil/hostutil_windows.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929

3030
"golang.org/x/sys/windows"
3131
"k8s.io/klog/v2"
32-
"k8s.io/kubernetes/pkg/util/filesystem"
3332
"k8s.io/mount-utils"
3433
utilpath "k8s.io/utils/path"
3534
)
@@ -103,14 +102,6 @@ func isSystemCannotAccessErr(err error) bool {
103102
func (hu *(HostUtil)) GetFileType(pathname string) (FileType, error) {
104103
filetype, err := getFileType(pathname)
105104

106-
// os.Stat will return a 1920 error (windows.ERROR_CANT_ACCESS_FILE) if we use it on a Unix Socket
107-
// on Windows. In this case, we need to use a different method to check if it's a Unix Socket.
108-
if err == errUnknownFileType || isSystemCannotAccessErr(err) {
109-
if isSocket, errSocket := filesystem.IsUnixDomainSocket(pathname); errSocket == nil && isSocket {
110-
return FileTypeSocket, nil
111-
}
112-
}
113-
114105
return filetype, err
115106
}
116107

staging/src/k8s.io/api/go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ go 1.23.0
66

77
godebug default=go1.23
88

9-
godebug winsymlink=0
10-
119
require (
1210
github.com/gogo/protobuf v1.3.2
1311
k8s.io/apimachinery v0.0.0

staging/src/k8s.io/apiextensions-apiserver/go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ go 1.23.0
66

77
godebug default=go1.23
88

9-
godebug winsymlink=0
10-
119
require (
1210
github.com/emicklei/go-restful/v3 v3.11.0
1311
github.com/fxamacker/cbor/v2 v2.7.0

staging/src/k8s.io/apimachinery/go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ go 1.23.0
66

77
godebug default=go1.23
88

9-
godebug winsymlink=0
10-
119
require (
1210
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
1311
github.com/davecgh/go-spew v1.1.1

staging/src/k8s.io/apiserver/go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ go 1.23.0
66

77
godebug default=go1.23
88

9-
godebug winsymlink=0
10-
119
require (
1210
github.com/blang/semver/v4 v4.0.0
1311
github.com/coreos/go-oidc v2.3.0+incompatible

staging/src/k8s.io/cli-runtime/go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ go 1.23.0
66

77
godebug default=go1.23
88

9-
godebug winsymlink=0
10-
119
require (
1210
github.com/google/gnostic-models v0.6.9
1311
github.com/google/go-cmp v0.6.0

0 commit comments

Comments
 (0)