Skip to content

Commit e414285

Browse files
committed
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.
1 parent a1de285 commit e414285

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

pkg/minikube/image/image.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,12 @@ func ExistsImageInDaemon(binary, img string) bool {
164164
return false
165165
}
166166

167-
// LoadFromTarball checks if the image exists as a tarball and tries to load it to the local daemon
168-
func LoadFromTarball(binary, img string) error {
169-
p := filepath.Join(constants.ImageCacheDir, img)
167+
// LoadImageFromCache loads img from the local cache directory
168+
func LoadImageFromCache(binary, img string) error {
169+
p := filepath.Join(constants.KICCacheDir, path.Base(img)+".tar")
170170
p = localpath.SanitizeCacheDir(p)
171171

172+
klog.Infof("Loading %s from local cache", img)
172173
switch binary {
173174
case driver.Podman:
174175
tag, err := name.NewTag(Tag(img))
@@ -181,7 +182,8 @@ func LoadFromTarball(binary, img string) error {
181182
return errors.Wrap(err, "tarball")
182183
}
183184

184-
_, err = PodmanWrite(tag, i)
185+
resp, err := PodmanWrite(tag, i)
186+
klog.V(2).Infof("response: %s", resp)
185187
return err
186188
case driver.Docker:
187189
tag, err := name.NewTag(Tag(img))
@@ -194,7 +196,8 @@ func LoadFromTarball(binary, img string) error {
194196
return errors.Wrap(err, "tarball")
195197
}
196198

197-
_, err = daemon.Write(tag, i)
199+
resp, err := daemon.Write(tag, i)
200+
klog.V(2).Infof("response: %s", resp)
198201
return err
199202
}
200203
return fmt.Errorf("unknown binary: %s", binary)

pkg/minikube/node/cache.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,16 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down
144144
if downloadOnly {
145145
return err
146146
}
147-
if err := image.LoadFromTarball(cc.Driver, img); err == nil {
147+
if err := image.LoadImageFromCache(cc.Driver, img); err == nil {
148148
klog.Infof("successfully loaded %s from cached tarball", img)
149149
// strip the digest from the img before saving it in the config
150150
// because loading an image from tarball to daemon doesn't load the digest
151151
finalImg = img
152152
return nil
153153
}
154154

155+
klog.Infof("failed to load %s, will try remote image if available: %v", img, err)
156+
155157
klog.Infof("Downloading %s to local daemon", img)
156158
if err = image.WriteImageToDaemon(cc.Driver, img); err == nil {
157159
klog.Infof("successfully downloaded %s", img)

0 commit comments

Comments
 (0)