Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback to trying kic image without SHA when using image registry #20226

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions pkg/minikube/node/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,19 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down
register.Reg.SetStep(register.PullingBaseImage)
out.Step(style.Pulling, "Pulling base image {{.kicVersion}} ...", out.V{"kicVersion": kic.Version})
g.Go(func() error {
images := make([]string, 0, 2+len(kic.FallbackImages))
baseImg := cc.KicBaseImage
baseFallbackImg := ""
if baseImg == kic.BaseImage && len(cc.KubernetesConfig.ImageRepository) != 0 {
baseImg = updateKicImageRepo(baseImg, cc.KubernetesConfig.ImageRepository)
baseImg, baseFallbackImg = updateKicImageRepo(baseImg, cc.KubernetesConfig.ImageRepository)
cc.KicBaseImage = baseImg
}
images = append(images, baseImg)
if baseFallbackImg != "" && baseFallbackImg != baseImg {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if minikube does not start with --image-registry option, or specify a different kic image that without sha (with --base-image option), it will not add the image without sha into the fallback list

images = append(images, baseFallbackImg)
}
images = append(images, kic.FallbackImages...)

var finalImg string
// If we end up using a fallback image, notify the user
defer func() {
Expand All @@ -139,7 +147,7 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down
}()
// first we try to download the kicbase image (and fall back images) from docker registry
var err error
for _, img := range append([]string{baseImg}, kic.FallbackImages...) {
for _, img := range images {

if driver.IsDocker(cc.Driver) && download.ImageExistsInDaemon(img) && !downloadOnly {
klog.Infof("%s exists in daemon, skipping load", img)
Expand Down Expand Up @@ -278,13 +286,16 @@ func imagesInConfigFile() ([]string, error) {
return []string{}, nil
}

func updateKicImageRepo(imgName string, repo string) string {
func updateKicImageRepo(imgName string, repo string) (string, string) {
image := strings.TrimPrefix(imgName, "gcr.io/")
if repo == constants.AliyunMirror {
// for aliyun registry must strip namespace from image name, e.g.
// registry.cn-hangzhou.aliyuncs.com/google_containers/k8s-minikube/kicbase:v0.0.25 will not work
// registry.cn-hangzhou.aliyuncs.com/google_containers/kicbase:v0.0.25 does work
image = strings.TrimPrefix(image, "k8s-minikube/")
}
return path.Join(repo, image)
baseImg := path.Join(repo, image)
// try a fallback image without sha, because #11068
fallbackImg := strings.Split(image, "@sha256:")[0]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pkg/driver/kic/types.go did not export the image's sha, so I removed the sha part from the repo updated image.

return baseImg, fallbackImg
}