From 1a01b9450cc12dbe664d89f676a441c4762635df Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Thu, 5 Mar 2020 10:23:51 -0800 Subject: [PATCH] Clarify logic around beginDownloadKicArtifacts --- pkg/minikube/node/cache.go | 19 ++++++++++++------- pkg/minikube/node/start.go | 13 ++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/pkg/minikube/node/cache.go b/pkg/minikube/node/cache.go index 15dc7e4018..67bf646ce7 100644 --- a/pkg/minikube/node/cache.go +++ b/pkg/minikube/node/cache.go @@ -35,8 +35,8 @@ import ( "k8s.io/minikube/pkg/minikube/out" ) -// beginCacheRequiredImages caches images required for kubernetes version in the background -func beginCacheRequiredImages(g *errgroup.Group, imageRepository string, k8sVersion string) { +// beginCacheKubernetesImages caches images required for kubernetes version in the background +func beginCacheKubernetesImages(g *errgroup.Group, imageRepository string, k8sVersion string) { if !viper.GetBool("cache-images") { return } @@ -82,17 +82,22 @@ func doCacheBinaries(k8sVersion string) error { return machine.CacheBinariesForBootstrapper(k8sVersion, viper.GetString(cmdcfg.Bootstrapper)) } -func beginDownloadKicArtifacts(g *errgroup.Group, k8sVersion, cRuntime string) { +// beginDownloadKicArtifacts downloads the kic image + preload tarball, returns true if preload is available +func beginDownloadKicArtifacts(g *errgroup.Group, k8sVersion, cRuntime string) bool { glog.Info("Beginning downloading kic artifacts") g.Go(func() error { glog.Infof("Downloading %s to local daemon", kic.BaseImage) return image.WriteImageToDaemon(kic.BaseImage) }) - g.Go(func() error { - glog.Info("Caching tarball of preloaded images") - return download.Preload(k8sVersion, cRuntime) - }) + if download.PreloadExists(k8sVersion, cRuntime) { + g.Go(func() error { + glog.Info("Caching tarball of preloaded images") + return download.Preload(k8sVersion, cRuntime) + }) + return true + } + return false } func waitDownloadKicArtifacts(g *errgroup.Group) { diff --git a/pkg/minikube/node/start.go b/pkg/minikube/node/start.go index f2a5507fc4..44a1667c46 100644 --- a/pkg/minikube/node/start.go +++ b/pkg/minikube/node/start.go @@ -23,7 +23,6 @@ import ( "golang.org/x/sync/errgroup" "k8s.io/minikube/pkg/addons" "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/download" "k8s.io/minikube/pkg/minikube/driver" "k8s.io/minikube/pkg/minikube/exit" "k8s.io/minikube/pkg/minikube/kubeconfig" @@ -41,17 +40,17 @@ func Start(mc config.ClusterConfig, n config.Node, primary bool, existingAddons // See if we can create a volume of preloaded images // If not, pull images in the background while the VM boots. var kicGroup errgroup.Group - downloadImages := true + needKubernetesImages := true if driver.IsKIC(driverName) { - if download.PreloadExists(k8sVersion, mc.KubernetesConfig.ContainerRuntime) { - beginDownloadKicArtifacts(&kicGroup, k8sVersion, mc.KubernetesConfig.ContainerRuntime) - downloadImages = false + // If we can download a preload tarball, it isn't necessary to pull Kubernetes images + if beginDownloadKicArtifacts(&kicGroup, k8sVersion, mc.KubernetesConfig.ContainerRuntime) { + needKubernetesImages = false } } var cacheGroup errgroup.Group - if downloadImages { - beginCacheRequiredImages(&cacheGroup, mc.KubernetesConfig.ImageRepository, k8sVersion) + if needKubernetesImages { + beginCacheKubernetesImages(&cacheGroup, mc.KubernetesConfig.ImageRepository, k8sVersion) } // Abstraction leakage alert: startHost requires the config to be saved, to satistfy pkg/provision/buildroot.