Skip to content

Commit f2995f4

Browse files
committed
Add the qemu driver to the minikube registry
Since the machine drivers are hardcoded in minikube, drivers need to be added to the registry to be tested. Add a basic sanity check for the qemu-system binary, and set up the basic configuration such as cpus/memory.
1 parent 793eeae commit f2995f4

File tree

10 files changed

+97
-0
lines changed

10 files changed

+97
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ require (
155155
github.com/json-iterator/go v1.1.12 // indirect
156156
github.com/klauspost/compress v1.13.0 // indirect
157157
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
158+
github.com/machine-drivers/docker-machine-driver-qemu v0.1.0
158159
github.com/magiconair/properties v1.8.5 // indirect
159160
github.com/mattn/go-colorable v0.1.12 // indirect
160161
github.com/mattn/go-runewidth v0.0.13 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,8 @@ github.com/lithammer/dedent v1.1.0/go.mod h1:jrXYCQtgg0nJiN+StA2KgR7w6CiQNv9Fd/Z
786786
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
787787
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
788788
github.com/lyft/protoc-gen-star v0.5.3/go.mod h1:V0xaHgaf5oCCqmcxYcWiDfTiKsZsRc87/1qhoTACD8w=
789+
github.com/machine-drivers/docker-machine-driver-qemu v0.1.0 h1:r5bMzOqca0dZuCkn/8vCM8QNpdsLPCVZ6VP5z/IU0HM=
790+
github.com/machine-drivers/docker-machine-driver-qemu v0.1.0/go.mod h1:1gevpWYcs2Gmvt9G9T6AbeRw9tGnQdQiKt56B7n2X7g=
789791
github.com/machine-drivers/docker-machine-driver-vmware v0.1.5 h1:51GqJ84u9EBATnn8rWsHNavcuRPlCLnDmvjzZVuliwY=
790792
github.com/machine-drivers/docker-machine-driver-vmware v0.1.5/go.mod h1:dTnTzUH3uzhMo0ddV1zRjGYWcVhQWwqiHPxz5l+HPd0=
791793
github.com/machine-drivers/machine v0.7.1-0.20211105063445-78a84df85426 h1:gVDPCmqwvHQ4ox/9svvnkomYJAAiV59smbPdTK4DIm4=

pkg/minikube/driver/driver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ const (
4444
SSH = "ssh"
4545
// KVM2 driver
4646
KVM2 = "kvm2"
47+
// QEMU driver
48+
QEMU = "qemu"
4749
// VirtualBox driver
4850
VirtualBox = "virtualbox"
4951
// HyperKit driver

pkg/minikube/driver/driver_darwin.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var supportedDrivers = func() []string {
2727
if runtime.GOARCH == "arm64" {
2828
// on darwin/arm64 only docker and ssh are supported yet
2929
return []string{
30+
QEMU,
3031
Docker,
3132
Podman,
3233
SSH,
@@ -50,6 +51,7 @@ var supportedDrivers = func() []string {
5051
VMwareFusion,
5152
HyperKit,
5253
VMware,
54+
QEMU,
5355
Docker,
5456
Podman,
5557
SSH,

pkg/minikube/driver/driver_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var supportedDrivers = []string{
2525
VirtualBox,
2626
VMwareFusion,
2727
KVM2,
28+
QEMU,
2829
VMware,
2930
None,
3031
Docker,

pkg/minikube/driver/driver_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func TestMachineType(t *testing.T) {
6666
None: "bare metal machine",
6767
SSH: "bare metal machine",
6868
KVM2: "VM",
69+
QEMU: "VM",
6970
VirtualBox: "VM",
7071
HyperKit: "VM",
7172
VMware: "VM",

pkg/minikube/driver/driver_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var supportedDrivers = []string{
3232
VMwareFusion,
3333
HyperV,
3434
VMware,
35+
QEMU,
3536
Docker,
3637
Podman,
3738
SSH,

pkg/minikube/registry/drvs/init.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
_ "k8s.io/minikube/pkg/minikube/registry/drvs/none"
2626
_ "k8s.io/minikube/pkg/minikube/registry/drvs/parallels"
2727
_ "k8s.io/minikube/pkg/minikube/registry/drvs/podman"
28+
_ "k8s.io/minikube/pkg/minikube/registry/drvs/qemu"
2829
_ "k8s.io/minikube/pkg/minikube/registry/drvs/ssh"
2930
_ "k8s.io/minikube/pkg/minikube/registry/drvs/virtualbox"
3031
_ "k8s.io/minikube/pkg/minikube/registry/drvs/vmware"
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package qemu
18+
19+
import (
20+
"fmt"
21+
"os/exec"
22+
"runtime"
23+
24+
"github.com/docker/machine/libmachine/drivers"
25+
drvqemu "github.com/machine-drivers/docker-machine-driver-qemu"
26+
27+
"k8s.io/minikube/pkg/minikube/config"
28+
"k8s.io/minikube/pkg/minikube/download"
29+
"k8s.io/minikube/pkg/minikube/driver"
30+
"k8s.io/minikube/pkg/minikube/localpath"
31+
"k8s.io/minikube/pkg/minikube/registry"
32+
)
33+
34+
const (
35+
docURL = "https://minikube.sigs.k8s.io/docs/reference/drivers/qemu/"
36+
)
37+
38+
func init() {
39+
if err := registry.Register(registry.DriverDef{
40+
Name: driver.QEMU,
41+
Config: configure,
42+
Status: status,
43+
Default: true,
44+
Priority: registry.Experimental,
45+
}); err != nil {
46+
panic(fmt.Sprintf("register failed: %v", err))
47+
}
48+
}
49+
50+
func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) {
51+
name := config.MachineName(cc, n)
52+
return drvqemu.Driver{
53+
BaseDriver: &drivers.BaseDriver{
54+
MachineName: name,
55+
StorePath: localpath.MiniPath(),
56+
SSHUser: "docker",
57+
},
58+
Boot2DockerURL: download.LocalISOResource(cc.MinikubeISO),
59+
DiskSize: cc.DiskSize,
60+
Memory: cc.Memory,
61+
CPU: cc.CPUs,
62+
}, nil
63+
}
64+
65+
func status() registry.State {
66+
var qemuSystem string
67+
arch := runtime.GOARCH
68+
switch arch {
69+
case "amd64":
70+
qemuSystem = "qemu-system-x86_64"
71+
case "arm64":
72+
qemuSystem = "qemu-system-aarch64"
73+
default:
74+
return registry.State{Error: fmt.Errorf("unknown arch: %s", arch), Doc: docURL}
75+
}
76+
77+
_, err := exec.LookPath(qemuSystem)
78+
if err != nil {
79+
return registry.State{Error: err, Fix: "Install qemu-system", Doc: docURL}
80+
}
81+
82+
return registry.State{Installed: true, Healthy: true, Running: true}
83+
}

site/content/en/docs/drivers/_index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ To do so, we use the [Docker Machine](https://github.com/docker/machine) library
1717
* [Docker]({{<ref "docker.md">}}) - container-based (preferred)
1818
* [KVM2]({{<ref "kvm2.md">}}) - VM-based (preferred)
1919
* [VirtualBox]({{<ref "virtualbox.md">}}) - VM
20+
* [QEMU]({{<ref "qemu.md">}}) - VM (experimental)
2021
* [None]({{<ref "none.md">}}) - bare-metal
2122
* [Podman]({{<ref "podman.md">}}) - container (experimental)
2223
* [SSH]({{<ref "ssh.md">}}) - remote ssh
@@ -29,6 +30,7 @@ To do so, we use the [Docker Machine](https://github.com/docker/machine) library
2930
* [VirtualBox]({{<ref "virtualbox.md">}}) - VM
3031
* [Parallels]({{<ref "parallels.md">}}) - VM
3132
* [VMware Fusion]({{<ref "vmware.md">}}) - VM
33+
* [QEMU]({{<ref "qemu.md">}}) - VM (experimental)
3234
* [SSH]({{<ref "ssh.md">}}) - remote ssh
3335

3436
## Windows
@@ -37,4 +39,5 @@ To do so, we use the [Docker Machine](https://github.com/docker/machine) library
3739
* [Docker]({{<ref "docker.md">}}) - VM + Container (preferred)
3840
* [VirtualBox]({{<ref "virtualbox.md">}}) - VM
3941
* [VMware Workstation]({{<ref "vmware.md">}}) - VM
42+
* [QEMU]({{<ref "qemu.md">}}) - VM (experimental)
4043
* [SSH]({{<ref "ssh.md">}}) - remote ssh

0 commit comments

Comments
 (0)