From a941e5466dd9a6b35d8882af273d2cac14dc506e Mon Sep 17 00:00:00 2001 From: Itamar Holder Date: Wed, 28 Apr 2021 10:12:56 +0300 Subject: [PATCH] Add new example VMI (vmi-kernel-boot) for testing Signed-off-by: Itamar Holder --- examples/vmi-kernel-boot.yaml | 23 +++++++++++++++++++ tools/vms-generator/utils/utils.go | 33 ++++++++++++++++++++++++++++ tools/vms-generator/vms-generator.go | 1 + 3 files changed, 57 insertions(+) create mode 100644 examples/vmi-kernel-boot.yaml diff --git a/examples/vmi-kernel-boot.yaml b/examples/vmi-kernel-boot.yaml new file mode 100644 index 000000000000..aa69bcf87b29 --- /dev/null +++ b/examples/vmi-kernel-boot.yaml @@ -0,0 +1,23 @@ +--- +apiVersion: kubevirt.io/v1 +kind: VirtualMachineInstance +metadata: + labels: + special: vmi-kernel-boot + name: vmi-kernel-boot +spec: + domain: + devices: {} + firmware: + kernelBoot: + container: + image: registry:5000/kubevirt/alpine-ext-kernel-boot-demo:devel + initrdPath: /boot/initramfs-virt + kernelPath: /boot/vmlinuz-virt + kernelArgs: console=ttyS0 + machine: + type: "" + resources: + requests: + memory: 1Gi + terminationGracePeriodSeconds: 0 diff --git a/tools/vms-generator/utils/utils.go b/tools/vms-generator/utils/utils.go index ea1f6ae025eb..426dc97b8e14 100644 --- a/tools/vms-generator/utils/utils.go +++ b/tools/vms-generator/utils/utils.go @@ -48,6 +48,7 @@ const ( VmiPVC = "vmi-pvc" VmiBlockPVC = "vmi-block-pvc" VmiWindows = "vmi-windows" + VmiKernelBoot = "vmi-kernel-boot" VmiSlirp = "vmi-slirp" VmiMasquerade = "vmi-masquerade" VmiSRIOV = "vmi-sriov" @@ -90,6 +91,7 @@ const ( imageCirros = "cirros-container-disk-demo" imageFedora = "fedora-cloud-container-disk-demo" imageMicroLiveCD = "microlivecd-container-disk-demo" + imageKernelBoot = "alpine-ext-kernel-boot-demo" ) const windowsFirmware = "5d307ca9-b3ef-428c-8861-06e72d69f223" const defaultInterfaceName = "default" @@ -188,6 +190,23 @@ func addContainerDisk(spec *v1.VirtualMachineInstanceSpec, image string, bus str return spec } +func addKernelBootContainer(spec *v1.VirtualMachineInstanceSpec, image, kernelArgs, kernelPath, initrdPath string) *v1.VirtualMachineInstanceSpec { + if spec.Domain.Firmware == nil { + spec.Domain.Firmware = &v1.Firmware{} + } + + spec.Domain.Firmware.KernelBoot = &v1.KernelBoot{ + KernelArgs: kernelArgs, + Container: &v1.KernelBootContainer{ + Image: image, + KernelPath: kernelPath, + InitrdPath: initrdPath, + }, + } + + return spec +} + func addNoCloudDisk(spec *v1.VirtualMachineInstanceSpec) *v1.VirtualMachineInstanceSpec { return addNoCloudDiskWitUserData(spec, "#!/bin/sh\n\necho 'printed from cloud-init userdata'\n") } @@ -573,6 +592,20 @@ func GetVMIWindows() *v1.VirtualMachineInstance { return vmi } +func GetVMIKernelBoot() *v1.VirtualMachineInstance { + vmi := getBaseVMI(VmiKernelBoot) + + image := fmt.Sprintf("%s/%s:%s", DockerPrefix, imageKernelBoot, DockerTag) + KernelArgs := "console=ttyS0" + kernelPath := "/boot/vmlinuz-virt" + initrdPath := "/boot/initramfs-virt" + + addKernelBootContainer(&vmi.Spec, image, KernelArgs, kernelPath, initrdPath) + + vmi.Spec.Domain.Resources.Requests[k8sv1.ResourceMemory] = resource.MustParse("1Gi") + return vmi +} + func getBaseVM(name string, labels map[string]string) *v1.VirtualMachine { baseVMISpec := getBaseVMISpec() running := false diff --git a/tools/vms-generator/vms-generator.go b/tools/vms-generator/vms-generator.go index b60e5bd079e5..4bf35e81dcc8 100644 --- a/tools/vms-generator/vms-generator.go +++ b/tools/vms-generator/vms-generator.go @@ -93,6 +93,7 @@ pciHostDevices: utils.VmiHostDisk: utils.GetVMIHostDisk(), utils.VmiGPU: utils.GetVMIGPU(), utils.VmiMacvtap: utils.GetVMIMacvtap(), + utils.VmiKernelBoot: utils.GetVMIKernelBoot(), } var vmireplicasets = map[string]*v1.VirtualMachineInstanceReplicaSet{