Skip to content

Commit

Permalink
Add --download-only option to start command
Browse files Browse the repository at this point in the history
Make it possible to download files without loading or installing,
and without starting the host... Download: ISO, binaries, images.
  • Loading branch information
afbjorklund committed Mar 26, 2019
1 parent 54f68e0 commit 0ebfe46
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cmd/minikube/cmd/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ func imagesInConfigFile() ([]string, error) {
return []string{}, nil
}

// CacheImagesInConfigFile caches the images currently in the config file (minikube start)
func CacheImagesInConfigFile() error {
images, err := imagesInConfigFile()
if err != nil {
return err
}
if len(images) == 0 {
return nil
}
return machine.CacheImages(images, constants.ImageCacheDir)
}

// LoadCachedImagesInConfigFile loads the images currently in the config file (minikube start)
func LoadCachedImagesInConfigFile() error {
images, err := imagesInConfigFile()
Expand Down
23 changes: 23 additions & 0 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const (
hidden = "hidden"
embedCerts = "embed-certs"
noVTXCheck = "no-vtx-check"
downloadOnly = "download-only"
)

var (
Expand Down Expand Up @@ -136,6 +137,7 @@ func init() {
startCmd.Flags().Bool(enableDefaultCNI, false, "Enable the default CNI plugin (/etc/cni/net.d/k8s.conf). Used in conjunction with \"--network-plugin=cni\"")
startCmd.Flags().String(featureGates, "", "A set of key=value pairs that describe feature gates for alpha/experimental features.")
startCmd.Flags().Bool(cacheImages, true, "If true, cache docker images for the current bootstrapper and load them into the machine.")
startCmd.Flags().Bool(downloadOnly, false, "If true, only download and cache files for later use - don't install or start anything.")
startCmd.Flags().Var(&extraOptions, "extra-config",
`A set of key=value pairs that describe configuration that may be passed to different components.
The key should be '.' separated, and the first part before the dot is the component to apply the configuration to.
Expand Down Expand Up @@ -187,6 +189,22 @@ func runStart(cmd *cobra.Command, args []string) {
if err != nil {
exit.WithError("Failed to get machine client", err)
}

if viper.GetBool(downloadOnly) {
if err := cluster.CacheISO(config.MachineConfig); err != nil {
exit.WithError("Failed to cache ISO", err)
}
if err := doCacheBinaries(k8sVersion); err != nil {
exit.WithError("Failed to cache binaries", err)
}
waitCacheImages(&cacheGroup)
if err := CacheImagesInConfigFile(); err != nil {
exit.WithError("Failed to cache images", err)
}
console.OutStyle("check", "Download complete!")
return
}

host, preexisting := startHost(m, config.MachineConfig)

ip := validateNetwork(host)
Expand Down Expand Up @@ -245,6 +263,11 @@ func validateConfig() {
}
}

// doCacheBinaries caches Kubernetes binaries in the foreground
func doCacheBinaries(k8sVersion string) error {
return machine.CacheBinariesForBootstrapper(k8sVersion, viper.GetString(cmdcfg.Bootstrapper))
}

// beginCacheImages caches Docker images in the background
func beginCacheImages(g *errgroup.Group, k8sVersion string) {
if !viper.GetBool(cacheImages) {
Expand Down
10 changes: 10 additions & 0 deletions pkg/minikube/bootstrapper/bootstrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ const (
BootstrapperTypeKubeadm = "kubeadm"
)

// GetCachedBinaryList returns the list of binaries
func GetCachedBinaryList(bootstrapper string) []string {
switch bootstrapper {
case BootstrapperTypeKubeadm:
return constants.GetKubeadmCachedBinaries()
default:
return []string{}
}
}

// GetCachedImageList returns the list of images for a version
func GetCachedImageList(imageRepository string, version string, bootstrapper string) []string {
switch bootstrapper {
Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/console/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var styles = map[string]style{
"documentation": {Prefix: "🗎 "},
"issues": {Prefix: "📚 "},
"issue": {Prefix: " ▪ "}, // Indented bullet
"check": {Prefix: "✔️ "},

// Specialized purpose styles
"iso-download": {Prefix: "💿 ", LowPrefix: "@ "},
Expand Down
17 changes: 17 additions & 0 deletions pkg/minikube/machine/cache_binaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ import (
"k8s.io/minikube/pkg/minikube/constants"
)

// CacheBinariesForBootstrapper will cache binaries for a bootstrapper
func CacheBinariesForBootstrapper(version string, clusterBootstrapper string) error {
binaries := bootstrapper.GetCachedBinaryList(clusterBootstrapper)

var g errgroup.Group
for _, bin := range binaries {
bin := bin
g.Go(func() error {
if _, err := CacheBinary(bin, version); err != nil {
return errors.Wrapf(err, "caching image %s", bin)
}
return nil
})
}
return g.Wait()
}

// CacheBinary will cache a binary on the host
func CacheBinary(binary, version string) (string, error) {
targetDir := constants.MakeMiniPath("cache", version)
Expand Down

0 comments on commit 0ebfe46

Please sign in to comment.