Merge pull request #11346 from afbjorklund/kicbase-load
Load kicbase image from right cache and add logpull/11537/head
commit
0d3c246f03
|
@ -43,10 +43,16 @@ var (
|
|||
}
|
||||
)
|
||||
|
||||
// imageExistsInCache if img exist in local cache directory
|
||||
func imageExistsInCache(img string) bool {
|
||||
// imagePathInCache returns path in local cache directory
|
||||
func imagePathInCache(img string) string {
|
||||
f := filepath.Join(constants.KICCacheDir, path.Base(img)+".tar")
|
||||
f = localpath.SanitizeCacheDir(f)
|
||||
return f
|
||||
}
|
||||
|
||||
// ImageExistsInCache if img exist in local cache directory
|
||||
func ImageExistsInCache(img string) bool {
|
||||
f := imagePathInCache(img)
|
||||
|
||||
// Check if image exists locally
|
||||
klog.Infof("Checking for %s in local cache directory", img)
|
||||
|
@ -60,7 +66,7 @@ func imageExistsInCache(img string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
var checkImageExistsInCache = imageExistsInCache
|
||||
var checkImageExistsInCache = ImageExistsInCache
|
||||
|
||||
// ImageExistsInDaemon if img exist in local docker daemon
|
||||
func ImageExistsInDaemon(img string) bool {
|
||||
|
@ -81,8 +87,7 @@ var checkImageExistsInDaemon = ImageExistsInDaemon
|
|||
|
||||
// ImageToCache downloads img (if not present in cache) and writes it to the local cache directory
|
||||
func ImageToCache(img string) error {
|
||||
f := filepath.Join(constants.KICCacheDir, path.Base(img)+".tar")
|
||||
f = localpath.SanitizeCacheDir(f)
|
||||
f := imagePathInCache(img)
|
||||
fileLock := f + ".lock"
|
||||
|
||||
releaser, err := lockDownload(fileLock)
|
||||
|
@ -163,6 +168,26 @@ func ImageToCache(img string) error {
|
|||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "new ref")
|
||||
}
|
||||
|
||||
tag := ref.Tag()
|
||||
i, err := tarball.ImageFromPath(p, &tag)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "tarball")
|
||||
}
|
||||
|
||||
resp, err := daemon.Write(ref, i)
|
||||
klog.V(2).Infof("response: %s", resp)
|
||||
return err
|
||||
}
|
||||
|
||||
// ImageToDaemon downloads img (if not present in daemon) and writes it to the local docker daemon
|
||||
func ImageToDaemon(img string) error {
|
||||
fileLock := filepath.Join(constants.KICCacheDir, path.Base(img)+".d.lock")
|
||||
|
|
|
@ -33,13 +33,10 @@ import (
|
|||
"github.com/google/go-containerregistry/pkg/v1/daemon"
|
||||
"github.com/google/go-containerregistry/pkg/v1/mutate"
|
||||
"github.com/google/go-containerregistry/pkg/v1/remote"
|
||||
"github.com/google/go-containerregistry/pkg/v1/tarball"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
"k8s.io/minikube/pkg/minikube/driver"
|
||||
"k8s.io/minikube/pkg/minikube/localpath"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -104,32 +101,6 @@ func DigestByGoLib(imgName string) string {
|
|||
return cf.Hex
|
||||
}
|
||||
|
||||
// LoadFromTarball checks if the image exists as a tarball and tries to load it to the local daemon
|
||||
// TODO: Pass in if we are loading to docker or podman so this function can also be used for podman
|
||||
func LoadFromTarball(binary, img string) error {
|
||||
p := filepath.Join(constants.ImageCacheDir, img)
|
||||
p = localpath.SanitizeCacheDir(p)
|
||||
|
||||
switch binary {
|
||||
case driver.Podman:
|
||||
return fmt.Errorf("not yet implemented, see issue #8426")
|
||||
default:
|
||||
tag, err := name.NewTag(Tag(img))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "new tag")
|
||||
}
|
||||
|
||||
i, err := tarball.ImageFromPath(p, &tag)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "tarball")
|
||||
}
|
||||
|
||||
_, err = daemon.Write(tag, i)
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 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
|
||||
|
|
|
@ -149,15 +149,22 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down
|
|||
}
|
||||
}
|
||||
|
||||
if err := image.LoadFromTarball(cc.Driver, img); err == nil {
|
||||
klog.Infof("successfully loaded %s from cached tarball", img)
|
||||
// strip the digest from the img before saving it in the config
|
||||
// because loading an image from tarball to daemon doesn't load the digest
|
||||
finalImg = img
|
||||
return nil
|
||||
if cc.Driver == driver.Podman {
|
||||
return fmt.Errorf("not yet implemented, see issue #8426")
|
||||
}
|
||||
if driver.IsDocker(cc.Driver) {
|
||||
klog.Infof("Loading %s from local cache", img)
|
||||
err = download.CacheToDaemon(img)
|
||||
if err == nil {
|
||||
klog.Infof("successfully loaded %s from cached tarball", img)
|
||||
finalImg = img
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
if driver.IsDocker(cc.Driver) {
|
||||
klog.Infof("failed to load %s, will try remote image if available: %v", img, err)
|
||||
|
||||
klog.Infof("Downloading %s to local daemon", img)
|
||||
err = download.ImageToDaemon(img)
|
||||
if err == nil {
|
||||
|
|
Loading…
Reference in New Issue