Skip to content

Commit 3568d65

Browse files
committed
auto select network on QEMU
1 parent 1353c3c commit 3568d65

File tree

3 files changed

+55
-10
lines changed

3 files changed

+55
-10
lines changed

cmd/minikube/cmd/start_flags.go

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -463,14 +463,31 @@ func getNetwork(driverName string) string {
463463
if !driver.IsQEMU(driverName) {
464464
return n
465465
}
466-
if n == "" {
467-
if runtime.GOOS == "darwin" {
468-
out.WarningT("The default network for QEMU will change from 'user' to 'socket_vmnet' in a future release")
466+
switch n {
467+
case "socket_vmnet":
468+
if runtime.GOOS != "darwin" {
469+
exit.Message(reason.Usage, "The socket_vmnet network is only supported on macOS")
470+
}
471+
if !detect.SocketVMNetInstalled() {
472+
exit.Message(reason.NotFoundSocketVMNet, "\n\n")
473+
}
474+
case "":
475+
if detect.SocketVMNetInstalled() {
476+
n = "socket_vmnet"
477+
} else {
478+
n = "user"
469479
}
470-
n = "user"
480+
out.Styled(style.Internet, "Automatically selected the {{.network}} network", out.V{"network": n})
481+
case "user":
482+
default:
483+
exit.Message(reason.Usage, "--network with QEMU must be 'user' or 'socket_vmnet'")
471484
}
472-
if n == "user" && runtime.GOOS == "darwin" {
473-
out.WarningT("You are using the QEMU driver without a dedicated network, which doesn't support `minikube service` & `minikube tunnel` commands.\nTo try the experimental dedicated network see: https://minikube.sigs.k8s.io/docs/drivers/qemu/#networking")
485+
if n == "user" {
486+
msg := "You are using the QEMU driver without a dedicated network, which doesn't support `minikube service` & `minikube tunnel` commands."
487+
if runtime.GOOS == "darwin" {
488+
msg += "\nTo try the experimental dedicated network see: https://minikube.sigs.k8s.io/docs/drivers/qemu/#networking"
489+
}
490+
out.WarningT(msg)
474491
}
475492
return n
476493
}
@@ -489,10 +506,6 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, rtime str
489506
out.WarningT("--network flag is only valid with the docker/podman, KVM and Qemu drivers, it will be ignored")
490507
}
491508

492-
if driver.IsQEMU(drvName) && viper.GetString(network) == "socket_vmnet" {
493-
out.WarningT("Using qemu with 'socket_vmnet' network is experimental")
494-
}
495-
496509
checkNumaCount(k8sVersion)
497510

498511
checkExtraDiskOptions(cmd, drvName)

pkg/minikube/detect/detect.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package detect
1818

1919
import (
20+
"errors"
2021
"net/http"
2122
"os"
2223
"os/exec"
@@ -25,7 +26,9 @@ import (
2526
"strings"
2627

2728
"github.com/klauspost/cpuid"
29+
"github.com/spf13/viper"
2830
"golang.org/x/sys/cpu"
31+
"k8s.io/klog/v2"
2932
"k8s.io/minikube/pkg/minikube/localpath"
3033
)
3134

@@ -129,3 +132,18 @@ func KICCacheDir() string {
129132
func ISOCacheDir() string {
130133
return filepath.Join(localpath.MakeMiniPath("cache", "iso"), runtime.GOARCH)
131134
}
135+
136+
// SocketVMNetInstalled returns if socket_vmnet is installed
137+
func SocketVMNetInstalled() bool {
138+
if runtime.GOOS != "darwin" {
139+
return false
140+
}
141+
_, err := os.Stat(viper.GetString("socket-vmnet-path"))
142+
if err == nil {
143+
return true
144+
}
145+
if !errors.Is(err, os.ErrNotExist) {
146+
klog.Warningf("failed to check for socket_vmnet: %v", err)
147+
}
148+
return false
149+
}

pkg/minikube/reason/reason.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,4 +483,18 @@ var (
483483
https://docs.docker.com/engine/install/`),
484484
Style: style.Docker,
485485
}
486+
NotFoundSocketVMNet = Kind{
487+
ID: "NOT_FOUND_SOCKET_VMNET",
488+
ExitCode: ExProgramNotFound,
489+
Advice: translate.T(`socket_vmnet was not found on the system, resolve by:
490+
491+
Option 1) Installing socket_vmnet:
492+
493+
https://minikube.sigs.k8s.io/docs/drivers/qemu/#networking
494+
495+
Option 2) Using the user network:
496+
497+
minikube start{{.profile}} --driver qemu --network user`),
498+
Style: style.SeeNoEvil,
499+
}
486500
)

0 commit comments

Comments
 (0)