Skip to content

Commit 12c4bf5

Browse files
committed
Add ability to create extra disks on qemu2 vms
Add the ability to create and attach extra disks to qemu2 vms. Signed-off-by: Blaine Gardner <[email protected]>
1 parent 0a10f15 commit 12c4bf5

File tree

16 files changed

+64
-37
lines changed

16 files changed

+64
-37
lines changed

Diff for: cmd/minikube/cmd/start_flags.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func initMinikubeFlags() {
196196
startCmd.Flags().StringP(network, "", "", "network to run minikube with. Now it is used by docker/podman and KVM drivers. If left empty, minikube will create a new network.")
197197
startCmd.Flags().StringVarP(&outputFormat, "output", "o", "text", "Format to print stdout in. Options include: [text,json]")
198198
startCmd.Flags().StringP(trace, "", "", "Send trace events. Options include: [gcp]")
199-
startCmd.Flags().Int(extraDisks, 0, "Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit and kvm2 drivers)")
199+
startCmd.Flags().Int(extraDisks, 0, "Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit, kvm2, and qemu2 drivers)")
200200
startCmd.Flags().Duration(certExpiration, constants.DefaultCertExpiration, "Duration until minikube certificate expiration, defaults to three years (26280h).")
201201
startCmd.Flags().String(binaryMirror, "", "Location to fetch kubectl, kubelet, & kubeadm binaries from.")
202202
startCmd.Flags().Bool(disableOptimizations, false, "If set, disables optimizations that are set for local Kubernetes. Including decreasing CoreDNS replicas from 2 to 1. Defaults to false.")
@@ -940,7 +940,7 @@ func interpretWaitFlag(cmd cobra.Command) map[string]bool {
940940
}
941941

942942
func checkExtraDiskOptions(cmd *cobra.Command, driverName string) {
943-
supportedDrivers := []string{driver.HyperKit, driver.KVM2}
943+
supportedDrivers := []string{driver.HyperKit, driver.KVM2, driver.QEMU2}
944944

945945
if cmd.Flags().Changed(extraDisks) {
946946
supported := false

Diff for: pkg/drivers/common.go

+29
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,35 @@ func ExtraDiskPath(d *drivers.BaseDriver, diskID int) string {
5656
return filepath.Join(d.ResolveStorePath("."), file)
5757
}
5858

59+
// CreateRawDisk creates a new raw disk image.
60+
//
61+
// Example usage:
62+
//
63+
// path := ExtraDiskPath(baseDriver, diskID)
64+
// err := CreateRawDisk(path, baseDriver.DiskSize)
65+
func CreateRawDisk(diskPath string, sizeMB int) error {
66+
log.Infof("Creating raw disk image: %s of size %vMB", diskPath, sizeMB)
67+
68+
_, err := os.Stat(diskPath)
69+
if err != nil {
70+
if !os.IsNotExist(err) {
71+
// un-handle-able error stat-ing the disk file
72+
return errors.Wrap(err, "stat")
73+
}
74+
// disk file does not exist; create it
75+
file, err := os.OpenFile(diskPath, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0644)
76+
if err != nil {
77+
return errors.Wrap(err, "open")
78+
}
79+
defer file.Close()
80+
81+
if err := file.Truncate(util.ConvertMBToBytes(sizeMB)); err != nil {
82+
return errors.Wrap(err, "truncate")
83+
}
84+
}
85+
return nil
86+
}
87+
5988
// CommonDriver is the common driver base class
6089
type CommonDriver struct{}
6190

Diff for: pkg/drivers/kvm/disks.go

-26
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@ package kvm
2121
import (
2222
"bytes"
2323
"fmt"
24-
"os"
2524
"text/template"
26-
27-
"github.com/docker/machine/libmachine/log"
28-
"github.com/pkg/errors"
29-
"k8s.io/minikube/pkg/drivers"
30-
"k8s.io/minikube/pkg/util"
3125
)
3226

3327
// extraDisksTmpl ExtraDisks XML Template
@@ -58,23 +52,3 @@ func getExtraDiskXML(diskpath string, logicalName string) (string, error) {
5852
}
5953
return extraDisksXML.String(), nil
6054
}
61-
62-
// createExtraDisks creates the extra disk files
63-
func createExtraDisk(d *Driver, index int) (string, error) {
64-
diskPath := drivers.ExtraDiskPath(d.BaseDriver, index)
65-
log.Infof("Creating raw disk image: %s of size %v", diskPath, d.DiskSize)
66-
67-
if _, err := os.Stat(diskPath); os.IsNotExist(err) {
68-
file, err := os.OpenFile(diskPath, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0644)
69-
if err != nil {
70-
return "", errors.Wrap(err, "open")
71-
}
72-
defer file.Close()
73-
74-
if err := file.Truncate(util.ConvertMBToBytes(d.DiskSize)); err != nil {
75-
return "", errors.Wrap(err, "truncate")
76-
}
77-
}
78-
return diskPath, nil
79-
80-
}

Diff for: pkg/drivers/kvm/kvm.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,8 @@ func (d *Driver) Create() (err error) {
365365
return errors.Wrap(err, "cannot create more than 20 extra disks")
366366
}
367367
for i := 0; i < d.ExtraDisks; i++ {
368-
diskpath, err := createExtraDisk(d, i)
369-
if err != nil {
368+
diskpath := pkgdrivers.ExtraDiskPath(d.BaseDriver, i)
369+
if err := pkgdrivers.CreateRawDisk(diskpath, d.DiskSize); err != nil {
370370
return errors.Wrap(err, "creating extra disks")
371371
}
372372
// Starting the logical names for the extra disks from hdd as the cdrom device is set to hdc.

Diff for: pkg/drivers/qemu/qemu.go

+20
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ type Driver struct {
8383
MACAddress string
8484
SocketVMNetPath string
8585
SocketVMNetClientPath string
86+
ExtraDisks int
8687
}
8788

8889
func (d *Driver) GetMachineName() string {
@@ -267,6 +268,16 @@ func (d *Driver) Create() error {
267268
}
268269
}
269270

271+
if d.ExtraDisks > 0 {
272+
log.Info("Creating extra disk images...")
273+
for i := 0; i < d.ExtraDisks; i++ {
274+
path := pkgdrivers.ExtraDiskPath(d.BaseDriver, i)
275+
if err := pkgdrivers.CreateRawDisk(path, d.DiskSize); err != nil {
276+
return err
277+
}
278+
}
279+
}
280+
270281
log.Info("Starting QEMU VM...")
271282
return d.Start()
272283
}
@@ -442,6 +453,15 @@ func (d *Driver) Start() error {
442453
"virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=config-2")
443454
}
444455

456+
for i := 0; i < d.ExtraDisks; i++ {
457+
// use a higher index for extra disks to reduce ID collision with current or future
458+
// low-indexed devices (e.g., firmware, ISO CDROM, cloud config, and network device)
459+
index := i + 10
460+
startCmd = append(startCmd,
461+
"-drive", fmt.Sprintf("file=%s,index=%d,media=disk,format=raw,if=virtio", pkgdrivers.ExtraDiskPath(d.BaseDriver, i), index),
462+
)
463+
}
464+
445465
if d.VirtioDrives {
446466
startCmd = append(startCmd,
447467
"-drive", fmt.Sprintf("file=%s,index=0,media=disk,if=virtio", d.diskPath()))

Diff for: pkg/minikube/registry/drvs/qemu2/qemu2.go

+1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) {
196196
MACAddress: mac,
197197
SocketVMNetPath: cc.SocketVMnetPath,
198198
SocketVMNetClientPath: cc.SocketVMnetClientPath,
199+
ExtraDisks: cc.ExtraDisks,
199200
}, nil
200201
}
201202

Diff for: site/content/en/docs/commands/start.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ minikube start [flags]
5252
The key should be '.' separated, and the first part before the dot is the component to apply the configuration to.
5353
Valid components are: kubelet, kubeadm, apiserver, controller-manager, etcd, proxy, scheduler
5454
Valid kubeadm parameters: ignore-preflight-errors, dry-run, kubeconfig, kubeconfig-dir, node-name, cri-socket, experimental-upload-certs, certificate-key, rootfs, skip-phases, pod-network-cidr
55-
--extra-disks int Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit and kvm2 drivers)
55+
--extra-disks int Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit, kvm2, and qemu2 drivers)
5656
--feature-gates string A set of key=value pairs that describe feature gates for alpha/experimental features.
5757
--force Force minikube to perform possibly dangerous operations
5858
--force-systemd If set, force the container runtime to use systemd as cgroup manager. Defaults to false.

