From b9f6013c12ca2201dd3f471740d263168446667a Mon Sep 17 00:00:00 2001 From: mansikulkarni96 Date: Mon, 17 Feb 2025 16:16:03 -0500 Subject: [PATCH] fix: handle socket file detection on Windows Cherry-picked https://github.com/kubernetes/kubernetes/commit/4060ee60c1d2e5ba1fba1f8729adfc211cee1b6f Update socket file detection logic to use os.Stat as per upstream Go fix for golang/go#33357. This resolves the issue where socket files could not be properly identified on Windows systems. --- pkg/kubelet/cm/devicemanager/manager.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pkg/kubelet/cm/devicemanager/manager.go b/pkg/kubelet/cm/devicemanager/manager.go index 5f4a72a43e3..9ed9c132293 100644 --- a/pkg/kubelet/cm/devicemanager/manager.go +++ b/pkg/kubelet/cm/devicemanager/manager.go @@ -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)