diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 63de1fd38892..400be798e2dc 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -88,8 +88,11 @@ assumes you have already installed one of the VM drivers: virtualbox/vmwarefusio func runStart(cmd *cobra.Command, args []string) { shouldCacheImages := viper.GetBool(cacheImages) + k8sVersion := viper.GetString(kubernetesVersion) + clusterBootstrapper := viper.GetString(cmdcfg.Bootstrapper) + if shouldCacheImages { - go machine.CacheImagesForBootstrapper(viper.GetString(cmdcfg.Bootstrapper)) + go machine.CacheImagesForBootstrapper(k8sVersion, clusterBootstrapper) } api, err := machine.NewAPIClient() if err != nil { @@ -112,8 +115,8 @@ func runStart(cmd *cobra.Command, args []string) { os.Exit(1) } - if dv := viper.GetString(kubernetesVersion); dv != constants.DefaultKubernetesVersion { - validateK8sVersion(dv) + if k8sVersion != constants.DefaultKubernetesVersion { + validateK8sVersion(k8sVersion) } config := cluster.MachineConfig{ @@ -195,7 +198,7 @@ func runStart(cmd *cobra.Command, args []string) { ShouldLoadCachedImages: shouldCacheImages, } - clusterBootstrapper, err := GetClusterBootstrapper(api, viper.GetString(cmdcfg.Bootstrapper)) + k8sBootstrapper, err := GetClusterBootstrapper(api, clusterBootstrapper) if err != nil { glog.Exitf("Error getting cluster bootstrapper: %s", err) } @@ -211,13 +214,13 @@ func runStart(cmd *cobra.Command, args []string) { } fmt.Println("Moving files into cluster...") - if err := clusterBootstrapper.UpdateCluster(kubernetesConfig); err != nil { + if err := k8sBootstrapper.UpdateCluster(kubernetesConfig); err != nil { glog.Errorln("Error updating cluster: ", err) cmdUtil.MaybeReportErrorAndExit(err) } fmt.Println("Setting up certs...") - if err := clusterBootstrapper.SetupCerts(kubernetesConfig); err != nil { + if err := k8sBootstrapper.SetupCerts(kubernetesConfig); err != nil { glog.Errorln("Error configuring authentication: ", err) cmdUtil.MaybeReportErrorAndExit(err) } @@ -253,12 +256,12 @@ func runStart(cmd *cobra.Command, args []string) { fmt.Println("Starting cluster components...") if !exists { - if err := clusterBootstrapper.StartCluster(kubernetesConfig); err != nil { + if err := k8sBootstrapper.StartCluster(kubernetesConfig); err != nil { glog.Errorln("Error starting cluster: ", err) cmdUtil.MaybeReportErrorAndExit(err) } } else { - if err := clusterBootstrapper.RestartCluster(kubernetesConfig); err != nil { + if err := k8sBootstrapper.RestartCluster(kubernetesConfig); err != nil { glog.Errorln("Error restarting cluster: ", err) cmdUtil.MaybeReportErrorAndExit(err) } diff --git a/pkg/minikube/bootstrapper/bootstrapper.go b/pkg/minikube/bootstrapper/bootstrapper.go index 11236e1dbd8c..d906470267fb 100644 --- a/pkg/minikube/bootstrapper/bootstrapper.go +++ b/pkg/minikube/bootstrapper/bootstrapper.go @@ -51,6 +51,13 @@ const ( BootstrapperTypeKubeadm = "kubeadm" ) -var CachedImagesForBootstrapper = map[string][]string{ - BootstrapperTypeLocalkube: constants.LocalkubeCachedImages, +func GetCachedImageList(version string, bootstrapper string) []string { + switch bootstrapper { + case BootstrapperTypeLocalkube: + return constants.LocalkubeCachedImages + case BootstrapperTypeKubeadm: + return constants.GetKubeadmCachedImages(version) + default: + return []string{} + } } diff --git a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go index 74ddbed5c56b..73f46ce7d98b 100644 --- a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go +++ b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go @@ -35,6 +35,7 @@ import ( "k8s.io/minikube/pkg/minikube/bootstrapper" "k8s.io/minikube/pkg/minikube/config" "k8s.io/minikube/pkg/minikube/constants" + "k8s.io/minikube/pkg/minikube/machine" "k8s.io/minikube/pkg/minikube/sshutil" "k8s.io/minikube/pkg/util" ) @@ -174,7 +175,7 @@ func (k *KubeadmBootstrapper) StartCluster(k8s bootstrapper.KubernetesConfig) er func addAddons(files *[]assets.CopyableFile) error { // add addons to file list // custom addons - assets.AddMinikubeAddonsDirToAssets(files) + assets.AddMinikubeDirToAssets("addons", constants.AddonsPath, files) // bundled addons for addonName, addonBundle := range assets.Addons { // TODO(r2d4): Kubeadm ignores the kube-dns addon and uses its own. @@ -228,6 +229,10 @@ func (k *KubeadmBootstrapper) SetupCerts(k8s bootstrapper.KubernetesConfig) erro } func (k *KubeadmBootstrapper) UpdateCluster(cfg bootstrapper.KubernetesConfig) error { + if cfg.ShouldLoadCachedImages { + // Make best effort to load any cached images + go machine.LoadImages(k.c, constants.GetKubeadmCachedImages(cfg.KubernetesVersion), constants.ImageCacheDir) + } kubeadmCfg, err := k.generateConfig(cfg) if err != nil { return errors.Wrap(err, "generating kubeadm cfg") diff --git a/pkg/minikube/bootstrapper/localkube/localkube.go b/pkg/minikube/bootstrapper/localkube/localkube.go index 8efa2230e61f..9da544bc2e84 100644 --- a/pkg/minikube/bootstrapper/localkube/localkube.go +++ b/pkg/minikube/bootstrapper/localkube/localkube.go @@ -109,7 +109,6 @@ func (lk *LocalkubeBootstrapper) UpdateCluster(config bootstrapper.KubernetesCon if config.ShouldLoadCachedImages { // Make best effort to load any cached images go machine.LoadImages(lk.cmd, constants.LocalkubeCachedImages, constants.ImageCacheDir) - } copyableFiles := []assets.CopyableFile{} diff --git a/pkg/minikube/constants/constants.go b/pkg/minikube/constants/constants.go index 6b67fdc25a7f..5fca6a6b53b9 100644 --- a/pkg/minikube/constants/constants.go +++ b/pkg/minikube/constants/constants.go @@ -181,4 +181,30 @@ var LocalkubeCachedImages = []string{ "gcr.io/google_containers/pause-amd64:3.0", } +func GetKubeadmCachedImages(version string) []string { + return []string{ + // Dashboard + "gcr.io/google_containers/kubernetes-dashboard-amd64:v1.6.3", + + // Addon Manager + "gcr.io/google-containers/kube-addon-manager:v6.4-beta.2", + + // Pause + "gcr.io/google_containers/pause-amd64:3.0", + + // DNS + "gcr.io/google_containers/k8s-dns-kube-dns-amd64:1.14.4", + "gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64:1.14.4", + "gcr.io/google_containers/k8s-dns-sidecar-amd64:1.14.4", + + // etcd + "gcr.io/google_containers/etcd-amd64:3.0.17", + + "gcr.io/google_containers/kube-proxy-amd64:" + version, + "gcr.io/google_containers/kube-scheduler-amd64:" + version, + "gcr.io/google_containers/kube-controller-manager-amd64:" + version, + "gcr.io/google_containers/kube-apiserver-amd64:" + version, + } +} + var ImageCacheDir = MakeMiniPath("cache", "images") diff --git a/pkg/minikube/machine/cache_images.go b/pkg/minikube/machine/cache_images.go index 7c182f58ecb9..2a599bbb0ec1 100644 --- a/pkg/minikube/machine/cache_images.go +++ b/pkg/minikube/machine/cache_images.go @@ -39,12 +39,8 @@ import ( const tempLoadDir = "/tmp" -func CacheImagesForBootstrapper(clusterBootstrapper string) error { - images, ok := bootstrapper.CachedImagesForBootstrapper[clusterBootstrapper] - if !ok { - glog.Infoln("Could not find list of images to cache for bootstrapper %s", clusterBootstrapper) - return nil - } +func CacheImagesForBootstrapper(version string, clusterBootstrapper string) error { + images := bootstrapper.GetCachedImageList(version, clusterBootstrapper) if err := CacheImages(images, constants.ImageCacheDir); err != nil { return errors.Wrapf(err, "Caching images for %s", clusterBootstrapper)