Skip to content

Commit

Permalink
Pass rootdisk parameter to virt-v2v and adjust boot order
Browse files Browse the repository at this point in the history
Signed-off-by: Bella Khizgiyaev <[email protected]>
  • Loading branch information
bkhizgiy committed Jun 13, 2024
1 parent 05a06d2 commit 7c9c2ff
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,7 @@ spec:
type: string
rootDisk:
description: Choose the primary disk the VM boots from
format: int32
type: integer
type: string
started:
description: Started timestamp.
format: date-time
Expand Down
3 changes: 1 addition & 2 deletions operator/config/crd/bases/forklift.konveyor.io_plans.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1011,8 +1011,7 @@ spec:
type: string
rootDisk:
description: Choose the primary disk the VM boots from
format: int32
type: integer
type: string
started:
description: Started timestamp.
format: date-time
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/forklift/v1beta1/plan/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type VMStatus struct {
// The firmware type detected from the OVF file produced by virt-v2v.
Firmware string `json:"firmware,omitempty"`
//Choose the primary disk the VM boots from
RootDisk int32 `json:"rootDisk,omitempty"`
RootDisk string `json:"rootDisk,omitempty"`
// Conditions.
libcnd.Conditions `json:",inline"`
}
Expand Down
23 changes: 21 additions & 2 deletions pkg/controller/plan/adapter/vsphere/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"regexp"
"sort"
"strings"
"strconv"


api "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
"github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1/plan"
Expand Down Expand Up @@ -499,7 +501,7 @@ func (r *Builder) VirtualMachine(vmRef ref.Ref, object *cnv.VirtualMachineSpec,
if object.Template == nil {
object.Template = &cnv.VirtualMachineInstanceTemplateSpec{}
}
r.mapDisks(vm, persistentVolumeClaims, object)
r.mapDisks(vm, vmRef, persistentVolumeClaims, object)
r.mapFirmware(vm, object)
r.mapCPU(vm, object)
r.mapMemory(vm, object)
Expand Down Expand Up @@ -636,7 +638,7 @@ func (r *Builder) mapFirmware(vm *model.VM, object *cnv.VirtualMachineSpec) {
object.Template.Spec.Domain.Firmware = firmware
}

func (r *Builder) mapDisks(vm *model.VM, persistentVolumeClaims []*core.PersistentVolumeClaim, object *cnv.VirtualMachineSpec) {
func (r *Builder) mapDisks(vm *model.VM, vmRef ref.Ref, persistentVolumeClaims []*core.PersistentVolumeClaim, object *cnv.VirtualMachineSpec) {
var kVolumes []cnv.Volume
var kDisks []cnv.Disk

Expand All @@ -654,6 +656,20 @@ func (r *Builder) mapDisks(vm *model.VM, persistentVolumeClaims []*core.Persiste
pvcMap[pvc.Annotations[AnnImportBackingFile]] = pvc
}
}

var bootDisk int
for _, vmConf := range r.Migration.Status.VMs {
if vmConf.ID == vmRef.ID {
var err error
bootDisk, err = strconv.Atoi(vmConf.RootDisk)
if err != nil {
bootDisk = 1
}
break
}
}
bootOrder := func(order uint) *uint { return &order }

for i, disk := range disks {
pvc := pvcMap[r.baseVolume(disk.File)]
volumeName := fmt.Sprintf("vol-%v", i)
Expand All @@ -675,6 +691,9 @@ func (r *Builder) mapDisks(vm *model.VM, persistentVolumeClaims []*core.Persiste
},
},
}
if bootDisk == i+1 {
kubevirtDisk.BootOrder = bootOrder(1)
}
kVolumes = append(kVolumes, volume)
kDisks = append(kDisks, kubevirtDisk)
}
Expand Down
19 changes: 5 additions & 14 deletions pkg/controller/plan/kubevirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/konveyor/forklift-controller/pkg/controller/plan/adapter"
ovfparser "github.com/konveyor/forklift-controller/pkg/controller/plan/adapter/ova"
plancontext "github.com/konveyor/forklift-controller/pkg/controller/plan/context"
model "github.com/konveyor/forklift-controller/pkg/controller/provider/web/vsphere"
libcnd "github.com/konveyor/forklift-controller/pkg/lib/condition"
liberr "github.com/konveyor/forklift-controller/pkg/lib/error"
core "k8s.io/api/core/v1"
Expand Down Expand Up @@ -1597,26 +1596,18 @@ func (r *KubeVirt) guestConversionPod(vm *plan.VMStatus, vmVolumes []cnv.Volume,
return
}

