Skip to content

Commit

Permalink
vms-generator: generate an example of usb pass through
Browse files Browse the repository at this point in the history
Signed-off-by: Luboslav Pivarc <[email protected]>
Signed-off-by: Victor Toso <[email protected]>
  • Loading branch information
xpivarc authored and victortoso committed Sep 19, 2023
1 parent 71d7396 commit 94b757d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
39 changes: 39 additions & 0 deletions examples/vmi-usb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
apiVersion: kubevirt.io/v1
kind: VirtualMachineInstance
metadata:
labels:
special: vmi-usb
name: vmi-usb
spec:
domain:
devices:
disks:
- disk:
bus: virtio
name: containerdisk
- disk:
bus: virtio
name: cloudinitdisk
hostDevices:
- deviceName: kubevirt.io/storage
name: node-usb-to-vmi-storage
rng: {}
resources:
requests:
memory: 1024M
terminationGracePeriodSeconds: 0
volumes:
- containerDisk:
image: registry:5000/kubevirt/fedora-with-test-tooling-container-disk:devel
name: containerdisk
- cloudInitNoCloud:
userData: |-
#cloud-config
password: fedora
chpasswd: { expire: False }
packages:
- nginx
runcmd:
- [ "systemctl", "enable", "--now", "nginx" ]
name: cloudinitdisk
15 changes: 15 additions & 0 deletions tools/vms-generator/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const (
VmiGPU = "vmi-gpu"
VmiARM = "vmi-arm"
VmiMacvtap = "vmi-macvtap"
VmiUSB = "vmi-usb"
VmTemplateFedora = "vm-template-fedora"
VmTemplateRHEL7 = "vm-template-rhel7"
VmTemplateWindows = "vm-template-windows2012r2"
Expand Down Expand Up @@ -1232,6 +1233,20 @@ func GetVMIARM() *v1.VirtualMachineInstance {
return vmi
}

func GetVMIUSB() *v1.VirtualMachineInstance {
vmi := getBaseVMI(VmiUSB)
vmi.Spec.Domain.Resources.Requests[k8sv1.ResourceMemory] = resource.MustParse("1024M")
initFedora(&vmi.Spec)
addNoCloudDiskWitUserData(&vmi.Spec, generateCloudConfigString(cloudConfigUserPassword, cloudConfigInstallAndStartService))

vmi.Spec.Domain.Devices.HostDevices = append(vmi.Spec.Domain.Devices.HostDevices,
v1.HostDevice{
Name: "node-usb-to-vmi-storage",
DeviceName: "kubevirt.io/storage",
})
return vmi
}

func generateCloudConfigString(cloudConfigElement ...string) string {
return strings.Join(
append([]string{cloudConfigHeader}, cloudConfigElement...), "\n")
Expand Down
3 changes: 2 additions & 1 deletion tools/vms-generator/vms-generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func main() {

config, _, _ := testutils.NewFakeClusterConfigUsingKVConfig(&v1.KubeVirtConfiguration{
DeveloperConfiguration: &v1.DeveloperConfiguration{
FeatureGates: []string{"DataVolumes", "LiveMigration", "SRIOV", "GPU", "HostDisk", "Macvtap"},
FeatureGates: []string{"DataVolumes", "LiveMigration", "SRIOV", "GPU", "HostDisk", "Macvtap", "HostDevices"},
},
NetworkConfiguration: &v1.NetworkConfiguration{
PermitSlirpInterface: &permit,
Expand Down Expand Up @@ -125,6 +125,7 @@ func main() {
utils.VmiMacvtap: utils.GetVMIMacvtap(),
utils.VmiKernelBoot: utils.GetVMIKernelBoot(),
utils.VmiARM: utils.GetVMIARM(),
utils.VmiUSB: utils.GetVMIUSB(),
}

var vmireplicasets = map[string]*v1.VirtualMachineInstanceReplicaSet{
Expand Down

0 comments on commit 94b757d

Please sign in to comment.