diff --git a/pkg/controller/plan/util/kubevirtvmparser.go b/pkg/controller/plan/util/kubevirtvmparser.go index b106ef11d..a0f14381a 100644 --- a/pkg/controller/plan/util/kubevirtvmparser.go +++ b/pkg/controller/plan/util/kubevirtvmparser.go @@ -66,11 +66,17 @@ func GetFirmwareFromYaml(yamlData []byte) (string, error) { if err := yaml.Unmarshal(yamlData, &cnvVm); err != nil { return "", err } - if cnvVm.Spec.Template.Spec.Domain.Firmware.Bootloader.BIOS != nil { - return "bios", nil - } - if cnvVm.Spec.Template.Spec.Domain.Firmware.Bootloader.EFI != nil { - return "uefi", nil + + if cnvVm.Spec.Template != nil && + cnvVm.Spec.Template.Spec.Domain.Firmware != nil && + cnvVm.Spec.Template.Spec.Domain.Firmware.Bootloader != nil { + + if cnvVm.Spec.Template.Spec.Domain.Firmware.Bootloader.BIOS != nil { + return "bios", nil + } + if cnvVm.Spec.Template.Spec.Domain.Firmware.Bootloader.EFI != nil { + return "uefi", nil + } } log.Info("Firmware type was not detected") diff --git a/pkg/controller/plan/util/kubevirtvmparser_test.go b/pkg/controller/plan/util/kubevirtvmparser_test.go index 3819b4c3c..1178a9374 100644 --- a/pkg/controller/plan/util/kubevirtvmparser_test.go +++ b/pkg/controller/plan/util/kubevirtvmparser_test.go @@ -13,6 +13,8 @@ func TestKubevirtVmParser(t *testing.T) { testFile(t, "new_format_efi.yml", "uefi") testFile(t, "old_format_bios.yml", "bios") testFile(t, "old_format_efi.yml", "uefi") + testFile(t, "old_format_none.yml", "") + testFile(t, "new_format_none.yml", "") } func testFile(t *testing.T, filename, expectedFormat string) { diff --git a/pkg/controller/plan/util/testdata/new_format_none.yml b/pkg/controller/plan/util/testdata/new_format_none.yml new file mode 100644 index 000000000..512fedd1f --- /dev/null +++ b/pkg/controller/plan/util/testdata/new_format_none.yml @@ -0,0 +1,37 @@ +--- +# generated by virt-v2v 2.5.8fedora=40,release=1.fc40 +apiVersion: kubevirt.io/v1 +kind: VirtualMachine +metadata: + name: mnecas-win-2022 + labels: + libguestfs.org/virt-v2v-version: "2.5.8" + libguestfs.org/genid: f2fc75e8-4961-1425-4740-fcf2bc09685a + libguestfs.org/osinfo: win2k22 + libguestfs.org/source: vmware +spec: + template: + spec: + domain: + firmware: + bootloader: + resources: + clock: + timer: + hpet: + present: false + hyperv: {} + pit: + tickPolicy: delay + rtc: + tickPolicy: catchup + utc: {} + requests: + memory: 8192Mi + features: + cpu: + sockets: 2 + cores: 2 + thread: 1 + terminationGracePeriodSeconds: 0 + diff --git a/pkg/controller/plan/util/testdata/old_format_none.yml b/pkg/controller/plan/util/testdata/old_format_none.yml new file mode 100644 index 000000000..582632b5a --- /dev/null +++ b/pkg/controller/plan/util/testdata/old_format_none.yml @@ -0,0 +1,37 @@ +--- +# generated by virt-v2v 2.5.8fedora=40,release=1.fc40 +apiVersion: kubevirt.io/v1 +kind: VirtualMachine +metadata: + name: mnecas-win-2022 + labels: + libguestfs.org/virt-v2v-version: "2.5.8" + libguestfs.org/genid: 4f3c8a7c-3464-c9b0-cf79-08325a6bf1e8 + libguestfs.org/osinfo: win2k22 + libguestfs.org/source: kvm +spec: + template: + spec: + domain: + os: + resources: + clock: + timer: + hpet: + present: false + hyperv: {} + pit: + tickPolicy: delay + rtc: + tickPolicy: catchup + utc: {} + requests: + memory: 8192Mi + features: + acpi: {} + apic: {} + cpu: + sockets: 2 + cores: 2 + thread: 1 + terminationGracePeriodSeconds: 0