Skip to content

Commit

Permalink
Merge pull request #10811 from tripolkaandrey/improve/cache-add-not-e…
Browse files Browse the repository at this point in the history
…xisting-image-error-message

cache add: improved error message when image does not exist
  • Loading branch information
medyagh committed Mar 25, 2021
2 parents eee2254 + b7976f6 commit 4224612
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions pkg/minikube/image/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,21 @@ import (
"k8s.io/klog/v2"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/util/lock"
)

type cacheError struct {
Err error
}

func (f *cacheError) Error() string {
return f.Err.Error()
}

// errCacheImageDoesntExist is thrown when image that user is trying to add does not exist
var errCacheImageDoesntExist = &cacheError{errors.New("the image you are trying to add does not exist")}

// DeleteFromCacheDir deletes tar files stored in cache dir
func DeleteFromCacheDir(images []string) error {
for _, image := range images {
Expand All @@ -60,8 +72,11 @@ func SaveToDir(images []string, cacheDir string) error {
dst := filepath.Join(cacheDir, image)
dst = localpath.SanitizeCacheDir(dst)
if err := saveToTarFile(image, dst); err != nil {
klog.Errorf("save image to file %q -> %q failed: %v", image, dst, err)
return errors.Wrapf(err, "caching image %q", dst)
if err == errCacheImageDoesntExist {
out.WarningT("The image you are trying to add {{.imageName}} doesn't exist!", out.V{"imageName": image})
} else {
return errors.Wrapf(err, "caching image %q", dst)
}
}
klog.Infof("save to tar file %s -> %s succeeded", image, dst)
return nil
Expand Down Expand Up @@ -116,7 +131,7 @@ func saveToTarFile(iname, rawDest string) error {

img, err := retrieveImage(ref)
if err != nil {
klog.Warningf("unable to retrieve image: %v", err)
return errCacheImageDoesntExist
}
if img == nil {
return errors.Wrapf(err, "nil image for %s", iname)
Expand Down

0 comments on commit 4224612

Please sign in to comment.