Diff for: translations/de.json

+1
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@
456456
"Noticed you have an activated podman-env on {{.driver_name}} driver in this terminal:": "Aktivives podman-env am Treiber {{.driver_name}} in diesem Terminal erkannt:",
457457
"Number of CPUs allocated to the minikube VM": "Anzahl der CPUs, die der minikube-VM zugeordnet sind",
458458
"Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit and kvm2 drivers)": "Anzahl der Extra-Disks, die erstellt und an die Minikube VM geängt werden (derzeit nur im hyperkit und kvm2 Treiber implementiert)",
459+
"Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit, kvm2, and qemu2 drivers)": "",
459460
"Number of lines back to go within the log": "Anzahl der Zeilen, die im Log zurückgegangen werden soll",
460461
"OS release is {{.pretty_name}}": "Die Betriebssystem-Version ist {{.pretty_name}}",
461462
"One of 'text', 'yaml' or 'json'.": "Entweder 'text', 'yaml' oder 'json'.",

Diff for: translations/es.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@
463463
"Noticed you have an activated docker-env on {{.driver_name}} driver in this terminal:": "",
464464
"Noticed you have an activated podman-env on {{.driver_name}} driver in this terminal:": "",
465465
"Number of CPUs allocated to the minikube VM": "Número de CPU asignadas a la VM de minikube",
466-
"Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit and kvm2 drivers)": "",
466+
"Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit, kvm2, and qemu2 drivers)": "",
467467
"Number of lines back to go within the log": "",
468468
"OS release is {{.pretty_name}}": "",
469469
"One of 'text', 'yaml' or 'json'.": "",

