Skip to content

Commit dfc8b27

Browse files
[kubelet] Make use of os.ModeSocket info
1 parent b84cb65 commit dfc8b27

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

0 commit comments

Comments
 (0)