Skip to content

Commit

Permalink
Merge pull request #129 from jeinwag/crio_retry
Browse files Browse the repository at this point in the history
CRI-O: try connecting with different socket paths
  • Loading branch information
def authored Sep 25, 2024
2 parents 99a6368 + b388bc2 commit 93f0d1f
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 93f0d1f

Please sign in to comment.