Skip to content

Commit

Permalink
Merge pull request #14890 from klaases/qemu_socket2
Browse files Browse the repository at this point in the history
enable `socket_vmnet` network driver for qemu Mac M1 ARM64
  • Loading branch information
spowelljr authored Sep 21, 2022
2 parents 5bf5d66 + d03b4a2 commit f7c69f4
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
18 changes: 16 additions & 2 deletions cmd/minikube/cmd/start_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ const (
disableOptimizations = "disable-optimizations"
disableMetrics = "disable-metrics"
qemuFirmwarePath = "qemu-firmware-path"
socketVMnetClientPath = "socket-vmnet-client-path"
socketVMnetPath = "socket-vmnet-path"
)

var (
Expand Down Expand Up @@ -274,6 +276,10 @@ func initNetworkingFlags() {
startCmd.Flags().String(sshSSHUser, defaultSSHUser, "SSH user (ssh driver only)")
startCmd.Flags().String(sshSSHKey, "", "SSH key (ssh driver only)")
startCmd.Flags().Int(sshSSHPort, defaultSSHPort, "SSH port (ssh driver only)")

// socket vmnet
startCmd.Flags().String(socketVMnetClientPath, "/opt/socket_vmnet/bin/socket_vmnet_client", "Path to the socket vmnet client binary")
startCmd.Flags().String(socketVMnetPath, "/var/run/socket_vmnet", "Path to socket vmnet binary")
}

// ClusterFlagValue returns the current cluster name based on flags
Expand Down Expand Up @@ -461,8 +467,12 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, rtime str
out.WarningT("With --network-plugin=cni, you will need to provide your own CNI. See --cni flag as a user-friendly alternative")
}

