Skip to content

Commit 0ffd4cc

Browse files
committed
run: Remove viper.GetBool("download-only") checks
Add run.CommandOptions.DownloadOnly option and replace viper.GetBool("download-only") calls in minikube packages.
1 parent 74b0d69 commit 0ffd4cc

File tree

7 files changed

+15
-10
lines changed

7 files changed

+15
-10
lines changed

cmd/minikube/cmd/flags/flags.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import (
2323

2424
// Flag names passed to minikube via run.CommandOptions.
2525
const (
26-
Interactive = "interactive"
26+
Interactive = "interactive"
27+
DownloadOnly = "download-only"
2728
)
2829

2930
// CommandOptions returns minikube runtime options from command line flags.
@@ -32,5 +33,6 @@ const (
3233
func CommandOptions() *run.CommandOptions {
3334
return &run.CommandOptions{
3435
NonInteractive: !viper.GetBool(Interactive),
36+
DownloadOnly: viper.GetBool(DownloadOnly),
3537
}
3638
}

cmd/minikube/cmd/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ func validateDriver(ds registry.DriverState, existing *config.ClusterConfig) {
933933
}
934934

935935
// if we are only downloading artifacts for a driver, we can stop validation here
936-
if viper.GetBool("download-only") {
936+
if viper.GetBool(flags.DownloadOnly) {
937937
return
938938
}
939939

cmd/minikube/cmd/start_flags.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ const (
102102
vsockPorts = "hyperkit-vsock-ports"
103103
embedCerts = "embed-certs"
104104
noVTXCheck = "no-vtx-check"
105-
downloadOnly = "download-only"
106105
dnsProxy = "dns-proxy"
107106
hostDNSResolver = "host-dns-resolver"
108107
waitComponents = "wait"
@@ -167,7 +166,7 @@ func initMinikubeFlags() {
167166
startCmd.Flags().String(cpus, "2", fmt.Sprintf("Number of CPUs allocated to Kubernetes. Use %q to use the maximum number of CPUs. Use %q to not specify a limit (Docker/Podman only)", constants.MaxResources, constants.NoLimit))
168167
startCmd.Flags().StringP(memory, "m", "", fmt.Sprintf("Amount of RAM to allocate to Kubernetes (format: <number>[<unit>], where unit = b, k, m or g). Use %q to use the maximum amount of memory. Use %q to not specify a limit (Docker/Podman only)", constants.MaxResources, constants.NoLimit))
169168
startCmd.Flags().String(humanReadableDiskSize, defaultDiskSize, "Disk size allocated to the minikube VM (format: <number>[<unit>], where unit = b, k, m or g).")
170-
startCmd.Flags().Bool(downloadOnly, false, "If true, only download and cache files for later use - don't install or start anything.")
169+
startCmd.Flags().Bool(flags.DownloadOnly, false, "If true, only download and cache files for later use - don't install or start anything.")
171170
startCmd.Flags().Bool(cacheImages, true, "If true, cache docker images for the current bootstrapper and load them into the machine. Always false with --driver=none.")
172171
startCmd.Flags().StringSlice(isoURL, download.DefaultISOURLs(), "Locations to fetch the minikube ISO from.")
173172
startCmd.Flags().String(kicBaseImage, kic.BaseImage, "The base image to use for docker/podman drivers. Intended for local development.")

pkg/drivers/common/vmnet/vmnet.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232

3333
"github.com/docker/machine/libmachine/log"
3434
"github.com/docker/machine/libmachine/state"
35-
"github.com/spf13/viper"
3635
"k8s.io/minikube/pkg/minikube/out"
3736
"k8s.io/minikube/pkg/minikube/process"
3837
"k8s.io/minikube/pkg/minikube/reason"
@@ -76,7 +75,7 @@ func ValidateHelper(options *run.CommandOptions) error {
7675
// Ideally minikube will not try to validate in download-only mode, but this
7776
// is called from different places in different drivers, so the easier way
7877
// to skip validation is to skip it here.
79-
if viper.GetBool("download-only") {
78+
if options.DownloadOnly {
8079
log.Debug("Skipping vmnet-helper validation in download-only mode")
8180
return nil
8281
}

pkg/minikube/node/cache.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ func beginCacheKubernetesImages(g *errgroup.Group, imageRepository string, k8sVe
7575
}
7676

7777
// handleDownloadOnly caches appropariate binaries and images
78-
func handleDownloadOnly(cacheGroup, kicGroup *errgroup.Group, k8sVersion, containerRuntime, driverName string) {
78+
func handleDownloadOnly(cacheGroup, kicGroup *errgroup.Group, k8sVersion, containerRuntime, driverName string, options *run.CommandOptions) {
7979
// If --download-only, complete the remaining downloads and exit.
80-
if !viper.GetBool("download-only") {
80+
if !options.DownloadOnly {
8181
return
8282
}
8383

pkg/minikube/node/start.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ func Provision(cc *config.ClusterConfig, n *config.Node, delOnFail bool, options
387387
}
388388

389389
if driver.IsKIC(cc.Driver) {
390-
beginDownloadKicBaseImage(&kicGroup, cc, viper.GetBool("download-only"))
390+
beginDownloadKicBaseImage(&kicGroup, cc, options.DownloadOnly)
391391
}
392392

393393
if !driver.BareMetal(cc.Driver) {
@@ -400,7 +400,7 @@ func Provision(cc *config.ClusterConfig, n *config.Node, delOnFail bool, options
400400
return nil, false, nil, nil, errors.Wrap(err, "Failed to save config")
401401
}
402402

403-
handleDownloadOnly(&cacheGroup, &kicGroup, n.KubernetesVersion, cc.KubernetesConfig.ContainerRuntime, cc.Driver)
403+
handleDownloadOnly(&cacheGroup, &kicGroup, n.KubernetesVersion, cc.KubernetesConfig.ContainerRuntime, cc.Driver, options)
404404
if driver.IsKIC(cc.Driver) {
405405
waitDownloadKicBaseImage(&kicGroup)
406406
}

pkg/minikube/run/options.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@ type CommandOptions struct {
2121
// NonInteractive is true if the minikube command run with the
2222
// --interactive=false flag and we can not interact with the user.
2323
NonInteractive bool
24+
25+
// DownloadOnly is true if the minikube command run with the --download-only
26+
// flag and we should If only download and cache files for later use and
27+
// don't install or start anything.
28+
DownloadOnly bool
2429
}

0 commit comments

Comments
 (0)