From 7c8ecad348dbcf9b67caac1a5459f60369ac65ed Mon Sep 17 00:00:00 2001 From: Bella Khizgiyaev Date: Tue, 11 Jun 2024 01:28:58 +0300 Subject: [PATCH] Add support for users to specify rootDisk in multiboot VM. Signed-off-by: Bella Khizgiyaev --- .../forklift.konveyor.io_migrations.yaml | 4 +++ .../crd/bases/forklift.konveyor.io_plans.yaml | 4 +++ pkg/apis/forklift/v1beta1/plan/vm.go | 3 ++- pkg/controller/plan/kubevirt.go | 25 +++++++++++++++++++ .../provider/container/vsphere/model.go | 9 +++++++ .../provider/model/vsphere/model.go | 1 + virt-v2v/cold/entrypoint.go | 7 +++++- 7 files changed, 51 insertions(+), 2 deletions(-) diff --git a/operator/config/crd/bases/forklift.konveyor.io_migrations.yaml b/operator/config/crd/bases/forklift.konveyor.io_migrations.yaml index 76d712912..5646ebb93 100644 --- a/operator/config/crd/bases/forklift.konveyor.io_migrations.yaml +++ b/operator/config/crd/bases/forklift.konveyor.io_migrations.yaml @@ -508,6 +508,10 @@ spec: restorePowerState: description: Source VM power state before migration. type: string + rootDisk: + description: Choose the primary disk the VM boots from + format: int32 + type: integer started: description: Started timestamp. format: date-time diff --git a/operator/config/crd/bases/forklift.konveyor.io_plans.yaml b/operator/config/crd/bases/forklift.konveyor.io_plans.yaml index b4d776e18..4d7b4d308 100644 --- a/operator/config/crd/bases/forklift.konveyor.io_plans.yaml +++ b/operator/config/crd/bases/forklift.konveyor.io_plans.yaml @@ -1012,6 +1012,10 @@ spec: restorePowerState: description: Source VM power state before migration. type: string + rootDisk: + description: Choose the primary disk the VM boots from + format: int32 + type: integer started: description: Started timestamp. format: date-time diff --git a/pkg/apis/forklift/v1beta1/plan/vm.go b/pkg/apis/forklift/v1beta1/plan/vm.go index 627962194..0069eb409 100644 --- a/pkg/apis/forklift/v1beta1/plan/vm.go +++ b/pkg/apis/forklift/v1beta1/plan/vm.go @@ -66,7 +66,8 @@ type VMStatus struct { Firmware string `json:"firmware,omitempty"` // The Operating System detected by virt-v2v. OperatingSystem string `json:"operatingSystem,omitempty"` - + //Choose the primary disk the VM boots from + RootDisk int32 `json:"rootDisk,omitempty"` // Conditions. libcnd.Conditions `json:",inline"` } diff --git a/pkg/controller/plan/kubevirt.go b/pkg/controller/plan/kubevirt.go index a56a77650..8171df156 100644 --- a/pkg/controller/plan/kubevirt.go +++ b/pkg/controller/plan/kubevirt.go @@ -38,6 +38,7 @@ 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" @@ -1608,6 +1609,30 @@ func (r *KubeVirt) guestConversionPod(vm *plan.VMStatus, vmVolumes []cnv.Volume, if err != nil { 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()) + 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 rootDisk != "" { + environment = append(environment, + core.EnvVar{ + Name: "V2V_RootDisk", + Value: rootDisk, + }) + } + } // pod annotations annotations := map[string]string{} if r.Plan.Spec.TransferNetwork != nil { diff --git a/pkg/controller/provider/container/vsphere/model.go b/pkg/controller/provider/container/vsphere/model.go index e388db637..075b576db 100644 --- a/pkg/controller/provider/container/vsphere/model.go +++ b/pkg/controller/provider/container/vsphere/model.go @@ -701,6 +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 for _, dev := range devArray.VirtualDevice { switch dev.(type) { case *types.VirtualDisk: @@ -712,6 +713,7 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) { File: backing.FileName, Capacity: disk.CapacityInBytes, Mode: backing.DiskMode, + Number: diskNum, } if backing.Datastore != nil { datastoreId, _ := sanitize(backing.Datastore.Value) @@ -721,6 +723,7 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) { } } disks = append(disks, md) + diskNum++ case *types.VirtualDiskFlatVer2BackingInfo: md := model.Disk{ Key: disk.Key, @@ -728,6 +731,7 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) { Capacity: disk.CapacityInBytes, Shared: backing.Sharing != "sharingNone", Mode: backing.DiskMode, + Number: diskNum, } if backing.Datastore != nil { datastoreId, _ := sanitize(backing.Datastore.Value) @@ -737,6 +741,7 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) { } } disks = append(disks, md) + diskNum++ case *types.VirtualDiskRawDiskMappingVer1BackingInfo: md := model.Disk{ Key: disk.Key, @@ -745,6 +750,7 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) { Shared: backing.Sharing != "sharingNone", Mode: backing.DiskMode, RDM: true, + Number: diskNum, } if backing.Datastore != nil { datastoreId, _ := sanitize(backing.Datastore.Value) @@ -754,6 +760,7 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) { } } disks = append(disks, md) + diskNum++ case *types.VirtualDiskRawDiskVer2BackingInfo: md := model.Disk{ Key: disk.Key, @@ -761,8 +768,10 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) { Capacity: disk.CapacityInBytes, Shared: backing.Sharing != "sharingNone", RDM: true, + Number: diskNum, } disks = append(disks, md) + diskNum++ } } } diff --git a/pkg/controller/provider/model/vsphere/model.go b/pkg/controller/provider/model/vsphere/model.go index 0fb0cdbe6..649d6ed2a 100644 --- a/pkg/controller/provider/model/vsphere/model.go +++ b/pkg/controller/provider/model/vsphere/model.go @@ -279,6 +279,7 @@ type Disk struct { Shared bool `json:"shared"` RDM bool `json:"rdm"` Mode string `json:"mode,omitempty"` + Number int32 `json:"number,omitempty"` } // Virtual Device. diff --git a/virt-v2v/cold/entrypoint.go b/virt-v2v/cold/entrypoint.go index 412fc9f5a..46a162b8e 100644 --- a/virt-v2v/cold/entrypoint.go +++ b/virt-v2v/cold/entrypoint.go @@ -99,7 +99,12 @@ func buildCommand() []string { fmt.Println("Preparing virt-v2v") switch source { case vSphere: - virtV2vArgs = append(virtV2vArgs, "--root", "first", "-i", "libvirt", "-ic", os.Getenv("V2V_libvirtURL")) + 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")) }