From 17fb466e078e07f594fce3c621db52d89b6c5171 Mon Sep 17 00:00:00 2001 From: Bella Khizgiyaev Date: Tue, 12 Mar 2024 11:08:45 +0200 Subject: [PATCH] minor changes Signed-off-by: Bella Khizgiyaev --- .../plan/adapter/ova/kubevirtvmparser.go | 4 +++- pkg/controller/plan/kubevirt.go | 6 ++---- virt-v2v/cold/entrypoint.go | 15 ++++++++++++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/pkg/controller/plan/adapter/ova/kubevirtvmparser.go b/pkg/controller/plan/adapter/ova/kubevirtvmparser.go index 1297eac16..1c2955fe5 100644 --- a/pkg/controller/plan/adapter/ova/kubevirtvmparser.go +++ b/pkg/controller/plan/adapter/ova/kubevirtvmparser.go @@ -1,6 +1,7 @@ package ova import ( + liberr "github.com/konveyor/forklift-controller/pkg/lib/error" "gopkg.in/yaml.v2" ) @@ -38,7 +39,7 @@ type EFI struct { SecureBoot bool `yaml:"secureBoot"` } -func ReadConfFromYaml(yamlData []byte) (firmware string, err error) { +func GetFirmwareFromYaml(yamlData []byte) (firmware string, err error) { var vmi VirtualMachineInstance if err = yaml.Unmarshal(yamlData, &vmi); err != nil { return @@ -52,5 +53,6 @@ func ReadConfFromYaml(yamlData []byte) (firmware string, err error) { firmware = "efi" return } + err = liberr.New("Firmware type was not detected") return } diff --git a/pkg/controller/plan/kubevirt.go b/pkg/controller/plan/kubevirt.go index 5c23011af..2f7629f6a 100644 --- a/pkg/controller/plan/kubevirt.go +++ b/pkg/controller/plan/kubevirt.go @@ -882,14 +882,12 @@ func (r *KubeVirt) UpdateVmByConvertedConfig(vm *plan.VMStatus, pod *core.Pod, s return } - vm.Firmware, err = yamlparser.ReadConfFromYaml(vmConf) + vm.Firmware, err = yamlparser.GetFirmwareFromYaml(vmConf) if err != nil { r.Log.Error(err, "failed to get firmware configuration") } - r.Log.Info("Setting the vm firmware", - "vm", - vm.String()) + r.Log.Info("Setting the vm firmware ", vm.Firmware, "vmId", vm.ID) shutdownURL := fmt.Sprintf("http://%s:8080/shutdown", pod.Status.PodIP) resp, err = http.Post(shutdownURL, "application/json", nil) diff --git a/virt-v2v/cold/entrypoint.go b/virt-v2v/cold/entrypoint.go index 3a749e90a..aa810518e 100644 --- a/virt-v2v/cold/entrypoint.go +++ b/virt-v2v/cold/entrypoint.go @@ -25,6 +25,7 @@ const ( var UEFI_RE = regexp.MustCompile(`(?i)UEFI\s+bootloader?`) var firmware = "bios" +var nameChanged bool var ( yamlFilePath string @@ -68,6 +69,7 @@ func main() { if checkEnvVariablesSet("V2V_NewName") { virtV2vArgs = append(virtV2vArgs, "-on", os.Getenv("V2V_NewName")) + nameChanged = true } virtV2vArgs = append(virtV2vArgs, "-os", DIR) @@ -161,13 +163,20 @@ func LinkDisks(diskKind string, num int) (err error) { return } + var diskSuffix string + if nameChanged { + diskSuffix = os.Getenv("V2V_newName") + } else { + diskSuffix = os.Getenv("V2V_vmName") + } + for _, disk := range disks { diskNum, err := strconv.Atoi(disk[num:]) if err != nil { fmt.Println("Error geting disks names ", err) return err } - diskLink := fmt.Sprintf("%s/%s-sd%s", DIR, os.Getenv("V2V_vmName"), genName(diskNum+1)) + diskLink := fmt.Sprintf("%s/%s-sd%s", DIR, diskSuffix, genName(diskNum+1)) diskImgPath := disk if diskKind == FS { diskImgPath = fmt.Sprintf("%s/disk.img", disk) @@ -264,8 +273,8 @@ func vmHandler(w http.ResponseWriter, r *http.Request) { err := addFirmwareToYaml(yamlFilePath) if err != nil { - fmt.Printf("Error setting yaml file: %v\n", err) - http.Error(w, "Error setting yaml file", http.StatusInternalServerError) + fmt.Printf("Error modifying vm configuration: %v\n", err) + http.Error(w, "Error modifying vm configuration:", http.StatusInternalServerError) } yamlData, err := os.ReadFile(yamlFilePath)