Skip to content

Commit

Permalink
Add support for AWS (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
alxtkr77 authored Sep 22, 2024
1 parent 1ae9da8 commit abf320e
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions pkg/cri/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,23 +232,47 @@ func (c *Containerd) createContainer(image string,

// pull the v3io-fuse image
// [IG-23016] MountVolume.SetUp failed for volume storage in k8s 1.29
//

var ctrPath string
var err error

// Check if "/usr/local/bin/ctr" exists
if _, err := os.Stat("/usr/local/bin/ctr"); err == nil {
// Get path to ctr
var ctrPath string
if ctrPath, err = exec.LookPath("ctr"); err == nil {
} else 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 {
} else if _, err = os.Stat("/usr/bin/ctr"); err == nil {
ctrPath = "/usr/bin/ctr"
} else {
}
if err != nil {
// 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)
// Check if AWS CLI is installed
var cmd *exec.Cmd
var awsPath string

if awsPath, err = exec.LookPath("aws"); err == nil {
// Get ECR password
cmd = exec.Command(awsPath, "ecr", "get-login-password", "--region", "us-east-2")
ecrPasswordBytes, err := cmd.Output()
if err != nil {
// Return an error if neither file exists
journal.Error("Failed to pull image: Error retrieving ECR password",
"containerName", containerName,
"image", image)
return nil, err
}
ecrPassword := strings.TrimSpace(string(ecrPasswordBytes))
cmd = exec.Command(ctrPath, "-n", "k8s.io", "images", "pull", "--user", fmt.Sprintf("AWS:%s", ecrPassword), image)
} else {
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 {
Expand Down

0 comments on commit abf320e

Please sign in to comment.