forked from kubevirt-ui/kubevirt-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 2181920: Display "UEFI" for Boot mode for "efi: {}" in yaml
This is a followup of kubevirt-ui#1236 introducing the change that "efi: { secureBoot: false }" was written to VM's yaml when changing Boot mode field value to "UEFI", because that was correct representation of "UEFI" boot mode (secure boot disabled). In this commit, the following remaining issues are fixed: - for existing VM: -- it shows "UEFI" for Boot mode field in Details for "efi: {}" in the yaml's bootloader section - in Create VM wizard: -- it shows "UEFI" for Boot mode field in Review and create VirtualMachine screen for "efi: {}" in the yaml's bootloader section - for existing template: -- it shows "UEFI" for Boot mode field in Details for "efi: {}" in the yaml's bootloader section -- after changing Boot mode field to "UEFI", "efi: {}" occurs in the yaml (this doesn't happen for existing VMs or when creating a VM) Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2181920
- Loading branch information
Hilda Stastna
committed
May 8, 2023
1 parent
da1582d
commit 712263c
Showing
8 changed files
with
110 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 36 additions & 2 deletions
38
src/utils/components/FirmwareBootloaderModal/utils/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,37 @@ | ||
export type BootloaderLabel = { value: string; title: string; description: string }; | ||
import { t } from '@kubevirt-utils/hooks/useKubevirtTranslation'; | ||
|
||
export type BootloaderOptionValue = 'bios' | 'uefi' | 'uefiSecure'; | ||
import { BootloaderLabel } from './types'; | ||
|
||
export enum BootMode { | ||
uefi = 'uefi', | ||
uefiSecure = 'uefiSecure', | ||
bios = 'bios', | ||
} | ||
|
||
export const BootModeTitles = { | ||
[BootMode.uefiSecure]: t('UEFI (secure)'), | ||
[BootMode.uefi]: t('UEFI '), | ||
[BootMode.bios]: t('BIOS'), | ||
}; | ||
|
||
export const bootloaderOptions: BootloaderLabel[] = [ | ||
{ | ||
value: BootMode.bios, | ||
title: BootModeTitles[BootMode.bios], | ||
description: t('Use BIOS when bootloading the guest OS (Default)'), | ||
}, | ||
{ | ||
value: BootMode.uefi, | ||
title: BootModeTitles[BootMode.uefi], | ||
description: t( | ||
'Use UEFI when bootloading the guest OS. Requires SMM feature, if the SMM feature is not set, choosing this method will set it to true', | ||
), | ||
}, | ||
{ | ||
value: BootMode.uefiSecure, | ||
title: BootModeTitles[BootMode.uefiSecure], | ||
description: t( | ||
'Use UEFI when bootloading the guest OS. Requires SMM feature, if the SMM feature is not set, choosing this method will set it to true', | ||
), | ||
}, | ||
]; |
60 changes: 46 additions & 14 deletions
60
src/utils/components/FirmwareBootloaderModal/utils/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,58 @@ | ||
import { TFunction } from 'i18next'; | ||
import produce from 'immer'; | ||
|
||
import { V1VirtualMachine } from '@kubevirt-ui/kubevirt-api/kubevirt'; | ||
import { ensurePath, isEmpty } from '@kubevirt-utils/utils/utils'; | ||
|
||
import { BootloaderOptionValue } from './constants'; | ||
import { BootMode, BootModeTitles } from './constants'; | ||
import { BootloaderOptionValue } from './types'; | ||
|
||
export const isObjectEmpty = (obj: object): boolean => obj && isEmpty(obj); | ||
|
||
export const getBootloaderFromVM = (vm: V1VirtualMachine): BootloaderOptionValue => { | ||
if (vm?.spec?.template?.spec?.domain?.firmware?.bootloader?.efi?.secureBoot) { | ||
return 'uefiSecure'; | ||
const secureBoot = vm?.spec?.template?.spec?.domain?.firmware?.bootloader?.efi; | ||
|
||
if (secureBoot?.secureBoot === true || isObjectEmpty(secureBoot)) { | ||
return BootMode.uefiSecure; | ||
} | ||
if (vm?.spec?.template?.spec?.domain?.firmware?.bootloader?.efi) { | ||
return `uefi`; | ||
if (secureBoot?.secureBoot === false) { | ||
return BootMode.uefi; | ||
} | ||
return 'bios'; | ||
return BootMode.bios; | ||
}; | ||
|
||
export const getBootloaderTitleFromVM = (vm: V1VirtualMachine, t: TFunction): string => { | ||
export const getBootloaderTitleFromVM = (vm: V1VirtualMachine): string => { | ||
const bootloader = getBootloaderFromVM(vm); | ||
const titles = { | ||
uefiSecure: t('UEFI (secure)'), | ||
uefi: t('UEFI '), | ||
bios: t('BIOS'), | ||
}; | ||
|
||
return titles[bootloader]; | ||
return BootModeTitles[bootloader]; | ||
}; | ||
|
||
/** | ||
* A function to return the VirtualMachine object updated with a given boot mode | ||
* @param {V1VirtualMachine} vm - VirtualMachine object | ||
* @param {BootloaderOptionValue} firmwareBootloader - selected boot mode | ||
* @returns {V1VirtualMachine} updated VirtualMachine object | ||
*/ | ||
export const updatedVMBootMode = ( | ||
vm: V1VirtualMachine, | ||
firmwareBootloader: BootloaderOptionValue, | ||
) => | ||
produce<V1VirtualMachine>(vm as V1VirtualMachine, (vmDraft: V1VirtualMachine) => { | ||
ensurePath(vmDraft, 'spec.template.spec.domain.firmware.bootloader'); | ||
ensurePath(vmDraft, 'spec.template.spec.domain.features.smm'); | ||
vmDraft.spec.template.spec.domain.features.smm = { enabled: true }; | ||
|
||
switch (firmwareBootloader) { | ||
case BootMode.uefi: | ||
vmDraft.spec.template.spec.domain.firmware.bootloader = { | ||
efi: { secureBoot: false }, | ||
}; | ||
break; | ||
case BootMode.uefiSecure: | ||
vmDraft.spec.template.spec.domain.firmware.bootloader = { | ||
efi: { secureBoot: true }, | ||
}; | ||
break; | ||
default: | ||
vmDraft.spec.template.spec.domain.firmware.bootloader = { bios: {} }; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters