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 1 commit
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 @@ -72,10 +72,10 @@ func SaveToDir(images []string, cacheDir string) error {
}

// saveToTarFile caches an image
func saveToTarFile(image, dst string) error {
func saveToTarFile(iname, dst string) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be iName ? or imgName

start := time.Now()
defer func() {
glog.Infof("cache image %q -> %s to local destination -> %q", image, dst, time.Since(start))
glog.Infof("cache image %q -> %s to local destination -> %q", iname, dst, time.Since(start))
}()

if _, err := os.Stat(dst); err == nil {
Expand All @@ -92,15 +92,22 @@ func saveToTarFile(image, dst 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: ", dstPath)
f, err := ioutil.TempFile(filepath.Dir(dstPath), filepath.Base(dstPath)+".*.tmp")
if err != nil {
Expand All @@ -116,7 +123,7 @@ func saveToTarFile(image, dst 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