Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
Signed-off-by: Bella Khizgiyaev <[email protected]>
  • Loading branch information
bkhizgiy committed Mar 12, 2024
1 parent 7fda24d commit 17fb466
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 3 additions & 1 deletion pkg/controller/plan/adapter/ova/kubevirtvmparser.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ova

import (
liberr "github.com/konveyor/forklift-controller/pkg/lib/error"
"gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -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
Expand All @@ -52,5 +53,6 @@ func ReadConfFromYaml(yamlData []byte) (firmware string, err error) {
firmware = "efi"
return
}
err = liberr.New("Firmware type was not detected")
return
}
6 changes: 2 additions & 4 deletions pkg/controller/plan/kubevirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 12 additions & 3 deletions virt-v2v/cold/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (

var UEFI_RE = regexp.MustCompile(`(?i)UEFI\s+bootloader?`)
var firmware = "bios"
var nameChanged bool

var (
yamlFilePath string
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 17fb466

Please sign in to comment.