Skip to content

Commit

Permalink
Add caching for kubeadm
Browse files Browse the repository at this point in the history
  • Loading branch information
r2d4 committed Sep 6, 2017
1 parent ca3c0b5 commit c27f52e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 18 deletions.
19 changes: 11 additions & 8 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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{
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
11 changes: 9 additions & 2 deletions pkg/minikube/bootstrapper/bootstrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
}
7 changes: 6 additions & 1 deletion pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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")
Expand Down
1 change: 0 additions & 1 deletion pkg/minikube/bootstrapper/localkube/localkube.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
26 changes: 26 additions & 0 deletions pkg/minikube/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
8 changes: 2 additions & 6 deletions pkg/minikube/machine/cache_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c27f52e

Please sign in to comment.