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

Fix --base-image caching for images specified by name:tag #11603

Merged
merged 5 commits into from
Jun 25, 2021
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
35 changes: 31 additions & 4 deletions pkg/minikube/download/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package download

import (
"fmt"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -168,17 +169,43 @@ func ImageToCache(img string) error {
}
}

func parseImage(img string) (*name.Tag, name.Reference, error) {
digest, err := name.NewDigest(img)
if err == nil {
tag := digest.Tag()
return &tag, digest, nil
}

_, ok := err.(*name.ErrBadName)
medyagh marked this conversation as resolved.
Show resolved Hide resolved
if !ok {
return nil, nil, errors.Wrap(err, "new ref")
medyagh marked this conversation as resolved.
Show resolved Hide resolved
}
// ErrBadName means img contains no digest
// It happens if its value is name:tag for example.
// In this case we want to give it a second chance and try to parse it one more time using name.NewTag(img)
tag, err := name.NewTag(img)
if err != nil {
return nil, nil, errors.Wrap(err, "failed to parse image reference")
}
return &tag, tag, nil
}

// CacheToDaemon loads image from tarball in the local cache directory to the local docker daemon
func CacheToDaemon(img string) error {
p := imagePathInCache(img)

ref, err := name.NewDigest(img)
tag, ref, err := parseImage(img)
if err != nil {
return errors.Wrap(err, "new ref")
return err
}
// do not use cache if image is set in format <name>:latest
if _, ok := ref.(name.Tag); ok {
if tag.Name() == "latest" {
return fmt.Errorf("can't cache 'latest' tag")
}
}

tag := ref.Tag()
i, err := tarball.ImageFromPath(p, &tag)
i, err := tarball.ImageFromPath(p, tag)
if err != nil {
return errors.Wrap(err, "tarball")
}
Expand Down