Skip to content

Commit b91345d

Browse files
committed
vment: Remove viper interactive check
vment.ValidateHelper() accept now *run.CommandOptions and use options.NonInteractive to check if interaction is allowed. Update callers to pass options from the minikube command. Testing non-interactive mode: % sudo rm /etc/sudoers.d/vmnet-helper % sudo -k % out/minikube start -d krunkit --interactive=false 😄 minikube v1.37.0 on Darwin 26.0.1 (arm64) ✨ Using the krunkit (experimental) driver based on user configuration 🤷 Exiting due to PROVIDER_KRUNKIT_NOT_FOUND: The 'krunkit' provider was not found: exit status 1: sudo: a password is required 💡 Suggestion: Install and configure vment-helper 📘 Documentation: https://minikube.sigs.k8s.io/docs/reference/drivers/krunkit/ Testing interactive mode: % out/minikube start -d krunkit 😄 minikube v1.37.0 on Darwin 26.0.1 (arm64) 💡 Unable to run vmnet-helper without a password To configure vment-helper to run without a password, please check the documentation: https://github.com/nirs/vmnet-helper/#granting-permission-to-run-vmnet-helper Password: ✨ Using the krunkit (experimental) driver based on user configuration 👍 Starting "minikube" primary control-plane node in "minikube" cluster 🔥 Creating krunkit VM (CPUs=2, Memory=6144MB, Disk=20000MB) ... 🐳 Preparing Kubernetes v1.34.1 on Docker 28.4.0 ... 🔗 Configuring bridge CNI (Container Networking Interface) ... 🔎 Verifying Kubernetes components... ▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5 🌟 Enabled addons: default-storageclass, storage-provisioner 🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
1 parent d98d710 commit b91345d

File tree

6 files changed

+20
-16
lines changed

6 files changed

+20
-16
lines changed

cmd/minikube/cmd/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ func provisionWithDriver(cmd *cobra.Command, ds registry.DriverState, existing *
346346
}
347347

348348
rtime := getContainerRuntime(existing)
349-
cc, n, err := generateClusterConfig(cmd, existing, k8sVersion, rtime, driverName)
349+
cc, n, err := generateClusterConfig(cmd, existing, k8sVersion, rtime, driverName, options)
350350
if err != nil {
351351
return node.Starter{}, errors.Wrap(err, "Failed to generate cluster config")
352352
}

