From b388bc2f259b14981d2c7bc6bb828aed502971bf Mon Sep 17 00:00:00 2001 From: Julian Einwag Date: Wed, 25 Sep 2024 13:04:58 +0200 Subject: [PATCH] CRI-O: try connecting with different socket paths Fixes coroot/coroot-node-agent#128. --- containers/crio.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/containers/crio.go b/containers/crio.go index 3a51f36..be30a28 100644 --- a/containers/crio.go +++ b/containers/crio.go @@ -8,6 +8,7 @@ import ( "net" "net/http" "os" + "strings" "time" "github.com/coroot/coroot-node-agent/common" @@ -20,7 +21,6 @@ const crioTimeout = 30 * time.Second var ( crioClient *http.Client - crioSocket = proc.HostPath("/var/run/crio/crio.sock") ) type CrioContainerInfo struct { @@ -37,8 +37,23 @@ type CrioVolume struct { } func CrioInit() error { - if _, err := os.Stat(crioSocket); err != nil { - return err + sockets := []string{ + "/var/run/crio/crio.sock", + "/run/crio/crio.sock", + } + var crioSocket string + var err error + for _, socket := range sockets { + socketHostPath := proc.HostPath(socket) + if _, err := os.Stat(socketHostPath); err == nil { + crioSocket = socketHostPath + break + } + } + if err != nil { + return fmt.Errorf("couldn't connect to CRI-O through the following UNIX sockets: [%s]: %s", + strings.Join(sockets, ","), err, + ) } klog.Infoln("cri-o socket:", crioSocket) @@ -50,6 +65,7 @@ func CrioInit() error { DisableCompression: true, }, } + return nil }