Merge pull request #6874 from priyawadhwa/skip-cache

Only cache k8s images if necessary
pull/6880/head
Medya Ghazizadeh 2020-03-04 19:06:47 -08:00 committed by GitHub
commit 5b6c7835b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 5 deletions

View File

@ -29,6 +29,7 @@ import (
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/logs"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/preload"
"k8s.io/minikube/pkg/util"
)
@ -45,7 +46,10 @@ func Start(mc config.ClusterConfig, n config.Node, primary bool, existingAddons
}
// Now that the ISO is downloaded, pull images in the background while the VM boots.
var cacheGroup errgroup.Group
beginCacheRequiredImages(&cacheGroup, mc.KubernetesConfig.ImageRepository, k8sVersion)
skipCacheImages := driver.IsKIC(driverName) && preload.TarballExists(k8sVersion, mc.KubernetesConfig.ContainerRuntime)
if !skipCacheImages {
beginCacheRequiredImages(&cacheGroup, mc.KubernetesConfig.ImageRepository, k8sVersion)
}
// Abstraction leakage alert: startHost requires the config to be saved, to satistfy pkg/provision/buildroot.
// Hence, saveConfig must be called before startHost, and again afterwards when we know the IP.

View File

@ -67,6 +67,17 @@ func remoteTarballURL(k8sVersion string) string {
return fmt.Sprintf("https://storage.googleapis.com/%s/%s", constants.PreloadedVolumeTarballsBucket, tarballName(k8sVersion))
}
// TarballExists returns true if there is a preloaded tarball
// that can be used
func TarballExists(k8sVersion, containerRuntime string) bool {
if containerRuntime != "docker" {
return false
}
url := remoteTarballURL(k8sVersion)
_, err := http.Head(url)
return err == nil
}
// CacheTarball caches the preloaded images tarball on the host machine
func CacheTarball(k8sVersion, containerRuntime string) error {
if containerRuntime != "docker" {
@ -81,15 +92,14 @@ func CacheTarball(k8sVersion, containerRuntime string) error {
}
}
url := remoteTarballURL(k8sVersion)
// Make sure we support this k8s version
if _, err := http.Get(url); err != nil {
glog.Infof("Unable to get response from %s, skipping downloading: %v", url, err)
if !TarballExists(k8sVersion, containerRuntime) {
glog.Infof("Preloaded tarball for k8s version %s does not exist", k8sVersion)
return nil
}
out.T(out.FileDownload, "Downloading preloaded images tarball for k8s {{.version}} ...", out.V{"version": k8sVersion})
url := remoteTarballURL(k8sVersion)
client := &getter.Client{
Src: url,
Dst: targetFilepath,