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

Check for nil ref and img before passing them into go-containerregistry #6236

Merged
merged 2 commits into from
Jan 22, 2020
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
17 changes: 12 additions & 5 deletions pkg/minikube/image/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ func SaveToDir(images []string, cacheDir string) error {
}

// saveToTarFile caches an image
func saveToTarFile(image, rawDest string) error {
func saveToTarFile(iname, rawDest string) error {
start := time.Now()
defer func() {
glog.Infof("cache image %q -> %q took %s", image, rawDest, time.Since(start))
glog.Infof("cache image %q -> %q took %s", iname, rawDest, time.Since(start))
}()

// OS-specific mangling of destination path
Expand All @@ -104,15 +104,22 @@ func saveToTarFile(image, rawDest string) error {
return errors.Wrapf(err, "making cache image directory: %s", dst)
}

ref, err := name.ParseReference(image, name.WeakValidation)
ref, err := name.ParseReference(iname, name.WeakValidation)
if err != nil {
return errors.Wrapf(err, "parsing image ref name for %s", image)
return errors.Wrapf(err, "parsing image ref name for %s", iname)
}
if ref == nil {
return errors.Wrapf(err, "nil reference for %s", iname)
}

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

glog.Infoln("opening: ", dst)
f, err := ioutil.TempFile(filepath.Dir(dst), filepath.Base(dst)+".*.tmp")
if err != nil {
Expand All @@ -128,7 +135,7 @@ func saveToTarFile(image, rawDest string) error {
}
}
}()
tag, err := name.NewTag(image, name.WeakValidation)
tag, err := name.NewTag(iname, name.WeakValidation)
if err != nil {
return errors.Wrap(err, "newtag")
}
Expand Down