|
| 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 | +} |
0 commit comments