|
| 1 | +//go:build linux |
| 2 | + |
| 3 | +/* |
| 4 | +Copyright 2025 The Kubernetes Authors All rights reserved. |
| 5 | +
|
| 6 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +you may not use this file except in compliance with the License. |
| 8 | +You may obtain a copy of the License at |
| 9 | +
|
| 10 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +
|
| 12 | +Unless required by applicable law or agreed to in writing, software |
| 13 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +See the License for the specific language governing permissions and |
| 16 | +limitations under the License. |
| 17 | +*/ |
| 18 | + |
| 19 | +package kvm |
| 20 | + |
| 21 | +import ( |
| 22 | + "github.com/docker/machine/libmachine/drivers" |
| 23 | + "k8s.io/minikube/pkg/drivers/common" |
| 24 | +) |
| 25 | + |
| 26 | +const ( |
| 27 | + qemusystem = "qemu:///system" |
| 28 | + defaultPrivateNetworkName = "minikube-net" |
| 29 | + defaultNetworkName = "default" |
| 30 | +) |
| 31 | + |
| 32 | +// Driver is the machine driver for KVM |
| 33 | +type Driver struct { |
| 34 | + *drivers.BaseDriver |
| 35 | + *common.CommonDriver |
| 36 | + |
| 37 | + // How much memory, in MB, to allocate to the VM |
| 38 | + Memory int |
| 39 | + |
| 40 | + // How many cpus to allocate to the VM |
| 41 | + CPU int |
| 42 | + |
| 43 | + // The name of the default network |
| 44 | + Network string |
| 45 | + |
| 46 | + // The name of the private network |
| 47 | + PrivateNetwork string |
| 48 | + |
| 49 | + // The size of the disk to be created for the VM, in MB |
| 50 | + DiskSize int |
| 51 | + |
| 52 | + // The path of the disk .img |
| 53 | + DiskPath string |
| 54 | + |
| 55 | + // A file or network URI to fetch the minikube ISO |
| 56 | + Boot2DockerURL string |
| 57 | + |
| 58 | + // The location of the iso to boot from |
| 59 | + ISO string |
| 60 | + |
| 61 | + // The randomly generated MAC Address |
| 62 | + // If empty, a random MAC will be generated. |
| 63 | + MAC string |
| 64 | + |
| 65 | + // The randomly generated MAC Address for the NIC attached to the private network |
| 66 | + // If empty, a random MAC will be generated. |
| 67 | + PrivateMAC string |
| 68 | + |
| 69 | + // Whether to passthrough GPU devices from the host to the VM. |
| 70 | + GPU bool |
| 71 | + |
| 72 | + // Whether to hide the KVM hypervisor signature from the guest |
| 73 | + Hidden bool |
| 74 | + |
| 75 | + // XML that needs to be added to passthrough GPU devices. |
| 76 | + DevicesXML string |
| 77 | + |
| 78 | + // QEMU Connection URI |
| 79 | + ConnectionURI string |
| 80 | + |
| 81 | + // NUMA node count default value is 1 |
| 82 | + NUMANodeCount int |
| 83 | + |
| 84 | + // NUMA XML |
| 85 | + NUMANodeXML string |
| 86 | + |
| 87 | + // Extra Disks |
| 88 | + ExtraDisks int |
| 89 | + |
| 90 | + // Extra Disks XML |
| 91 | + ExtraDisksXML []string |
| 92 | +} |
| 93 | + |
| 94 | +// NewDriver creates a new driver for a host |
| 95 | +func NewDriver(hostName, storePath string) *Driver { |
| 96 | + return &Driver{ |
| 97 | + BaseDriver: &drivers.BaseDriver{ |
| 98 | + MachineName: hostName, |
| 99 | + StorePath: storePath, |
| 100 | + SSHUser: "docker", |
| 101 | + }, |
| 102 | + CommonDriver: &common.CommonDriver{}, |
| 103 | + PrivateNetwork: defaultPrivateNetworkName, |
| 104 | + Network: defaultNetworkName, |
| 105 | + ConnectionURI: qemusystem, |
| 106 | + } |
| 107 | +} |
0 commit comments