Skip to content

Commit 7e1b0dd

Browse files
committed
[k3s] using the k3s-specific containerd UNIX socket path as a fallback (closes #2)
1 parent 86d0ae7 commit 7e1b0dd

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

containers/containerd.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/coroot/coroot-node-agent/proc"
1212
"github.com/coroot/logparser"
1313
"k8s.io/klog/v2"
14+
"strings"
1415
"time"
1516
)
1617

@@ -21,13 +22,22 @@ var (
2122
)
2223

2324
func ContainerdInit() error {
24-
c, err := containerd.New(proc.HostPath("/run/containerd/containerd.sock"),
25-
containerd.WithDefaultNamespace(constants.K8sContainerdNamespace),
26-
containerd.WithTimeout(time.Second))
27-
if err != nil {
28-
return err
25+
sockets := []string{"/run/containerd/containerd.sock", "/run/k3s/containerd/containerd.sock"}
26+
var err error
27+
for _, socket := range sockets {
28+
containerdClient, err = containerd.New(proc.HostPath(socket),
29+
containerd.WithDefaultNamespace(constants.K8sContainerdNamespace),
30+
containerd.WithTimeout(time.Second))
31+
if err == nil {
32+
break
33+
}
34+
}
35+
if containerdClient == nil {
36+
return fmt.Errorf(
37+
"couldn't connect to containerd through the following UNIX sockets [%s]: %s",
38+
strings.Join(sockets, ","), err,
39+
)
2940
}
30-
containerdClient = c
3141
return nil
3242
}
3343

0 commit comments

Comments
 (0)