load from tarball if cached kic image exists

pull/8417/head
Priya Wadhwa 2020-06-04 12:40:19 -07:00
parent 1f6e140e00
commit c629b9b81c
2 changed files with 26 additions and 7 deletions

View File

@ -34,8 +34,10 @@ import (
v1 "github.com/google/go-containerregistry/pkg/v1" v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/daemon" "github.com/google/go-containerregistry/pkg/v1/daemon"
"github.com/google/go-containerregistry/pkg/v1/remote" "github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/google/go-containerregistry/pkg/v1/tarball"
"github.com/pkg/errors" "github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/localpath"
) )
var defaultPlatform = v1.Platform{ var defaultPlatform = v1.Platform{
@ -94,6 +96,24 @@ func ExistsImageInDaemon(img string) bool {
return false return false
} }
// LoadFromTarball checks if the image exists as a tarball and tries to load it to the local daemon
func LoadFromTarball(img string) error {
p := filepath.Join(constants.ImageCacheDir, img)
p = localpath.SanitizeCacheDir(p)
tag, err := name.NewTag(img)
if err != nil {
return errors.Wrap(err, "tag")
}
i, err := tarball.ImageFromPath(p, &tag)
_, err = daemon.Write(tag, i)
if err != nil {
return errors.Wrap(err, "writing daemon image")
}
return nil
}
// Tag returns just the image with the tag // Tag returns just the image with the tag
// eg image:tag@sha256:digest -> image:tag if there is an associated tag // eg image:tag@sha256:digest -> image:tag if there is an associated tag
// if not possible, just return the initial img // if not possible, just return the initial img
@ -135,12 +155,6 @@ func WriteImageToDaemon(img string) error {
return nil return nil
} }
// Tarball writes the img to a tarball in the minikube cache
func Tarball(img string) error {
return nil
}
func retrieveImage(ref name.Reference) (v1.Image, error) { func retrieveImage(ref name.Reference) (v1.Image, error) {
glog.Infof("retrieving image: %+v", ref) glog.Infof("retrieving image: %+v", ref)
img, err := daemon.Image(ref) img, err := daemon.Image(ref)

View File

@ -126,6 +126,11 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down
} }
}() }()
for _, img := range append([]string{cc.KicBaseImage}, kic.FallbackImages...) { for _, img := range append([]string{cc.KicBaseImage}, kic.FallbackImages...) {
if err := image.LoadFromTarball(img); err == nil {
glog.Infof("successfully loaded %s from cached tarball", img)
finalImg = img
return nil
}
glog.Infof("Downloading %s to local daemon", img) glog.Infof("Downloading %s to local daemon", img)
err := image.WriteImageToDaemon(img) err := image.WriteImageToDaemon(img)
if err == nil { if err == nil {
@ -134,7 +139,7 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down
return nil return nil
} }
if downloadOnly { if downloadOnly {
if err := image.Tarball(img); err == nil { if err := image.SaveToDir([]string{img}, constants.ImageCacheDir); err == nil {
glog.Infof("successfully saved %s as a tarball", img) glog.Infof("successfully saved %s as a tarball", img)
finalImg = img finalImg = img
return nil return nil