Diff for: translations/fr.json

+1
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@
445445
"Noticed you have an activated docker-env on {{.driver_name}} driver in this terminal:": "Vous avez remarqué que vous avez un docker-env activé sur le pilote {{.driver_name}} dans ce terminal :",
446446
"Noticed you have an activated podman-env on {{.driver_name}} driver in this terminal:": "Vous avez remarqué que vous avez un pilote podman-env activé sur {{.driver_name}} dans ce terminal :",
447447
"Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit and kvm2 drivers)": "Nombre de disques supplémentaires créés et attachés à la machine virtuelle minikube (actuellement implémenté uniquement pour les pilotes hyperkit et kvm2)",
448+
"Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit, kvm2, and qemu2 drivers)": "",
448449
"Number of lines back to go within the log": "Nombre de lignes à remonter dans le journal",
449450
"OS release is {{.pretty_name}}": "La version du système d'exploitation est {{.pretty_name}}",
450451
"One of 'text', 'yaml' or 'json'.": "Un parmi 'text', 'yaml' ou 'json'.",

Diff for: translations/ja.json

+1
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@
431431
"Noticed you have an activated docker-env on {{.driver_name}} driver in this terminal:": "通知: このターミナルでは、{{.driver_name}} ドライバーの docker-env が有効になっています:",
432432
"Noticed you have an activated podman-env on {{.driver_name}} driver in this terminal:": "通知: このターミナルでは、{{.driver_name}} ドライバーの podman-env が有効になっています:",
433433
"Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit and kvm2 drivers)": "作成して minikube VM に接続する追加ディスク数 (現在、hyperkit と kvm2 ドライバーでのみ実装されています)",
434+
"Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit, kvm2, and qemu2 drivers)": "",
434435
"Number of lines back to go within the log": "ログ中で遡る行数",
435436
"OS release is {{.pretty_name}}": "OS リリースは {{.pretty_name}} です",
436437
"One of 'text', 'yaml' or 'json'.": "'text'、'yaml'、'json' のいずれか。",

