Skip to content

Commit d98d710

Browse files
committed
run: Pass command options to drivers
Some drivers need command line options since they need to pass command line options back to minikube firewall package. The way to pass command line options to the driver is via the NewDriver function, called by the registry Loader function. The registry Loader function is called by machine.LocalClient.Load, which is part of the limachine API interface, which is not part of minikube so we cannot change it. We pass the options to machine.NewAPIClient(), so the client can pass the options to Load(). Some drivers need to validate vment helper in the registry StatusChecker function, considering the --interactive and --download-only flags. So we pas the options to the StatusChecker function. This change create the options in most commands that call machine.NewAPIClient or registry StatusChecker function and pass the options down.
1 parent 539567b commit d98d710

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+531
-366
lines changed

cmd/minikube/cmd/cache.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/spf13/viper"
2222
"k8s.io/klog/v2"
2323
cmdConfig "k8s.io/minikube/cmd/minikube/cmd/config"
24+
"k8s.io/minikube/cmd/minikube/cmd/flags"
2425
"k8s.io/minikube/pkg/minikube/config"
2526
"k8s.io/minikube/pkg/minikube/exit"
2627
"k8s.io/minikube/pkg/minikube/image"
@@ -49,8 +50,9 @@ var addCacheCmd = &cobra.Command{
4950
Long: "Add an image to local cache.",
5051
Run: func(_ *cobra.Command, args []string) {
5152
out.WarningT("\"minikube cache\" will be deprecated in upcoming versions, please switch to \"minikube image load\"")
53+
options := flags.CommandOptions()
5254
// Cache and load images into docker daemon
53-
if err := machine.CacheAndLoadImages(args, cacheAddProfiles(), false); err != nil {
55+
if err := machine.CacheAndLoadImages(args, cacheAddProfiles(), false, options); err != nil {
5456
exit.Error(reason.InternalCacheLoad, "Failed to cache and load images", err)
5557
}
5658
// Add images to config file
@@ -103,7 +105,8 @@ var reloadCacheCmd = &cobra.Command{
103105
Short: "reload cached images.",
104106
Long: "reloads images previously added using the 'cache add' subcommand",
105107
Run: func(_ *cobra.Command, _ []string) {
106-
err := node.CacheAndLoadImagesInConfig(cacheAddProfiles())
108+
options := flags.CommandOptions()
109+
err := node.CacheAndLoadImagesInConfig(cacheAddProfiles(), options)
107110
if err != nil {
108111
exit.Error(reason.GuestCacheLoad, "Failed to reload cached images", err)
109112
}

cmd/minikube/cmd/config/addons_list.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/olekukonko/tablewriter/tw"
2929
"github.com/spf13/cobra"
3030
"k8s.io/klog/v2"
31+
"k8s.io/minikube/cmd/minikube/cmd/flags"
3132
"k8s.io/minikube/pkg/minikube/assets"
3233
"k8s.io/minikube/pkg/minikube/config"
3334
"k8s.io/minikube/pkg/minikube/exit"
@@ -55,9 +56,10 @@ var addonsListCmd = &cobra.Command{
5556
exit.Message(reason.Usage, "usage: minikube addons list")
5657
}
5758

59+
options := flags.CommandOptions()
5860
var cc *config.ClusterConfig
5961
if config.ProfileExists(ClusterFlagValue()) {
60-
_, cc = mustload.Partial(ClusterFlagValue())
62+
_, cc = mustload.Partial(ClusterFlagValue(), options)
6163
}
6264
switch strings.ToLower(addonListOutput) {
6365
case "list":

cmd/minikube/cmd/config/configure.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727

2828
"github.com/spf13/cobra"
2929
"k8s.io/klog/v2"
30+
"k8s.io/minikube/cmd/minikube/cmd/flags"
3031
"k8s.io/minikube/pkg/addons"
3132
"k8s.io/minikube/pkg/minikube/assets"
3233
"k8s.io/minikube/pkg/minikube/cluster"
@@ -37,6 +38,7 @@ import (
3738
"k8s.io/minikube/pkg/minikube/mustload"
3839
"k8s.io/minikube/pkg/minikube/out"
3940
"k8s.io/minikube/pkg/minikube/reason"
41+
"k8s.io/minikube/pkg/minikube/run"
4042
"k8s.io/minikube/pkg/minikube/style"
4143
"k8s.io/minikube/pkg/minikube/sysinit"
4244
)
@@ -59,6 +61,7 @@ var addonsConfigureCmd = &cobra.Command{
5961
exit.Message(reason.Usage, "usage: minikube addons configure ADDON_NAME")
6062
}
6163

64+
options := flags.CommandOptions()
6265
profile := ClusterFlagValue()
6366
addon := args[0]
6467
addonConfig := loadAddonConfigFile(addon, addonConfigFile)
@@ -69,16 +72,16 @@ var addonsConfigureCmd = &cobra.Command{
6972
processRegistryCredsConfig(profile, addonConfig)
7073

7174
case "metallb":
72-
processMetalLBConfig(profile, addonConfig)
75+
processMetalLBConfig(profile, addonConfig, options)
7376

7477
case "ingress":
75-
processIngressConfig(profile, addonConfig)
78+
processIngressConfig(profile, addonConfig, options)
7679

7780
case "registry-aliases":
78-
processRegistryAliasesConfig(profile, addonConfig)
81+
processRegistryAliasesConfig(profile, addonConfig, options)
7982

8083
case "auto-pause":
81-
processAutoPauseConfig(profile, addonConfig)
84+
processAutoPauseConfig(profile, addonConfig, options)
8285

8386
default:
8487
out.FailureT("{{.name}} has no available configuration options", out.V{"name": addon})
@@ -162,8 +165,8 @@ func loadAddonConfigFile(addon, configFilePath string) (ac *addonConfig) {
162165
}
163166

164167
// Processes metallb addon config from configFile if it exists otherwise resorts to default behavior
165-
func processMetalLBConfig(profile string, _ *addonConfig) {
166-
_, cfg := mustload.Partial(profile)
168+
func processMetalLBConfig(profile string, _ *addonConfig, options *run.CommandOptions) {
169+
_, cfg := mustload.Partial(profile, options)
167170

168171
validator := func(s string) bool {
169172
return net.ParseIP(s) != nil
@@ -178,14 +181,14 @@ func processMetalLBConfig(profile string, _ *addonConfig) {
178181
}
179182

180183
// Re-enable metallb addon in order to generate template manifest files with Load Balancer Start/End IP
181-
if err := addons.EnableOrDisableAddon(cfg, "metallb", "true"); err != nil {
184+
if err := addons.EnableOrDisableAddon(cfg, "metallb", "true", options); err != nil {
182185
out.ErrT(style.Fatal, "Failed to configure metallb IP {{.profile}}", out.V{"profile": profile})
183186
}
184187
}
185188

186189
// Processes ingress addon config from configFile if it exists otherwise resorts to default behavior
187-
func processIngressConfig(profile string, _ *addonConfig) {
188-
_, cfg := mustload.Partial(profile)
190+
func processIngressConfig(profile string, _ *addonConfig, options *run.CommandOptions) {
191+
_, cfg := mustload.Partial(profile, options)
189192

190193
validator := func(s string) bool {
191194
format := regexp.MustCompile("^.+/.+$")
@@ -208,8 +211,8 @@ func processIngressConfig(profile string, _ *addonConfig) {
208211
}
209212

210213
// Processes auto-pause addon config from configFile if it exists otherwise resorts to default behavior
211-
func processAutoPauseConfig(profile string, _ *addonConfig) {
212-
lapi, cfg := mustload.Partial(profile)
214+
func processAutoPauseConfig(profile string, _ *addonConfig, options *run.CommandOptions) {
215+
lapi, cfg := mustload.Partial(profile, options)
213216
intervalInput := AskForStaticValue("-- Enter interval time of auto-pause-interval (ex. 1m0s): ")
214217
intervalTime, err := time.ParseDuration(intervalInput)
215218
if err != nil {
@@ -234,11 +237,11 @@ func processAutoPauseConfig(profile string, _ *addonConfig) {
234237
out.ErrT(style.Fatal, "failed to load profile: {{.error}}", out.V{"error": err})
235238
}
236239
if profileStatus(p, lapi).StatusCode/100 == 2 { // 2xx code
237-
co := mustload.Running(profile)
240+
co := mustload.Running(profile, options)
238241
// first unpause all nodes cluster immediately
239242
unpauseWholeCluster(co)
240243
// Re-enable auto-pause addon in order to update interval time
241-
if err := addons.EnableOrDisableAddon(cfg, "auto-pause", "true"); err != nil {
244+
if err := addons.EnableOrDisableAddon(cfg, "auto-pause", "true", options); err != nil {
242245
out.ErrT(style.Fatal, "Failed to configure auto-pause {{.profile}}", out.V{"profile": profile})
243246
}
244247
// restart auto-pause service
@@ -250,8 +253,8 @@ func processAutoPauseConfig(profile string, _ *addonConfig) {
250253
}
251254

252255
// Processes registry-aliases addon config from configFile if it exists otherwise resorts to default behavior
253-
func processRegistryAliasesConfig(profile string, _ *addonConfig) {
254-
_, cfg := mustload.Partial(profile)
256+
func processRegistryAliasesConfig(profile string, _ *addonConfig, options *run.CommandOptions) {
257+
_, cfg := mustload.Partial(profile, options)
255258
validator := func(s string) bool {
256259
format := regexp.MustCompile(`^([a-zA-Z0-9-_]+\.[a-zA-Z0-9-_]+)+(\ [a-zA-Z0-9-_]+\.[a-zA-Z0-9-_]+)*$`)
257260
return format.MatchString(s)
@@ -266,7 +269,7 @@ func processRegistryAliasesConfig(profile string, _ *addonConfig) {
266269
addon := assets.Addons["registry-aliases"]
267270
if addon.IsEnabled(cfg) {
268271
// Re-enable registry-aliases addon in order to generate template manifest files with custom hosts
269-
if err := addons.EnableOrDisableAddon(cfg, "registry-aliases", "true"); err != nil {
272+
if err := addons.EnableOrDisableAddon(cfg, "registry-aliases", "true", options); err != nil {
270273
out.ErrT(style.Fatal, "Failed to configure registry-aliases {{.profile}}", out.V{"profile": profile})
271274
}
272275
}

cmd/minikube/cmd/config/disable.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package config
1818

1919
import (
2020
"github.com/spf13/cobra"
21+
"k8s.io/minikube/cmd/minikube/cmd/flags"
2122
"k8s.io/minikube/pkg/addons"
2223
"k8s.io/minikube/pkg/minikube/assets"
2324
"k8s.io/minikube/pkg/minikube/exit"
@@ -35,8 +36,10 @@ var addonsDisableCmd = &cobra.Command{
3536
if len(args) != 1 {
3637
exit.Message(reason.Usage, "usage: minikube addons disable ADDON_NAME")
3738
}
38-
_, cc := mustload.Partial(ClusterFlagValue())
39-
err := addons.VerifyNotPaused(ClusterFlagValue(), false)
39+
40+
options := flags.CommandOptions()
41+
_, cc := mustload.Partial(ClusterFlagValue(), options)
42+
err := addons.VerifyNotPaused(ClusterFlagValue(), false, options)
4043
if err != nil {
4144
exit.Error(reason.InternalAddonDisablePaused, "disable failed", err)
4245
}
@@ -49,7 +52,7 @@ var addonsDisableCmd = &cobra.Command{
4952
exit.Message(reason.AddonUnsupported, `"'{{.minikube_addon}}' is not a valid minikube addon`, out.V{"minikube_addon": addon})
5053
}
5154
if validAddon.IsEnabled(cc) {
52-
err = addons.SetAndSave(ClusterFlagValue(), addon, "false")
55+
err = addons.SetAndSave(ClusterFlagValue(), addon, "false", options)
5356
if err != nil {
5457
exit.Error(reason.InternalAddonDisable, "disable failed", err)
5558
}

cmd/minikube/cmd/config/enable.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"github.com/spf13/cobra"
2323
"github.com/spf13/viper"
24+
"k8s.io/minikube/cmd/minikube/cmd/flags"
2425
"k8s.io/minikube/pkg/addons"
2526
"k8s.io/minikube/pkg/minikube/assets"
2627
"k8s.io/minikube/pkg/minikube/config"
@@ -41,12 +42,14 @@ var addonsEnableCmd = &cobra.Command{
4142
if len(args) != 1 {
4243
exit.Message(reason.Usage, "usage: minikube addons enable ADDON_NAME")
4344
}
44-
_, cc := mustload.Partial(ClusterFlagValue())
45+
46+
options := flags.CommandOptions()
47+
_, cc := mustload.Partial(ClusterFlagValue(), options)
4548
if cc.KubernetesConfig.KubernetesVersion == constants.NoKubernetesVersion {
4649
exit.Message(reason.Usage, "You cannot enable addons on a cluster without Kubernetes, to enable Kubernetes on your cluster, run: minikube start --kubernetes-version=stable")
4750
}
4851

49-
err := addons.VerifyNotPaused(ClusterFlagValue(), true)
52+
err := addons.VerifyNotPaused(ClusterFlagValue(), true, options)
5053
if err != nil {
5154
exit.Error(reason.InternalAddonEnablePaused, "enabled failed", err)
5255
}
@@ -83,7 +86,7 @@ You can view the list of minikube maintainers at: https://github.com/kubernetes/
8386
if registries != "" {
8487
viper.Set(config.AddonRegistries, registries)
8588
}
86-
err = addons.SetAndSave(ClusterFlagValue(), addon, "true")
89+
err = addons.SetAndSave(ClusterFlagValue(), addon, "true", options)
8790
if err != nil && !errors.Is(err, addons.ErrSkipThisAddon) {
8891
exit.Error(reason.InternalAddonEnable, "enable failed", err)
8992
}

cmd/minikube/cmd/config/open.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"text/template"
2222

2323
"github.com/spf13/cobra"
24+
"k8s.io/minikube/cmd/minikube/cmd/flags"
2425
"k8s.io/minikube/pkg/minikube/assets"
2526
"k8s.io/minikube/pkg/minikube/browser"
2627
"k8s.io/minikube/pkg/minikube/exit"
@@ -57,10 +58,12 @@ var addonsOpenCmd = &cobra.Command{
5758
if len(args) != 1 {
5859
exit.Message(reason.Usage, "usage: minikube addons open ADDON_NAME")
5960
}
61+
62+
options := flags.CommandOptions()
6063
addonName := args[0]
6164

6265
cname := ClusterFlagValue()
63-
co := mustload.Healthy(cname)
66+
co := mustload.Healthy(cname, options)
6467

6568
addon, ok := assets.Addons[addonName] // validate addon input
6669
if !ok {

cmd/minikube/cmd/config/profile_list.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"strconv"
2424
"strings"
2525

26+
"k8s.io/minikube/cmd/minikube/cmd/flags"
2627
"k8s.io/minikube/pkg/minikube/cluster"
2728
"k8s.io/minikube/pkg/minikube/config"
2829
"k8s.io/minikube/pkg/minikube/constants"
@@ -31,6 +32,7 @@ import (
3132
"k8s.io/minikube/pkg/minikube/notify"
3233
"k8s.io/minikube/pkg/minikube/out"
3334
"k8s.io/minikube/pkg/minikube/reason"
35+
"k8s.io/minikube/pkg/minikube/run"
3436
"k8s.io/minikube/pkg/minikube/style"
3537

3638
"github.com/docker/machine/libmachine"
@@ -52,15 +54,16 @@ var profileListCmd = &cobra.Command{
5254
Short: "Lists all minikube profiles.",
5355
Long: "Lists all valid minikube profiles and detects all possible invalid profiles.",
5456
Run: func(_ *cobra.Command, _ []string) {
57+
options := flags.CommandOptions()
5558
output := strings.ToLower(profileOutput)
5659
out.SetJSON(output == "json")
5760
go notify.MaybePrintUpdateTextFromGithub()
5861

5962
switch output {
6063
case "json":
61-
printProfilesJSON()
64+
printProfilesJSON(options)
6265
case "table":
63-
printProfilesTable()
66+
printProfilesTable(options)
6467
default:
6568
exit.Message(reason.Usage, fmt.Sprintf("invalid output format: %s. Valid values: 'table', 'json'", profileOutput))
6669
}
@@ -77,7 +80,7 @@ func listProfiles() (validProfiles, invalidProfiles []*config.Profile, err error
7780
return validProfiles, invalidProfiles, err
7881
}
7982

80-
func printProfilesTable() {
83+
func printProfilesTable(options *run.CommandOptions) {
8184
validProfiles, invalidProfiles, err := listProfiles()
8285

8386
if err != nil {
@@ -88,20 +91,20 @@ func printProfilesTable() {
8891
exit.Message(reason.UsageNoProfileRunning, "No minikube profile was found.")
8992
}
9093

91-
updateProfilesStatus(validProfiles)
94+
updateProfilesStatus(validProfiles, options)
9295
renderProfilesTable(profilesToTableData(validProfiles))
9396
warnInvalidProfiles(invalidProfiles)
9497
}
9598

96-
func updateProfilesStatus(profiles []*config.Profile) {
99+
func updateProfilesStatus(profiles []*config.Profile, options *run.CommandOptions) {
97100
if isLight {
98101
for _, p := range profiles {
99102
p.Status = "Skipped"
100103
}
101104
return
102105
}
103106

104-
api, err := machine.NewAPIClient()
107+
api, err := machine.NewAPIClient(options)
105108
if err != nil {
106109
klog.Errorf("failed to get machine api client %v", err)
107110
}
@@ -205,9 +208,9 @@ func warnInvalidProfiles(invalidProfiles []*config.Profile) {
205208
}
206209
}
207210

208-
func printProfilesJSON() {
211+
func printProfilesJSON(options *run.CommandOptions) {
209212
validProfiles, invalidProfiles, err := listProfiles()
210-
updateProfilesStatus(validProfiles)
213+
updateProfilesStatus(validProfiles, options)
211214

212215
var body = map[string]interface{}{}
213216
if err == nil || config.IsNotExist(err) {

cmd/minikube/cmd/config/set.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func Set(name string, value string) error {
5656
return errors.Wrapf(err, "find settings for %q value of %q", name, value)
5757
}
5858
// Validate the new value
59-
err = run(name, value, s.validations)
59+
err = invoke(name, value, s.validations)
6060
if err != nil {
6161
return errors.Wrapf(err, "run validations for %q with value of %q", name, value)
6262
}
@@ -72,7 +72,7 @@ func Set(name string, value string) error {
7272
}
7373

7474
// Run any callbacks for this property
75-
err = run(name, value, s.callbacks)
75+
err = invoke(name, value, s.callbacks)
7676
if err != nil {
7777
return errors.Wrapf(err, "run callbacks for %q with value of %q", name, value)
7878
}

cmd/minikube/cmd/config/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import (
2525
"k8s.io/minikube/pkg/minikube/out"
2626
)
2727

28-
// Runs all the validation or callback functions and collects errors
29-
func run(name string, value string, fns []setFn) error {
28+
// Invoke all the validation or callback functions and collects errors
29+
func invoke(name string, value string, fns []setFn) error {
3030
var errors []error
3131
for _, fn := range fns {
3232
err := fn(name, value)

cmd/minikube/cmd/cp.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
pt "path"
2828
"strings"
2929

30+
"k8s.io/minikube/cmd/minikube/cmd/flags"
3031
"k8s.io/minikube/pkg/minikube/assets"
3132
"k8s.io/minikube/pkg/minikube/command"
3233
"k8s.io/minikube/pkg/minikube/exit"
@@ -54,17 +55,18 @@ Example Command : "minikube cp a.txt /home/docker/b.txt" +
5455
"minikube cp minikube-m01:a.txt minikube-m02:/home/docker/b.txt"`,
5556
Run: func(_ *cobra.Command, args []string) {
5657
if len(args) != 2 {
57-
exit.Message(reason.Usage, `Please specify the path to copy:
58+
exit.Message(reason.Usage, `Please specify the path to copy:
5859
minikube cp <source file path> <target file absolute path> (example: "minikube cp a/b.txt /copied.txt")`)
5960
}
6061

62+
options := flags.CommandOptions()
6163
srcPath := args[0]
6264
dstPath := setDstFileNameFromSrc(args[1], srcPath)
6365
src := newRemotePath(srcPath)
6466
dst := newRemotePath(dstPath)
6567
validateArgs(src, dst)
6668

67-
co := mustload.Running(ClusterFlagValue())
69+
co := mustload.Running(ClusterFlagValue(), options)
6870
var runner command.Runner
6971

7072
if dst.node != "" {

0 commit comments

Comments
 (0)