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

cache add: improved error message when image does not exist #10811

Merged
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
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