Diff for: translations/ko.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@
476476
"None of the known repositories in your location are accessible. Using {{.image_repository_name}} as fallback.": "",
477477
"Noticed you have an activated docker-env on {{.driver_name}} driver in this terminal:": "",
478478
"Noticed you have an activated podman-env on {{.driver_name}} driver in this terminal:": "",
479-
"Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit and kvm2 drivers)": "",
479+
"Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit, kvm2, and qemu2 drivers)": "",
480480
"Number of lines back to go within the log": "",
481481
"OS release is {{.pretty_name}}": "",
482482
"One of 'text', 'yaml' or 'json'.": "",

Diff for: translations/pl.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@
468468
"Number of CPUs allocated to Kubernetes.": "Liczba procesorów przypisana do Kubernetesa",
469469
"Number of CPUs allocated to the minikube VM": "Liczba procesorów przypisana do maszyny wirtualnej minikube",
470470
"Number of CPUs allocated to the minikube VM.": "Liczba procesorów przypisana do maszyny wirtualnej minikube",
471-
"Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit and kvm2 drivers)": "",
471+
"Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit, kvm2, and qemu2 drivers)": "",
472472
"Number of lines back to go within the log": "",
473473
"OS release is {{.pretty_name}}": "Wersja systemu operacyjnego to {{.pretty_name}}",
474474
"One of 'text', 'yaml' or 'json'.": "",

Diff for: translations/ru.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@
426426
"None of the known repositories in your location are accessible. Using {{.image_repository_name}} as fallback.": "",
427427
"Noticed you have an activated docker-env on {{.driver_name}} driver in this terminal:": "",
428428
"Noticed you have an activated podman-env on {{.driver_name}} driver in this terminal:": "",
429-
"Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit and kvm2 drivers)": "",
429+
"Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit, kvm2, and qemu2 drivers)": "",
430430
"Number of lines back to go within the log": "",
431431
"OS release is {{.pretty_name}}": "",
432432
"One of 'text', 'yaml' or 'json'.": "",

Diff for: translations/strings.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@
426426
"None of the known repositories in your location are accessible. Using {{.image_repository_name}} as fallback.": "",
427427
"Noticed you have an activated docker-env on {{.driver_name}} driver in this terminal:": "",
428428
"Noticed you have an activated podman-env on {{.driver_name}} driver in this terminal:": "",
429-
"Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit and kvm2 drivers)": "",
429+
"Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit, kvm2, and qemu2 drivers)": "",
430430
"Number of lines back to go within the log": "",
431431
"OS release is {{.pretty_name}}": "",
432432
"One of 'text', 'yaml' or 'json'.": "",

Diff for: translations/zh-CN.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@
543543
"Noticed you have an activated docker-env on {{.driver_name}} driver in this terminal:": "",
544544
"Noticed you have an activated podman-env on {{.driver_name}} driver in this terminal:": "",
545545
"Number of CPUs allocated to the minikube VM": "分配给 minikube 虚拟机的 CPU 的数量",
546-
"Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit and kvm2 drivers)": "",
546+
"Number of extra disks created and attached to the minikube VM (currently only implemented for hyperkit, kvm2, and qemu2 drivers)": "",
547547
"Number of lines back to go within the log": "",
548548
"OS release is {{.pretty_name}}": "",
549549
"One of 'text', 'yaml' or 'json'.": "",

0 commit comments

Comments
 (0)