make warning output prettier by including tags

pull/8373/head
Priya Wadhwa 2020-06-04 12:11:54 -07:00
parent 15088526cd
commit de81670130
3 changed files with 62 additions and 1 deletions

View File

@ -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)

View File

@ -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)
}
})
}
}

View File

@ -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)