Clarify logic around beginDownloadKicArtifacts

pull/6892/head
Thomas Stromberg 2020-03-05 10:23:51 -08:00
parent 1f7ae5b35b
commit 1a01b9450c
2 changed files with 18 additions and 14 deletions

View File

@ -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) {

View File

@ -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.