load from tarball if cached kic image exists
parent
1f6e140e00
commit
c629b9b81c
|
@ -34,8 +34,10 @@ import (
|
|||
v1 "github.com/google/go-containerregistry/pkg/v1"
|
||||
"github.com/google/go-containerregistry/pkg/v1/daemon"
|
||||
"github.com/google/go-containerregistry/pkg/v1/remote"
|
||||
"github.com/google/go-containerregistry/pkg/v1/tarball"
|
||||
"github.com/pkg/errors"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
"k8s.io/minikube/pkg/minikube/localpath"
|
||||
)
|
||||
|
||||
var defaultPlatform = v1.Platform{
|
||||
|
@ -94,6 +96,24 @@ func ExistsImageInDaemon(img string) bool {
|
|||
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
|
||||
// eg image:tag@sha256:digest -> image:tag if there is an associated tag
|
||||
// if not possible, just return the initial img
|
||||
|
@ -135,12 +155,6 @@ func WriteImageToDaemon(img string) error {
|
|||
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) {
|
||||
glog.Infof("retrieving image: %+v", ref)
|
||||
img, err := daemon.Image(ref)
|
||||
|
|
|
@ -126,6 +126,11 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down
|
|||
}
|
||||
}()
|
||||
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)
|
||||
err := image.WriteImageToDaemon(img)
|
||||
if err == nil {
|
||||
|
@ -134,7 +139,7 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down
|
|||
return nil
|
||||
}
|
||||
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)
|
||||
finalImg = img
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue