From 7a7892355cfa060afe2cc9d2507b1d1308b66169 Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Thu, 2 Oct 2025 19:03:16 +0300 Subject: [PATCH] vmnet: Move download-only check to start command Skipping validation in vment.ValidateHelper() was the simplest way to avoid validation when starting with --download-only flag, but it requires accessing viper outside of the commands using strings. This make the code fragile and makes testing harder since we depend on global state. Fixed by moving vment-helper validation to validateVmnetNetwork() helper in the minikube/cmd package. We skip the call to vment.ValidateHelper() in download-only mode. The helper is called for vfkit and krunkit when validating the --network flag. For krunkit the validation was part of Driver.Status check, which is good place to validate, but it does not have access to start command flags. Validating in the start command is little bit ugly since krunkit does not use the --network option, and it moves driver logic to the start command, but at least it is consistent with vfkit and qemu, and it avoids the trouble of passing start flags deep inside minikube. --- cmd/minikube/cmd/start_flags.go | 18 ++++++++++++++---- pkg/minikube/registry/drvs/krunkit/krunkit.go | 4 ---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/cmd/minikube/cmd/start_flags.go b/cmd/minikube/cmd/start_flags.go index 92546e3f9c90..494a6f2f6819 100644 --- a/cmd/minikube/cmd/start_flags.go +++ b/cmd/minikube/cmd/start_flags.go @@ -490,6 +490,8 @@ func getNetwork(driverName string) string { return validateQemuNetwork(n) } else if driver.IsVFKit(driverName) { return validateVfkitNetwork(n) + } else if driver.IsKrunkit(driverName) { + return validateVmnetNetwork(n) } return n } @@ -535,10 +537,7 @@ func validateVfkitNetwork(n string) string { // always available case "vmnet-shared": // "vment-shared" provides access between machines, with lower performance compared to "nat". - if err := vmnet.ValidateHelper(); err != nil { - vmnetErr := err.(*vmnet.Error) - exit.Message(vmnetErr.Kind, "failed to validate {{.network}} network: {{.reason}}", out.V{"network": n, "reason": err}) - } + n = validateVmnetNetwork(n) case "": // Default to nat since it is always available and provides the best performance. n = "nat" @@ -548,6 +547,17 @@ func validateVfkitNetwork(n string) string { return n } +func validateVmnetNetwork(n string) string { + if !viper.GetBool(downloadOnly) { + if err := vmnet.ValidateHelper(); err != nil { + vmnetErr := err.(*vmnet.Error) + exit.Message(vmnetErr.Kind, "failed to validate {{.network}} network: {{.reason}}", + out.V{"network": n, "reason": err}) + } + } + return n +} + // generateNewConfigFromFlags generate a config.ClusterConfig based on flags func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, rtime string, drvName string) config.ClusterConfig { var cc config.ClusterConfig diff --git a/pkg/minikube/registry/drvs/krunkit/krunkit.go b/pkg/minikube/registry/drvs/krunkit/krunkit.go index 2faf138dba5f..f86616848bfc 100644 --- a/pkg/minikube/registry/drvs/krunkit/krunkit.go +++ b/pkg/minikube/registry/drvs/krunkit/krunkit.go @@ -98,9 +98,5 @@ func status() registry.State { if _, err := exec.LookPath("krunkit"); err != nil { return registry.State{Error: err, Fix: "Run 'brew tap slp/krunkit && brew install krunkit'", Doc: docURL} } - if err := vmnet.ValidateHelper(); err != nil { - vmnetErr := err.(*vmnet.Error) - return registry.State{Error: vmnetErr.Err, Fix: "Install and configure vment-helper", Doc: docURL} - } return registry.State{Installed: true, Healthy: true, Running: true} }