diff --git a/pkg/controller/plan/util/BUILD.bazel b/pkg/controller/plan/util/BUILD.bazel index 7251e3d05..dff289312 100644 --- a/pkg/controller/plan/util/BUILD.bazel +++ b/pkg/controller/plan/util/BUILD.bazel @@ -14,7 +14,6 @@ go_library( "//pkg/apis/forklift/v1beta1", "//pkg/controller/provider/web/openstack", "//pkg/controller/provider/web/ovirt", - "//pkg/lib/error", "//pkg/lib/logging", "//pkg/settings", "//vendor/gopkg.in/yaml.v2:yaml_v2", diff --git a/pkg/controller/plan/util/kubevirtvmparser.go b/pkg/controller/plan/util/kubevirtvmparser.go index 509a86c70..d54b79250 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,47 +52,50 @@ 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) { +func GetFirmwareFromYaml(yamlData []byte) (string, error) { var vm VirtualMachine - if err = yaml.Unmarshal(yamlData, &vm); err != nil { - return + if err := yaml.Unmarshal(yamlData, &vm); err != nil { + return "", err } - if vm.Spec.Domain.OS.Firmware != "" { - return + firmware := vm.Spec.Template.Spec.Domain.OS.Firmware + if firmware == "" { + log.Info("Firmware type was not detected") } - err = liberr.New("Firmware type was not detected") - return + + return firmware, nil } func GetOperationSystemFromYaml(yamlData []byte) (os string, err error) { @@ -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) }