Load kicbase image from right cache and add log
It was silently failing to load from the (wrong) cache directory, causing the image to be download twice from the network instead. Add new function to get the path in the cache directory, so that we don't have to duplicate that both inside and outside module.pull/11346/head
parent
d61989afa9
commit
580161ad1c
|
@ -43,10 +43,16 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// imageExistsInCache if img exist in local cache directory
|
// ImagePathInCache returns path in local cache directory
|
||||||
func imageExistsInCache(img string) bool {
|
func ImagePathInCache(img string) string {
|
||||||
f := filepath.Join(constants.KICCacheDir, path.Base(img)+".tar")
|
f := filepath.Join(constants.KICCacheDir, path.Base(img)+".tar")
|
||||||
f = localpath.SanitizeCacheDir(f)
|
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
|
// Check if image exists locally
|
||||||
klog.Infof("Checking for %s in local cache directory", img)
|
klog.Infof("Checking for %s in local cache directory", img)
|
||||||
|
@ -60,7 +66,7 @@ func imageExistsInCache(img string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
var checkImageExistsInCache = imageExistsInCache
|
var checkImageExistsInCache = ImageExistsInCache
|
||||||
|
|
||||||
// ImageExistsInDaemon if img exist in local docker daemon
|
// ImageExistsInDaemon if img exist in local docker daemon
|
||||||
func ImageExistsInDaemon(img string) bool {
|
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
|
// ImageToCache downloads img (if not present in cache) and writes it to the local cache directory
|
||||||
func ImageToCache(img string) error {
|
func ImageToCache(img string) error {
|
||||||
f := filepath.Join(constants.KICCacheDir, path.Base(img)+".tar")
|
f := ImagePathInCache(img)
|
||||||
f = localpath.SanitizeCacheDir(f)
|
|
||||||
fileLock := f + ".lock"
|
fileLock := f + ".lock"
|
||||||
|
|
||||||
releaser, err := lockDownload(fileLock)
|
releaser, err := lockDownload(fileLock)
|
||||||
|
|
|
@ -39,7 +39,6 @@ import (
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
"k8s.io/minikube/pkg/minikube/constants"
|
"k8s.io/minikube/pkg/minikube/constants"
|
||||||
"k8s.io/minikube/pkg/minikube/driver"
|
"k8s.io/minikube/pkg/minikube/driver"
|
||||||
"k8s.io/minikube/pkg/minikube/localpath"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -104,12 +103,8 @@ func DigestByGoLib(imgName string) string {
|
||||||
return cf.Hex
|
return cf.Hex
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadFromTarball checks if the image exists as a tarball and tries to load it to the local daemon
|
// LoadFromTarball loads image from tarball
|
||||||
// TODO: Pass in if we are loading to docker or podman so this function can also be used for podman
|
func LoadFromTarball(binary, img, p string) error {
|
||||||
func LoadFromTarball(binary, img string) error {
|
|
||||||
p := filepath.Join(constants.ImageCacheDir, img)
|
|
||||||
p = localpath.SanitizeCacheDir(p)
|
|
||||||
|
|
||||||
switch binary {
|
switch binary {
|
||||||
case driver.Podman:
|
case driver.Podman:
|
||||||
return fmt.Errorf("not yet implemented, see issue #8426")
|
return fmt.Errorf("not yet implemented, see issue #8426")
|
||||||
|
@ -124,10 +119,10 @@ func LoadFromTarball(binary, img string) error {
|
||||||
return errors.Wrap(err, "tarball")
|
return errors.Wrap(err, "tarball")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = daemon.Write(tag, i)
|
resp, err := daemon.Write(tag, i)
|
||||||
|
klog.V(2).Infof("response: %s", resp)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tag returns just the image with the tag
|
// Tag returns just the image with the tag
|
||||||
|
|
|
@ -145,7 +145,8 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := image.LoadFromTarball(cc.Driver, img); err == nil {
|
klog.Infof("Loading %s from local cache", img)
|
||||||
|
if err := image.LoadFromTarball(cc.Driver, img, download.ImagePathInCache(img)); err == nil {
|
||||||
klog.Infof("successfully loaded %s from cached tarball", img)
|
klog.Infof("successfully loaded %s from cached tarball", img)
|
||||||
// strip the digest from the img before saving it in the config
|
// 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
|
// because loading an image from tarball to daemon doesn't load the digest
|
||||||
|
@ -154,6 +155,8 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down
|
||||||
}
|
}
|
||||||
|
|
||||||
if driver.IsDocker(cc.Driver) {
|
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)
|
klog.Infof("Downloading %s to local daemon", img)
|
||||||
err = download.ImageToDaemon(img)
|
err = download.ImageToDaemon(img)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
Loading…
Reference in New Issue