Skip to content

Commit

Permalink
add warning when loading image with wrong arch
Browse files Browse the repository at this point in the history
  • Loading branch information
medyagh committed Jul 11, 2024
1 parent 2ad3117 commit ca64435
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
16 changes: 11 additions & 5 deletions pkg/minikube/machine/cache_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func LoadCachedImages(cc *config.ClusterConfig, runner command.Runner, images []
})
}
if err := g.Wait(); err != nil {
return errors.Wrap(err, "loading cached images")
return errors.Wrap(err, "LoadCachedImages")
}
klog.Infoln("Successfully loaded all cached images")
return nil
Expand Down Expand Up @@ -223,7 +223,6 @@ func DoLoadImages(images []string, profiles []*config.Profile, cacheDir string,

for _, n := range c.Nodes {
m := config.MachineName(*c, n)

status, err := Status(api, m)
if err != nil {
klog.Warningf("error getting status for %s: %v", m, err)
Expand Down Expand Up @@ -251,16 +250,20 @@ func DoLoadImages(images []string, profiles []*config.Profile, cacheDir string,
}
if err != nil {
failed = append(failed, m)
klog.Warningf("Failed to load cached images for profile %s. make sure the profile is running. %v", pName, err)
klog.Warningf("Failed to load cached images for %q: %v", pName, err)
continue
}
succeeded = append(succeeded, m)
}
}
}

klog.Infof("succeeded pushing to: %s", strings.Join(succeeded, " "))
klog.Infof("failed pushing to: %s", strings.Join(failed, " "))
if len(succeeded) > 0 {
klog.Infof("succeeded pushing to: %s", strings.Join(succeeded, " "))
}
if len(failed) > 0 {
klog.Infof("failed pushing to: %s", strings.Join(failed, " "))
}
// Live pushes are not considered a failure
return nil
}
Expand Down Expand Up @@ -309,6 +312,9 @@ func transferAndLoadImage(cr command.Runner, k8s config.KubernetesConfig, src st

err = r.LoadImage(dst)
if err != nil {
if strings.Contains(err.Error(), "ctr: image might be filtered out") {
out.WarningT("The image '{{.imageName}}' does not match arch of the container runtime, use a multi-arch image instead", out.V{"imageName": imgName})
}
return errors.Wrapf(err, "%s load %s", r.Name(), dst)
}

Expand Down
16 changes: 8 additions & 8 deletions test/integration/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import (
"golang.org/x/build/kubernetes/api"
)

const addonResizer = "gcr.io/google-containers/addon-resizer"
const echoServerImg = "gcr.io/k8s-minikube/kicbase-builds/echo-server"

// validateFunc are for subtests that share a single setup
type validateFunc func(context.Context, *testing.T, string)
Expand Down Expand Up @@ -182,10 +182,10 @@ func cleanupUnwantedImages(ctx context.Context, t *testing.T, profile string) {
if err != nil {
t.Skipf("docker is not installed, cannot delete docker images")
} else {
t.Run("delete addon-resizer images", func(t *testing.T) {
tags := []string{"1.8.8", profile}
t.Run("delete echo-server images", func(t *testing.T) {
tags := []string{"1.0", profile}
for _, tag := range tags {
image := fmt.Sprintf("%s:%s", addonResizer, tag)
image := fmt.Sprintf("%s:%s", echoServerImg, tag)
rr, err := Run(t, exec.CommandContext(ctx, "docker", "rmi", "-f", image))
if err != nil {
t.Logf("failed to remove image %q from docker images. args %q: %v", image, rr.Command(), err)
Expand Down Expand Up @@ -230,7 +230,7 @@ func validateNodeLabels(ctx context.Context, t *testing.T, profile string) {

// tagAndLoadImage is a helper function to pull, tag, load image (decreases cyclomatic complexity for linter).
func tagAndLoadImage(ctx context.Context, t *testing.T, profile, taggedImage string) {
newPulledImage := fmt.Sprintf("%s:%s", addonResizer, "1.8.9")
newPulledImage := fmt.Sprintf("%s:%s", echoServerImg, "1.8.9")
rr, err := Run(t, exec.CommandContext(ctx, "docker", "pull", newPulledImage))
if err != nil {
t.Fatalf("failed to setup test (pull image): %v\n%s", err, rr.Output())
Expand Down Expand Up @@ -325,8 +325,8 @@ func validateImageCommands(ctx context.Context, t *testing.T, profile string) {
checkImageExists(ctx, t, profile, newImage)
})

taggedImage := fmt.Sprintf("%s:%s", addonResizer, profile)
imageFile := "addon-resizer-save.tar"
taggedImage := fmt.Sprintf("%s:%s", echoServerImg, profile)
imageFile := "echo-server-save.tar"
var imagePath string
defer os.Remove(imageFile)

Expand All @@ -337,7 +337,7 @@ func validateImageCommands(ctx context.Context, t *testing.T, profile string) {
t.Fatalf("failed to get absolute path of file %q: %v", imageFile, err)
}

pulledImage := fmt.Sprintf("%s:%s", addonResizer, "1.8.8")
pulledImage := fmt.Sprintf("%s:%s", echoServerImg, "2.0")
rr, err := Run(t, exec.CommandContext(ctx, "docker", "pull", pulledImage))
if err != nil {
t.Fatalf("failed to setup test (pull image): %v\n%s", err, rr.Output())
Expand Down

0 comments on commit ca64435

Please sign in to comment.