Skip to content

Commit 07c809f

Browse files
committed
start: Validate vfkit --network option
The vfkit driver supports now `nat` and `vmnet-shared` network options. The `nat` option provides the best performance and is always available, so it is the default network option. The `vmnet-shared` option provides access between machines with lower performance compared to `nat`. If `vment-shared` option is selected, we verify that vmnet-helper is available. The check ensure that vmnet-helper is installed and sudoers configuration allows the current user to run vment-helper without a password. If validating vment-helper failed, we return a new NotFoundVmnetHelper reason pointing to vment-helper installation docs or recommending to use `nat`. This is based on how we treat missing socket_vmnet for QEMU driver.
1 parent 5be050a commit 07c809f

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

cmd/minikube/cmd/start_flags.go

+33-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"k8s.io/klog/v2"
3131
"k8s.io/minikube/pkg/drivers/kic"
3232
"k8s.io/minikube/pkg/drivers/kic/oci"
33+
"k8s.io/minikube/pkg/drivers/vmnet"
3334
"k8s.io/minikube/pkg/minikube/bootstrapper/bsutil"
3435
"k8s.io/minikube/pkg/minikube/bootstrapper/bsutil/kverify"
3536
"k8s.io/minikube/pkg/minikube/cni"
@@ -197,7 +198,7 @@ func initMinikubeFlags() {
197198
startCmd.Flags().Bool(noKubernetes, false, "If set, minikube VM/container will start without starting or configuring Kubernetes. (only works on new clusters)")
198199
startCmd.Flags().Bool(deleteOnFailure, false, "If set, delete the current cluster if start fails and try again. Defaults to false.")
199200
startCmd.Flags().Bool(forceSystemd, false, "If set, force the container runtime to use systemd as cgroup manager. Defaults to false.")
200-
startCmd.Flags().String(network, "", "network to run minikube with. Now it is used by docker/podman and KVM drivers. If left empty, minikube will create a new network.")
201+
startCmd.Flags().String(network, "", "network to run minikube with. Used by docker/podman, qemu, kvm, and vfkit drivers. If left empty, minikube will create a new network.")
201202
startCmd.Flags().StringVarP(&outputFormat, "output", "o", "text", "Format to print stdout in. Options include: [text,json]")
202203
startCmd.Flags().String(trace, "", "Send trace events. Options include: [gcp]")
203204
startCmd.Flags().Int(extraDisks, 0, "Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit, kvm2, and qemu2 drivers)")
@@ -469,9 +470,15 @@ func getCNIConfig(cmd *cobra.Command) string {
469470

470471
func getNetwork(driverName string) string {
471472
n := viper.GetString(network)
472-
if !driver.IsQEMU(driverName) {
473-
return n
473+
if driver.IsQEMU(driverName) {
474+
return validateQemuNetwork(n)
475+
} else if driver.IsVFKit(driverName) {
476+
return validateVfkitNetwork(n)
474477
}
478+
return n
479+
}
480+
481+
func validateQemuNetwork(n string) string {
475482
switch n {
476483
case "socket_vmnet":
477484
if runtime.GOOS != "darwin" {
@@ -503,6 +510,27 @@ func getNetwork(driverName string) string {
503510
return n
504511
}
505512

513+
func validateVfkitNetwork(n string) string {
514+
if runtime.GOOS != "darwin" {
515+
exit.Message(reason.Usage, "The vfkit driver is only supported on macOS")
516+
}
517+
switch n {
518+
case "nat":
519+
// always available
520+
case "vmnet-shared":
521+
// "vment-shared" provides access between machines, with lower performance compared to "nat".
522+
if !vmnet.HelperAvailable() {
523+
exit.Message(reason.NotFoundVmnetHelper, "\n\n")
524+
}
525+
case "":
526+
// Default to nat since it is always available and provides the best performance.
527+
n = "nat"
528+
default:
529+
exit.Message(reason.Usage, "--network with vfkit must be 'nat' or 'vmnet-shared'")
530+
}
531+
return n
532+
}
533+
506534
// generateNewConfigFromFlags generate a config.ClusterConfig based on flags
507535
func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, rtime string, drvName string) config.ClusterConfig {
508536
var cc config.ClusterConfig
@@ -513,8 +541,8 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, rtime str
513541
out.WarningT("With --network-plugin=cni, you will need to provide your own CNI. See --cni flag as a user-friendly alternative")
514542
}
515543

516-
if !(driver.IsKIC(drvName) || driver.IsKVM(drvName) || driver.IsQEMU(drvName)) && viper.GetString(network) != "" {
517-
out.WarningT("--network flag is only valid with the docker/podman, KVM and Qemu drivers, it will be ignored")
544+
if viper.GetString(network) != "" && !driver.SupportsNetworkFlag(drvName) {
545+
out.WarningT("--network flag is only valid with the docker/podman, qemu, kvm, and vfkit drivers, it will be ignored")
518546
}
519547

520548
validateHANodeCount(cmd)

pkg/minikube/driver/driver.go

+10
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ func IsQEMU(name string) bool {
173173
return name == QEMU2 || name == QEMU
174174
}
175175

176+
// IsVFKit checks if the driver is vfkit
177+
func IsVFKit(name string) bool {
178+
return name == VFKit
179+
}
180+
176181
// IsVM checks if the driver is a VM
177182
func IsVM(name string) bool {
178183
if IsKIC(name) || BareMetal(name) {
@@ -206,6 +211,11 @@ func IsHyperV(name string) bool {
206211
return name == HyperV
207212
}
208213

214+
// SupportsNetworkFlag reutuns if driver supports the --network flag
215+
func SupportsNetworkFlag(name string) bool {
216+
return IsKIC(name) || IsKVM(name) || IsQEMU(name) || IsVFKit(name)
217+
}
218+
209219
// AllowsPreload returns if preload is allowed for the driver
210220
func AllowsPreload(driverName string) bool {
211221
return !BareMetal(driverName) && !IsSSH(driverName)

pkg/minikube/reason/reason.go

+14
Original file line numberDiff line numberDiff line change
@@ -549,4 +549,18 @@ var (
549549
minikube start{{.profile}} --driver qemu --network user`),
550550
Style: style.SeeNoEvil,
551551
}
552+
NotFoundVmnetHelper = Kind{
553+
ID: "NOT_FOUND_VMNET_HELPER",
554+
ExitCode: ExProgramNotFound,
555+
Advice: translate.T(`vmnet-helper was not found on the system, resolve by:
556+
557+
Option 1) Installing vment-helper:
558+
559+
https://github.com/nirs/vmnet-helper#installation
560+
561+
Option 2) Using the nat network:
562+
563+
minikube start{{.profile}} --driver vfkit --network nat`),
564+
Style: style.SeeNoEvil,
565+
}
552566
)

0 commit comments

Comments
 (0)