Skip to content

Commit

Permalink
refactor arch ehcking logic into func
Browse files Browse the repository at this point in the history
  • Loading branch information
spowelljr committed Jul 15, 2024
1 parent 03d5ee2 commit fa26408
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions pkg/minikube/download/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,27 +86,35 @@ func ImageExistsInDaemon(img string) bool {
if !strings.Contains(string(output), image.TrimDockerIO(img)) {
return false
}
ref, err := name.ParseReference(img)
correctArch, err := isImageCorrectArch(img)
if err != nil {
klog.Warningf("failed to parse reference: %v", err)
klog.Warning(err)
return false
}
if !correctArch {
klog.Warningf("image %s is of wrong architecture", img)
return false
}
klog.Infof("Found %s in local docker daemon, skipping pull", img)
return true
}

// isImageCorrectArch is needed to resolve
// https://github.com/kubernetes/minikube/pull/19205
func isImageCorrectArch(img string) (bool, error) {
ref, err := name.ParseReference(img)
if err != nil {
return false, fmt.Errorf("failed to parse reference: %v", err)
}
dImg, err := daemon.Image(ref)
if err != nil {
klog.Warningf("failed to get image from daemon: %v", err)
return false
return false, fmt.Errorf("failed to get image from daemon: %v", err)
}
cfg, err := dImg.ConfigFile()
if err != nil {
klog.Warningf("failed to get config for %s: %v", img, err)
return false
return false, fmt.Errorf("failed to get config for %s: %v", img, err)
}
if cfg.Architecture != runtime.GOOS {
klog.Warningf("image %s is of wrong architecture", img)
return false
}
klog.Infof("Found %s in local docker daemon, skipping pull", img)
return true
return cfg.Architecture == runtime.GOOS, nil
}

// ImageToCache downloads img (if not present in cache) and writes it to the local cache directory
Expand Down

0 comments on commit fa26408

Please sign in to comment.