From 11f1d24165440250c3a629097f68e73c121d7cd1 Mon Sep 17 00:00:00 2001 From: Claudiu Belu Date: Wed, 26 Apr 2023 13:20:08 +0000 Subject: [PATCH] unit tests: Fixes kubelet util unit tests for Windows The unit tests are currently failing due to missing imports. This commit addresses this issue. Additionally, TestIsUnixDomainSocket expects an error to be raised by IsUnixDomainSocket if the file does not exist, but on Windows we do not raise such error. This issue is addressed by Stat-ing the file, and checking if the file exists or not. We're also handling the case in which the given filePath is a named pipe, returning false immediately, instead of trying to dial it as a Unix domain socket. --- pkg/kubelet/util/util_windows.go | 6 ++++++ pkg/kubelet/util/util_windows_test.go | 2 ++ 2 files changed, 8 insertions(+) diff --git a/pkg/kubelet/util/util_windows.go b/pkg/kubelet/util/util_windows.go index 33a279e9a1a..b8fc558d2e2 100644 --- a/pkg/kubelet/util/util_windows.go +++ b/pkg/kubelet/util/util_windows.go @@ -24,6 +24,7 @@ import ( "fmt" "net" "net/url" + "os" "path/filepath" "strings" "syscall" @@ -165,6 +166,11 @@ func IsUnixDomainSocket(filePath string) (bool, error) { // 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) { + return false, fmt.Errorf("File %s not found. Err: %v", filePath, err) + } + klog.V(6).InfoS("Function IsUnixDomainSocket starts", "filePath", filePath) // 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 diff --git a/pkg/kubelet/util/util_windows_test.go b/pkg/kubelet/util/util_windows_test.go index d718f6add3d..1450365a4c5 100644 --- a/pkg/kubelet/util/util_windows_test.go +++ b/pkg/kubelet/util/util_windows_test.go @@ -22,6 +22,8 @@ package util import ( "fmt" "math/rand" + "net" + "os" "reflect" "runtime" "sync"