diff --git a/pkg/minikube/image/image.go b/pkg/minikube/image/image.go index 7c68a8c588..4bc72bc01d 100644 --- a/pkg/minikube/image/image.go +++ b/pkg/minikube/image/image.go @@ -18,6 +18,7 @@ package image import ( "context" + "fmt" "io/ioutil" "os" "os/exec" @@ -93,6 +94,18 @@ func ExistsImageInDaemon(img string) bool { return false } +// Tag returns just the image with the tag +// eg image:tag@sha256:digest -> image:tag if there is an associated tag +// if not possible, just return the initial img +func Tag(img string) string { + split := strings.Split(img, ":") + if len(split) == 3 { + tag := strings.Split(split[1], "@")[0] + return fmt.Sprintf("%s:%s", split[0], tag) + } + return img +} + // WriteImageToDaemon write img to the local docker daemon func WriteImageToDaemon(img string) error { glog.Infof("Writing %s to local daemon", img) diff --git a/pkg/minikube/image/image_test.go b/pkg/minikube/image/image_test.go new file mode 100644 index 0000000000..5546593442 --- /dev/null +++ b/pkg/minikube/image/image_test.go @@ -0,0 +1,48 @@ +/* +Copyright 2020 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package image + +import "testing" + +func TestTag(t *testing.T) { + tcs := []struct { + image string + expected string + }{ + { + image: "image:tag@sha256:digest", + expected: "image:tag", + }, { + image: "image:tag", + expected: "image:tag", + }, { + image: "image@sha256:digest", + expected: "image@sha256:digest", + }, { + image: "image", + expected: "image", + }, + } + for _, tc := range tcs { + t.Run(tc.image, func(t *testing.T) { + actual := Tag(tc.image) + if actual != tc.expected { + t.Errorf("actual does not match expected\nActual:%v\nExpected:%v\n", actual, tc.expected) + } + }) + } +} diff --git a/pkg/minikube/node/cache.go b/pkg/minikube/node/cache.go index 995c9ce1d5..cae0144d7c 100644 --- a/pkg/minikube/node/cache.go +++ b/pkg/minikube/node/cache.go @@ -122,7 +122,7 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig) { err := image.WriteImageToDaemon(img) if err == nil { if img != cc.KicBaseImage { - out.WarningT(fmt.Sprintf("minikube was unable to download %s, but successfully downloaded %s\n minikube will use %s as a fallback image", cc.KicBaseImage, img, img)) + out.WarningT(fmt.Sprintf("minikube was unable to download %s, but successfully downloaded %s\n minikube will use %s as a fallback image", image.Tag(cc.KicBaseImage), image.Tag(img), image.Tag(img))) cc.KicBaseImage = img } glog.Infof("successfully downloaded %s", img)