From 405fc926d836c626a0332a93e8a519c8c8d151fe Mon Sep 17 00:00:00 2001 From: Bella Khizgiyaev Date: Tue, 23 Jul 2024 14:47:46 +0300 Subject: [PATCH] minor changes virt-v2v ymal parser Signed-off-by: Bella Khizgiyaev --- pkg/controller/plan/util/kubevirtvmparser.go | 42 ++++++++++---------- virt-v2v/cold/entrypoint.go | 4 +- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/pkg/controller/plan/util/kubevirtvmparser.go b/pkg/controller/plan/util/kubevirtvmparser.go index 509a86c70..8f87a8e80 100644 --- a/pkg/controller/plan/util/kubevirtvmparser.go +++ b/pkg/controller/plan/util/kubevirtvmparser.go @@ -4,7 +4,6 @@ import ( "fmt" "strings" - liberr "github.com/konveyor/forklift-controller/pkg/lib/error" "github.com/konveyor/forklift-controller/pkg/lib/logging" "gopkg.in/yaml.v2" ) @@ -53,34 +52,36 @@ var osV2VMap = map[string]string{ "win2k22": "windows2022srvNext_64Guest", } -type VirtualMachine struct { - ApiVersion string `yaml:"apiVersion"` - Kind string `yaml:"kind"` - Metadata Metadata `yaml:"metadata"` - Spec Spec `yaml:"spec"` +type OS struct { + Firmware string `yaml:"firmware"` } -type Metadata struct { - Name string `yaml:"name"` - Labels map[string]string `yaml:"labels"` +type Domain struct { + OS OS `yaml:"os"` } -type Spec struct { +type TemplateSpec struct { Domain Domain `yaml:"domain"` } -type Domain struct { - OS OS `yaml:"os"` +type Template struct { + Spec TemplateSpec `yaml:"spec"` } -type OS struct { - Firmware string `yaml:"firmware"` +type VirtualMachineSpec struct { + Template Template `yaml:"template"` } -type Bios struct{} +type VirtualMachine struct { + APIVersion string `yaml:"apiVersion"` + Kind string `yaml:"kind"` + Metadata Metadata `yaml:"metadata"` + Spec VirtualMachineSpec `yaml:"spec"` +} -type EFI struct { - SecureBoot bool `yaml:"secureBoot"` +type Metadata struct { + Name string `yaml:"name"` + Labels map[string]string `yaml:"labels"` } func GetFirmwareFromYaml(yamlData []byte) (firmware string, err error) { @@ -89,10 +90,11 @@ func GetFirmwareFromYaml(yamlData []byte) (firmware string, err error) { return } - if vm.Spec.Domain.OS.Firmware != "" { + firmware = vm.Spec.Template.Spec.Domain.OS.Firmware + if firmware != "" { return } - err = liberr.New("Firmware type was not detected") + log.Info("Firmware type was not detected") return } @@ -124,7 +126,7 @@ func mapOs(labelOS string) (os string) { distro = "fedora" } - os, ok := osV2VMap[os] + os, ok := osV2VMap[distro] if !ok { log.Info(fmt.Sprintf("Received %s, mapped to: %s", labelOS, os)) os = "otherGuest64" diff --git a/virt-v2v/cold/entrypoint.go b/virt-v2v/cold/entrypoint.go index 7b74eb3a3..db2156ba6 100644 --- a/virt-v2v/cold/entrypoint.go +++ b/virt-v2v/cold/entrypoint.go @@ -307,9 +307,7 @@ func vmHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/yaml") _, err = w.Write(yamlData) - if err == nil { - w.WriteHeader(http.StatusOK) - } else { + if err != nil { fmt.Printf("Error writing response: %v\n", err) http.Error(w, "Error writing response", http.StatusInternalServerError) }