if vm.RootDisk > 0 {
vmInventory := &model.VM{}
err = r.Source.Inventory.Find(vmInventory, vm.Ref)
if err != nil {
err = liberr.Wrap(err, "vm", vm.Ref.String())
if vm.RootDisk != "" {
diskNum, errDisk := strconv.Atoi(vm.RootDisk)
if errDisk != nil {
return
}

var rootDisk string
for diskNum, disk := range vmInventory.Disks {
if disk.Number == vm.RootDisk {
rootDisk = fmt.Sprintf("/dev/sd%c", 'a'+(diskNum)%26)
}
}
if diskNum > 0 {

if rootDisk != "" {
environment = append(environment,
core.EnvVar{
Name: "V2V_RootDisk",
Value: rootDisk,
Value: vm.RootDisk,
})
}
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/controller/provider/container/vsphere/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ func (v *VmAdapter) Apply(u types.ObjectUpdate) {
// Update virtual disk devices.
func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) {
disks := []model.Disk{}
var diskNum int32 = 1
//var diskNum int32 = 1
for _, dev := range devArray.VirtualDevice {
switch dev.(type) {
case *types.VirtualDisk:
Expand All @@ -713,7 +713,7 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) {
File: backing.FileName,
Capacity: disk.CapacityInBytes,
Mode: backing.DiskMode,
Number: diskNum,
//Number: diskNum,
}
if backing.Datastore != nil {
datastoreId, _ := sanitize(backing.Datastore.Value)
Expand All @@ -723,15 +723,15 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) {
}
}
disks = append(disks, md)
diskNum++
//diskNum++
case *types.VirtualDiskFlatVer2BackingInfo:
md := model.Disk{
Key: disk.Key,
File: backing.FileName,
Capacity: disk.CapacityInBytes,
Shared: backing.Sharing != "sharingNone",
Mode: backing.DiskMode,
Number: diskNum,
//Number: diskNum,
}
if backing.Datastore != nil {
datastoreId, _ := sanitize(backing.Datastore.Value)
Expand All @@ -741,7 +741,7 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) {
}
}
disks = append(disks, md)
diskNum++
//diskNum++
case *types.VirtualDiskRawDiskMappingVer1BackingInfo:
md := model.Disk{
Key: disk.Key,
Expand All @@ -750,7 +750,7 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) {
Shared: backing.Sharing != "sharingNone",
Mode: backing.DiskMode,
RDM: true,
Number: diskNum,
//Number: diskNum,
}
if backing.Datastore != nil {
datastoreId, _ := sanitize(backing.Datastore.Value)
Expand All @@ -760,18 +760,18 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) {
}
}
disks = append(disks, md)
diskNum++
//diskNum++
case *types.VirtualDiskRawDiskVer2BackingInfo:
md := model.Disk{
Key: disk.Key,
File: backing.DescriptorFileName,
Capacity: disk.CapacityInBytes,
Shared: backing.Sharing != "sharingNone",
RDM: true,
Number: diskNum,
//Number: diskNum,
}
disks = append(disks, md)
diskNum++
//diskNum++
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/provider/model/vsphere/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ type Disk struct {
Shared bool `json:"shared"`
RDM bool `json:"rdm"`
Mode string `json:"mode,omitempty"`
Number int32 `json:"number,omitempty"`
//Number int32 `json:"number,omitempty"`
}

// Virtual Device.
Expand Down
18 changes: 13 additions & 5 deletions virt-v2v/cold/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,21 @@ func buildCommand() []string {
}

fmt.Println("Preparing virt-v2v")

if checkEnvVariablesSet("V2V_RootDisk") {
diskNum, err := strconv.Atoi(os.Getenv("V2V_RootDisk"))
if err != nil {
fmt.Println("Error:", err)
os.Exit(1)
}
rootDisk := fmt.Sprintf("/dev/sd%s", genName(diskNum))
virtV2vArgs = append(virtV2vArgs, "--root", rootDisk)
} else {
virtV2vArgs = append(virtV2vArgs, "--root", "first")
}

switch source {
case vSphere:
if checkEnvVariablesSet("V2V_RootDisk") {
virtV2vArgs = append(virtV2vArgs, "--root", os.Getenv("V2V_RootDisk"))
} else {
virtV2vArgs = append(virtV2vArgs, "--root", "first")
}
virtV2vArgs = append(virtV2vArgs, "-i", "libvirt", "-ic", os.Getenv("V2V_libvirtURL"))
case OVA:
virtV2vArgs = append(virtV2vArgs, "-i", "ova", os.Getenv("V2V_diskPath"))
Expand Down

0 comments on commit 7c9c2ff

Please sign in to comment.