libvmi: add `WithEmptyDisk` Option
@@ -21,6 +21,7 @@ package libvmi
import (
k8sv1 "k8s.io/api/core/v1"
+ "k8s.io/apimachinery/pkg/api/resource"
v1 "kubevirt.io/api/core/v1"
)
@@ -50,6 +51,14 @@ func WithDataVolume(diskName, pvcName string) Option {
}
}
+// WithEmptyDisk specifies the name of the EmptyDisk to be used.
+func WithEmptyDisk(diskName string, bus v1.DiskBus, capacity resource.Quantity) Option {
+ return func(vmi *v1.VirtualMachineInstance) {
+ addDisk(vmi, newDisk(diskName, bus))
+ addVolume(vmi, newEmptyDisk(diskName, capacity))
+ }
+}
+
func addDisk(vmi *v1.VirtualMachineInstance, disk v1.Disk) {
if !diskExists(vmi, disk) {
vmi.Spec.Domain.Devices.Disks = append(vmi.Spec.Domain.Devices.Disks, disk)
@@ -137,3 +146,14 @@ func newDataVolume(name, dataVolumeName string) v1.Volume {
},
}
}
+
+func newEmptyDisk(name string, capacity resource.Quantity) v1.Volume {
+ return v1.Volume{
+ Name: name,
+ VolumeSource: v1.VolumeSource{
+ EmptyDisk: &v1.EmptyDiskSource{
+ Capacity: capacity,
+ },
+ },
+ }
+}