cmd/minikube/cmd/start_flags.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import (
4545
"k8s.io/minikube/pkg/minikube/out"
4646
"k8s.io/minikube/pkg/minikube/proxy"
4747
"k8s.io/minikube/pkg/minikube/reason"
48+
"k8s.io/minikube/pkg/minikube/run"
4849
"k8s.io/minikube/pkg/minikube/style"
4950
pkgutil "k8s.io/minikube/pkg/util"
5051
"k8s.io/minikube/pkg/version"
@@ -314,7 +315,7 @@ func ClusterFlagValue() string {
314315
}
315316

316317
// generateClusterConfig generate a config.ClusterConfig based on flags or existing cluster config
317-
func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k8sVersion string, rtime string, drvName string) (config.ClusterConfig, config.Node, error) {
318+
func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k8sVersion string, rtime string, drvName string, options *run.CommandOptions) (config.ClusterConfig, config.Node, error) {
318319
var cc config.ClusterConfig
319320
if existing != nil {
320321
cc = updateExistingConfigFromFlags(cmd, existing)
@@ -325,7 +326,7 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k
325326
}
326327
} else {
327328
klog.Info("no existing cluster config was found, will generate one from the flags ")
328-
cc = generateNewConfigFromFlags(cmd, k8sVersion, rtime, drvName)
329+
cc = generateNewConfigFromFlags(cmd, k8sVersion, rtime, drvName, options)
329330

330331
cnm, err := cni.New(&cc)
331332
if err != nil {
@@ -484,12 +485,12 @@ func getCNIConfig(cmd *cobra.Command) string {
484485
return chosenCNI
485486
}
486487

487-
func getNetwork(driverName string) string {
488+
func getNetwork(driverName string, options *run.CommandOptions) string {
488489
n := viper.GetString(network)
489490
if driver.IsQEMU(driverName) {
490491
return validateQemuNetwork(n)
491492
} else if driver.IsVFKit(driverName) {
492-
return validateVfkitNetwork(n)
493+
return validateVfkitNetwork(n, options)
493494
}
494495
return n
495496
}
@@ -526,7 +527,7 @@ func validateQemuNetwork(n string) string {
526527
return n
527528
}
528529

529-
func validateVfkitNetwork(n string) string {
530+
func validateVfkitNetwork(n string, options *run.CommandOptions) string {
530531
if runtime.GOOS != "darwin" {
531532
exit.Message(reason.Usage, "The vfkit driver is only supported on macOS")
532533
}
@@ -535,7 +536,7 @@ func validateVfkitNetwork(n string) string {
535536
// always available
536537
case "vmnet-shared":
537538
// "vment-shared" provides access between machines, with lower performance compared to "nat".
538-
if err := vmnet.ValidateHelper(); err != nil {
539+
if err := vmnet.ValidateHelper(options); err != nil {
539540
vmnetErr := err.(*vmnet.Error)
540541
exit.Message(vmnetErr.Kind, "failed to validate {{.network}} network: {{.reason}}", out.V{"network": n, "reason": err})
541542
}
@@ -549,7 +550,7 @@ func validateVfkitNetwork(n string) string {
549550
}
550551

551552
// generateNewConfigFromFlags generate a config.ClusterConfig based on flags
552-
func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, rtime string, drvName string) config.ClusterConfig {
553+
func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, rtime string, drvName string, options *run.CommandOptions) config.ClusterConfig {
553554
var cc config.ClusterConfig
554555

555556
// networkPlugin cni deprecation warning
@@ -574,7 +575,7 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, rtime str
574575
EmbedCerts: viper.GetBool(embedCerts),
575576
MinikubeISO: viper.GetString(isoURL),
576577
KicBaseImage: viper.GetString(kicBaseImage),
577-
Network: getNetwork(drvName),
578+
Network: getNetwork(drvName, options),
578579
Subnet: viper.GetString(subnet),
579580
Memory: getMemorySize(cmd, drvName),
580581
CPUs: getCPUCount(drvName),

cmd/minikube/cmd/start_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"k8s.io/minikube/pkg/minikube/cruntime"
3333
"k8s.io/minikube/pkg/minikube/driver"
3434
"k8s.io/minikube/pkg/minikube/proxy"
35+
"k8s.io/minikube/pkg/minikube/run"
3536
)
3637

3738
func TestGetKubernetesVersion(t *testing.T) {
@@ -169,7 +170,7 @@ func TestMirrorCountry(t *testing.T) {
169170
viper.SetDefault(imageRepository, test.imageRepository)
170171
viper.SetDefault(imageMirrorCountry, test.mirrorCountry)
171172
viper.SetDefault(kvmNUMACount, 1)
172-
config, _, err := generateClusterConfig(cmd, nil, k8sVersion, rtime, driver.Mock)
173+
config, _, err := generateClusterConfig(cmd, nil, k8sVersion, rtime, driver.Mock, &run.CommandOptions{})
173174
if err != nil {
174175
t.Fatalf("Got unexpected error %v during config generation", err)
175176
}
@@ -230,7 +231,7 @@ func TestGenerateCfgFromFlagsHTTPProxyHandling(t *testing.T) {
230231

231232
cfg.DockerEnv = []string{} // clear docker env to avoid pollution
232233
proxy.SetDockerEnv()
233-
config, _, err := generateClusterConfig(cmd, nil, k8sVersion, rtime, "none")
234+
config, _, err := generateClusterConfig(cmd, nil, k8sVersion, rtime, "none", &run.CommandOptions{})
234235
if err != nil {
235236
t.Fatalf("Got unexpected error %v during config generation", err)
236237
}

pkg/drivers/common/vmnet/vmnet.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"k8s.io/minikube/pkg/minikube/out"
3737
"k8s.io/minikube/pkg/minikube/process"
3838
"k8s.io/minikube/pkg/minikube/reason"
39+
"k8s.io/minikube/pkg/minikube/run"
3940
"k8s.io/minikube/pkg/minikube/style"
4041
)
4142

@@ -71,7 +72,7 @@ type interfaceInfo struct {
7172
// ValidateHelper checks if vmnet-helper is installed and we can run it as root.
7273
// The returned error.Kind can be used to provide a suggestion for resolving the
7374
// issue.
74-
func ValidateHelper() error {
75+
func ValidateHelper(options *run.CommandOptions) error {
7576
// Ideally minikube will not try to validate in download-only mode, but this
7677
// is called from different places in different drivers, so the easier way
7778
// to skip validation is to skip it here.
@@ -93,7 +94,7 @@ func ValidateHelper() error {
9394
stdout, err := cmd.Output()
9495
if err != nil {
9596
// Can we interact with the user?
96-
if !viper.GetBool("interactive") {
97+
if options.NonInteractive {
9798
if exitErr, ok := err.(*exec.ExitError); ok {
9899
stderr := strings.TrimSpace(string(exitErr.Stderr))
99100
err = fmt.Errorf("%w: %s", err, stderr)

pkg/drivers/common/vmnet/vmnet_stub.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ import (
2323
"runtime"
2424

2525
"k8s.io/minikube/pkg/minikube/reason"
26+
"k8s.io/minikube/pkg/minikube/run"
2627
)
2728

28-
func ValidateHelper() error {
29+
func ValidateHelper(_ *run.CommandOptions) error {
2930
return &Error{Kind: reason.Usage, Err: fmt.Errorf("vmnet-helper is not available on %q", runtime.GOOS)}
3031
}

pkg/minikube/registry/drvs/krunkit/krunkit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ func configure(cfg config.ClusterConfig, n config.Node) (interface{}, error) {
9393
}, nil
9494
}
9595

96-
func status(_ *run.CommandOptions) registry.State {
96+
func status(options *run.CommandOptions) registry.State {
9797
if runtime.GOOS != "darwin" && runtime.GOARCH != "arm64" {
9898
err := errors.New("the krunkit driver is only supported on macOS arm64 machines")
9999
return registry.State{Error: err, Fix: "Use another driver", Doc: docURL}
100100
}
101101
if _, err := exec.LookPath("krunkit"); err != nil {
102102
return registry.State{Error: err, Fix: "Run 'brew tap slp/krunkit && brew install krunkit'", Doc: docURL}
103103
}
104-
if err := vmnet.ValidateHelper(); err != nil {
104+
if err := vmnet.ValidateHelper(options); err != nil {
105105
vmnetErr := err.(*vmnet.Error)
106106
return registry.State{Error: vmnetErr.Err, Fix: "Install and configure vment-helper", Doc: docURL}
107107
}

0 commit comments

Comments
 (0)