Skip to content

Commit

Permalink
virt-api, Arm64: refactor function ValidateVirtualMachineInstanceArm6…
Browse files Browse the repository at this point in the history
…4Setting

Signed-off-by: howard zhang <[email protected]>
  • Loading branch information
zhlhahaha committed Jan 12, 2023
1 parent 668a9e8 commit 486065d
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions pkg/virt-api/webhooks/arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,19 @@ const (
defaultCPUModel = v1.CPUModeHostPassthrough
)

// ValidateVirtualMachineInstanceArm64Setting is validation function for validating-webhook
// 1. if setting bios boot
// 2. if use uefi secure boot
// 3. if use host-model for cpu model
// 4. if not use 'scsi', 'virtio' as disk bus
// ValidateVirtualMachineInstanceArm64Setting is a validation function for validating-webhook to filter unsupported setting on Arm64
func ValidateVirtualMachineInstanceArm64Setting(field *k8sfield.Path, spec *v1.VirtualMachineInstanceSpec) []metav1.StatusCause {
var statusCauses []metav1.StatusCause
validateBootOptions(field, spec, &statusCauses)
validateCPUModel(field, spec, &statusCauses)
validateDiskBus(field, spec, &statusCauses)
return statusCauses
}

func validateBootOptions(field *k8sfield.Path, spec *v1.VirtualMachineInstanceSpec, statusCauses *[]metav1.StatusCause) {
if spec.Domain.Firmware != nil && spec.Domain.Firmware.Bootloader != nil {
if spec.Domain.Firmware.Bootloader.BIOS != nil {
statusCauses = append(statusCauses, metav1.StatusCause{
*statusCauses = append(*statusCauses, metav1.StatusCause{
Type: metav1.CauseTypeFieldValueNotSupported,
Message: "Arm64 does not support bios boot, please change to uefi boot",
Field: field.Child("domain", "firmware", "bootloader", "bios").String(),
Expand All @@ -53,21 +56,27 @@ func ValidateVirtualMachineInstanceArm64Setting(field *k8sfield.Path, spec *v1.V
// 1 is EFI is enabled without Secureboot setting
// 2 is both EFI and Secureboot enabled
if spec.Domain.Firmware.Bootloader.EFI.SecureBoot == nil || (spec.Domain.Firmware.Bootloader.EFI.SecureBoot != nil && *spec.Domain.Firmware.Bootloader.EFI.SecureBoot) {
statusCauses = append(statusCauses, metav1.StatusCause{
*statusCauses = append(*statusCauses, metav1.StatusCause{
Type: metav1.CauseTypeFieldValueNotSupported,
Message: "UEFI secure boot is currently not supported on aarch64 Arch",
Field: field.Child("domain", "firmware", "bootloader", "efi", "secureboot").String(),
})
}
}
}
}

func validateCPUModel(field *k8sfield.Path, spec *v1.VirtualMachineInstanceSpec, statusCauses *[]metav1.StatusCause) {
if spec.Domain.CPU != nil && (&spec.Domain.CPU.Model != nil) && spec.Domain.CPU.Model == "host-model" {
statusCauses = append(statusCauses, metav1.StatusCause{
*statusCauses = append(*statusCauses, metav1.StatusCause{
Type: metav1.CauseTypeFieldValueNotSupported,
Message: "Arm64 not support host model well",
Message: "Arm64 not support CPU host-model",
Field: field.Child("domain", "cpu", "model").String(),
})
}
}

func validateDiskBus(field *k8sfield.Path, spec *v1.VirtualMachineInstanceSpec, statusCauses *[]metav1.StatusCause) {
if spec.Domain.Devices.Disks != nil {
// checkIfBusAvailable: if bus type is nil, virtio, scsi return true, otherwise, return false
checkIfBusAvailable := func(bus v1.DiskBus) bool {
Expand All @@ -79,29 +88,28 @@ func ValidateVirtualMachineInstanceArm64Setting(field *k8sfield.Path, spec *v1.V

for i, disk := range spec.Domain.Devices.Disks {
if disk.Disk != nil && !checkIfBusAvailable(disk.Disk.Bus) {
statusCauses = append(statusCauses, metav1.StatusCause{
*statusCauses = append(*statusCauses, metav1.StatusCause{
Type: metav1.CauseTypeFieldValueNotSupported,
Message: "Arm64 not support this disk bus type, please use virtio or scsi",
Field: field.Child("domain", "devices", "disks").Index(i).Child("disk", "bus").String(),
})
}
if disk.CDRom != nil && !checkIfBusAvailable(disk.CDRom.Bus) {
statusCauses = append(statusCauses, metav1.StatusCause{
*statusCauses = append(*statusCauses, metav1.StatusCause{
Type: metav1.CauseTypeFieldValueNotSupported,
Message: "Arm64 not support this disk bus type, please use virtio or scsi",
Field: field.Child("domain", "devices", "disks").Index(i).Child("cdrom", "bus").String(),
})
}
if disk.LUN != nil && !checkIfBusAvailable(disk.LUN.Bus) {
statusCauses = append(statusCauses, metav1.StatusCause{
*statusCauses = append(*statusCauses, metav1.StatusCause{
Type: metav1.CauseTypeFieldValueNotSupported,
Message: "Arm64 not support this disk bus type, please use virtio or scsi",
Field: field.Child("domain", "devices", "disks").Index(i).Child("lun", "bus").String(),
})
}
}
}
return statusCauses
}

// setDefaultCPUModel set default cpu model to host-passthrough
Expand Down

0 comments on commit 486065d

Please sign in to comment.