if !(driver.IsKIC(drvName) || driver.IsKVM(drvName)) && viper.GetString(network) != "" {
out.WarningT("--network flag is only valid with the docker/podman and KVM drivers, it will be ignored")
if !(driver.IsKIC(drvName) || driver.IsKVM(drvName) || driver.IsQEMU(drvName)) && viper.GetString(network) != "" {
out.WarningT("--network flag is only valid with the docker/podman, KVM and Qemu drivers, it will be ignored")
}

if driver.IsQEMU(drvName) && viper.GetString(network) == "socket" {
out.WarningT("Using qemu with --network=socket for 'socket_vmnet' is experimental")
}

checkNumaCount(k8sVersion)
Expand Down Expand Up @@ -528,6 +538,8 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, rtime str
DisableOptimizations: viper.GetBool(disableOptimizations),
DisableMetrics: viper.GetBool(disableMetrics),
CustomQemuFirmwarePath: viper.GetString(qemuFirmwarePath),
SocketVMnetClientPath: viper.GetString(socketVMnetClientPath),
SocketVMnetPath: viper.GetString(socketVMnetPath),
KubernetesConfig: config.KubernetesConfig{
KubernetesVersion: k8sVersion,
ClusterName: ClusterFlagValue(),
Expand Down Expand Up @@ -747,6 +759,8 @@ func updateExistingConfigFromFlags(cmd *cobra.Command, existing *config.ClusterC
updateStringFromFlag(cmd, &cc.BinaryMirror, binaryMirror)
updateBoolFromFlag(cmd, &cc.DisableOptimizations, disableOptimizations)
updateStringFromFlag(cmd, &cc.CustomQemuFirmwarePath, qemuFirmwarePath)
updateStringFromFlag(cmd, &cc.SocketVMnetClientPath, socketVMnetClientPath)
updateStringFromFlag(cmd, &cc.SocketVMnetPath, socketVMnetPath)

if cmd.Flags().Changed(kubernetesVersion) {
cc.KubernetesConfig.KubernetesVersion = getKubernetesVersion(existing)
Expand Down
17 changes: 16 additions & 1 deletion pkg/drivers/qemu/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ import (
"github.com/docker/machine/libmachine/ssh"
"github.com/docker/machine/libmachine/state"
"github.com/pkg/errors"
"github.com/spf13/viper"

pkgdrivers "k8s.io/minikube/pkg/drivers"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/reason"
)

const (
Expand Down Expand Up @@ -408,6 +411,9 @@ func (d *Driver) Start() error {
startCmd = append(startCmd,
"-nic", fmt.Sprintf("user,model=virtio,hostfwd=tcp::%d-:22,hostfwd=tcp::%d-:2376,hostname=%s", d.SSHPort, d.EnginePort, d.GetMachineName()),
)
case "socket":
// TODO: implement final socket_vmnet network flags.
exit.Message(reason.Unimplemented, "socket_vmnet network flags are not yet implemented with the qemu2 driver.\n See https://github.com/kubernetes/minikube/pull/14890 for details.")
case "tap":
startCmd = append(startCmd,
"-nic", fmt.Sprintf("tap,model=virtio,ifname=%s,script=no,downscript=no", d.NetworkInterface),
Expand Down Expand Up @@ -445,11 +451,20 @@ func (d *Driver) Start() error {
d.diskPath())
}

if stdout, stderr, err := cmdOutErr(d.Program, startCmd...); err != nil {
// If socket network, start with socket_vmnet.
startProgram := d.Program
if d.Network == "socket" {
startProgram = viper.GetString("socket-vmnet-client-path")
socketVMnetPath := viper.GetString("socket-vmnet-path")
startCmd = append([]string{socketVMnetPath, d.Program}, startCmd...)
}

if stdout, stderr, err := cmdOutErr(startProgram, startCmd...); err != nil {
fmt.Printf("OUTPUT: %s\n", stdout)
fmt.Printf("ERROR: %s\n", stderr)
return err
}

log.Infof("Waiting for VM to start (ssh -p %d docker@localhost)...", d.SSHPort)

return WaitForTCPWithDelay(fmt.Sprintf("localhost:%d", d.SSHPort), time.Second)
Expand Down
2 changes: 2 additions & 0 deletions pkg/minikube/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ type ClusterConfig struct {
DisableOptimizations bool
DisableMetrics bool
CustomQemuFirmwarePath string
SocketVMnetClientPath string
SocketVMnetPath string
}

// KubernetesConfig contains the parameters used to configure the VM Kubernetes.
Expand Down
8 changes: 7 additions & 1 deletion pkg/minikube/registry/drvs/qemu2/qemu2.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) {
if err != nil {
return nil, err
}
qemuNetwork := cc.Network
if qemuNetwork == "" {
qemuNetwork = "user"
// TODO: on next minor release, default to "socket".
}

return qemu.Driver{
BaseDriver: &drivers.BaseDriver{
MachineName: name,
Expand All @@ -177,7 +183,7 @@ func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) {
CPUType: qemuCPU,
Firmware: qemuFirmware,
VirtioDrives: false,
Network: "user",
Network: qemuNetwork,
CacheMode: "default",
IOMode: "threads",
}, nil
Expand Down
2 changes: 2 additions & 0 deletions site/content/en/docs/commands/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ minikube start [flags]
--qemu-firmware-path string Path to the qemu firmware file. Defaults: For Linux, the default firmware location. For macOS, the brew installation location. For Windows, C:\Program Files\qemu\share
--registry-mirror strings Registry mirrors to pass to the Docker daemon
--service-cluster-ip-range string The CIDR to be used for service cluster IPs. (default "10.96.0.0/12")
--socket-vmnet-client-path string Path to the socket vmnet client binary. (default "/opt/socket_vmnet/bin/socket_vmnet_client")
--socket-vmnet-path string Path to socket vmnet binary. (default "/var/run/socket_vmnet")
--ssh-ip-address string IP address (ssh driver only)
--ssh-key string SSH key (ssh driver only)
--ssh-port int SSH port (ssh driver only) (default 22)
Expand Down

0 comments on commit f7c69f4

Please sign in to comment.