From d6f60bbd4a9e31745cc92d2e4a5e425573eb92f8 Mon Sep 17 00:00:00 2001 From: Andriy Dzikh Date: Tue, 27 Apr 2021 16:36:32 -0700 Subject: [PATCH] Move image existence checks into downloading functions. --- pkg/minikube/download/image.go | 9 +++++++++ pkg/minikube/node/cache.go | 13 ++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/pkg/minikube/download/image.go b/pkg/minikube/download/image.go index 06cf774b05..e7f9d88fd7 100644 --- a/pkg/minikube/download/image.go +++ b/pkg/minikube/download/image.go @@ -75,6 +75,11 @@ func ImageExistsInDaemon(img string) bool { // ImageToCache writes img to the local cache directory func ImageToCache(img string) error { + if ImageExistsInCache(img) { + klog.Infof("%s exists in cache, skipping pull", img) + return nil + } + f := filepath.Join(constants.KICCacheDir, path.Base(img)+".tar") f = localpath.SanitizeCacheDir(f) @@ -140,6 +145,10 @@ func ImageToCache(img string) error { // ImageToDaemon writes img to the local docker daemon func ImageToDaemon(img string) error { + if ImageExistsInDaemon(img) { + klog.Infof("%s exists in daemon, skipping pull", img) + return nil + } // buffered channel c := make(chan v1.Update, 200) diff --git a/pkg/minikube/node/cache.go b/pkg/minikube/node/cache.go index 0af32e5e15..2e2bfb689e 100644 --- a/pkg/minikube/node/cache.go +++ b/pkg/minikube/node/cache.go @@ -127,16 +127,11 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down }() for _, img := range append([]string{baseImg}, kic.FallbackImages...) { var err error - if download.ImageExistsInCache(img) { - klog.Infof("%s exists in cache, skipping pull", img) + klog.Infof("Downloading %s to local cache", img) + err = download.ImageToCache(img) + if err == nil { + klog.Infof("successfully saved %s as a tarball", img) finalImg = img - } else { - klog.Infof("Downloading %s to local cache", img) - err = download.ImageToCache(img) - if err == nil { - klog.Infof("successfully saved %s as a tarball", img) - finalImg = img - } } if downloadOnly { return err