Skip to content

Commit

Permalink
CRI-O: try connecting with different socket paths
Browse files Browse the repository at this point in the history
Fixes #128.
  • Loading branch information
jeinwag committed Sep 25, 2024
1 parent 99a6368 commit b388bc2
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions containers/crio.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net"
"net/http"
"os"
"strings"
"time"

"github.com/coroot/coroot-node-agent/common"
Expand All @@ -20,7 +21,6 @@ const crioTimeout = 30 * time.Second

var (
crioClient *http.Client
crioSocket = proc.HostPath("/var/run/crio/crio.sock")
)

type CrioContainerInfo struct {
Expand All @@ -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)

Expand All @@ -50,6 +65,7 @@ func CrioInit() error {
DisableCompression: true,
},
}

return nil
}

Expand Down

0 comments on commit b388bc2

Please sign in to comment.