From 1ae9da8165e7e65079f72b149f72877febe40209 Mon Sep 17 00:00:00 2001 From: alxtkr77 <3098237+alxtkr77@users.noreply.github.com> Date: Tue, 17 Sep 2024 14:43:47 +0300 Subject: [PATCH] Check ctr location (#67) --- pkg/cri/containerd.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pkg/cri/containerd.go b/pkg/cri/containerd.go index 6f427d1..7be126b 100644 --- a/pkg/cri/containerd.go +++ b/pkg/cri/containerd.go @@ -24,6 +24,7 @@ import ( "context" "fmt" "io/ioutil" + "os" "os/exec" "path" "strconv" @@ -231,7 +232,23 @@ func (c *Containerd) createContainer(image string, // pull the v3io-fuse image // [IG-23016] MountVolume.SetUp failed for volume storage in k8s 1.29 - cmd := exec.Command("/usr/local/bin/ctr", "-n", "k8s.io", "images", "pull", "--hosts-dir", "/etc/containerd/certs.d/", image) + + var ctrPath string + + // Check if "/usr/local/bin/ctr" exists + if _, err := os.Stat("/usr/local/bin/ctr"); err == nil { + ctrPath = "/usr/local/bin/ctr" + } else if _, err := os.Stat("/usr/bin/ctr"); err == nil { + ctrPath = "/usr/bin/ctr" + } else { + // Return an error if neither file exists + journal.Error("Failed to pull image: ctr not found", + "containerName", containerName, + "image", image) + return nil, err + } + + cmd := exec.Command(ctrPath, "-n", "k8s.io", "images", "pull", "--hosts-dir", "/etc/containerd/certs.d/", image) output, err := cmd.CombinedOutput() // Handle errors if err != nil {