Skip to content

Commit

Permalink
add vmi-fedora-isolated.yaml
Browse files Browse the repository at this point in the history
An example of YAML configuration with CPU isolation.

Signed-off-by: Marcelo Tosatti <[email protected]>
  • Loading branch information
matosatti committed Nov 9, 2022
1 parent 572076e commit 9bcb03c
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
36 changes: 36 additions & 0 deletions examples/vmi-fedora-isolated.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
apiVersion: kubevirt.io/v1
kind: VirtualMachineInstance
metadata:
labels:
special: vmi-fedora
name: vmi-fedora
spec:
domain:
cpu:
cores: 1
dedicatedCpuPlacement: true
isolateEmulatorThread: true
devices:
disks:
- disk:
bus: virtio
name: containerdisk
- disk:
bus: virtio
name: cloudinitdisk
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 }
name: cloudinitdisk
26 changes: 26 additions & 0 deletions tools/vms-generator/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const (
VmiInstancetypeSmall = "vmi-instancetype-small"
VmiSata = "vmi-sata"
VmiFedora = "vmi-fedora"
VmiFedoraIsolated = "vmi-fedora-isolated"
VmiSecureBoot = "vmi-secureboot"
VmiAlpineEFI = "vmi-alpine-efi"
VmiNoCloud = "vmi-nocloud"
Expand Down Expand Up @@ -186,6 +187,13 @@ func initFedora(spec *v1.VirtualMachineInstanceSpec) *v1.VirtualMachineInstanceS
addRNG(spec) // without RNG, newer fedora images may hang waiting for entropy sources
return spec
}
func initFedoraIsolated(spec *v1.VirtualMachineInstanceSpec) *v1.VirtualMachineInstanceSpec {
addContainerDisk(spec, fmt.Sprintf(strFmt, DockerPrefix, imageFedora, DockerTag), v1.DiskBusVirtio)
addRNG(spec) // without RNG, newer fedora images may hang waiting for entropy sources

addDedicatedAndIsolatedCPU(spec)
return spec
}
func enableNetworkInterfaceMultiqueue(spec *v1.VirtualMachineInstanceSpec, enable bool) {
spec.Domain.Devices.NetworkInterfaceMultiQueue = &enable
}
Expand All @@ -206,6 +214,16 @@ func setDefaultNetworkAndInterface(spec *v1.VirtualMachineInstanceSpec, bindingM
return spec
}

func addDedicatedAndIsolatedCPU(spec *v1.VirtualMachineInstanceSpec) *v1.VirtualMachineInstanceSpec {
cpu := &v1.CPU{
IsolateEmulatorThread: true,
DedicatedCPUPlacement: true,
Cores: 1,
}
spec.Domain.CPU = cpu
return spec
}

func addRNG(spec *v1.VirtualMachineInstanceSpec) *v1.VirtualMachineInstanceSpec {
spec.Domain.Devices.Rng = &v1.Rng{}
return spec
Expand Down Expand Up @@ -453,6 +471,14 @@ func GetVMIEphemeralFedora() *v1.VirtualMachineInstance {
return vmi
}

func GetVMIEphemeralFedoraIsolated() *v1.VirtualMachineInstance {
vmi := getBaseVMI(VmiFedora)
vmi.Spec.Domain.Resources.Requests[k8sv1.ResourceMemory] = resource.MustParse("1024M")
initFedoraIsolated(&vmi.Spec)
addNoCloudDiskWitUserData(&vmi.Spec, generateCloudConfigString(cloudConfigUserPassword))
return vmi
}

func GetVMISecureBoot() *v1.VirtualMachineInstance {
vmi := getBaseVMI(VmiSecureBoot)

Expand Down
1 change: 1 addition & 0 deletions tools/vms-generator/vms-generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func main() {
utils.VmiMigratable: utils.GetVMIMigratable(),
utils.VmiSata: utils.GetVMISata(),
utils.VmiFedora: utils.GetVMIEphemeralFedora(),
utils.VmiFedoraIsolated: utils.GetVMIEphemeralFedoraIsolated(),
utils.VmiSecureBoot: utils.GetVMISecureBoot(),
utils.VmiAlpineEFI: utils.GetVMIAlpineEFI(),
utils.VmiNoCloud: utils.GetVMINoCloud(),
Expand Down

0 comments on commit 9bcb03c

Please sign in to comment.