diff --git a/operator/config/crd/bases/forklift.konveyor.io_migrations.yaml b/operator/config/crd/bases/forklift.konveyor.io_migrations.yaml index 49558a062..b3bd8956b 100644 --- a/operator/config/crd/bases/forklift.konveyor.io_migrations.yaml +++ b/operator/config/crd/bases/forklift.konveyor.io_migrations.yaml @@ -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 diff --git a/operator/config/crd/bases/forklift.konveyor.io_plans.yaml b/operator/config/crd/bases/forklift.konveyor.io_plans.yaml index 1805454ec..40b032f2a 100644 --- a/operator/config/crd/bases/forklift.konveyor.io_plans.yaml +++ b/operator/config/crd/bases/forklift.konveyor.io_plans.yaml @@ -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 diff --git a/pkg/apis/forklift/v1beta1/plan/vm.go b/pkg/apis/forklift/v1beta1/plan/vm.go index 304bf6684..c1b04df1d 100644 --- a/pkg/apis/forklift/v1beta1/plan/vm.go +++ b/pkg/apis/forklift/v1beta1/plan/vm.go @@ -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"` } diff --git a/pkg/controller/plan/adapter/vsphere/builder.go b/pkg/controller/plan/adapter/vsphere/builder.go index b8f8a4483..22f90ed7e 100644 --- a/pkg/controller/plan/adapter/vsphere/builder.go +++ b/pkg/controller/plan/adapter/vsphere/builder.go @@ -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" @@ -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) @@ -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 @@ -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) @@ -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) } diff --git a/pkg/controller/plan/kubevirt.go b/pkg/controller/plan/kubevirt.go index 34f87343a..3248d66a3 100644 --- a/pkg/controller/plan/kubevirt.go +++ b/pkg/controller/plan/kubevirt.go @@ -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" @@ -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, }) } } diff --git a/pkg/controller/provider/container/vsphere/model.go b/pkg/controller/provider/container/vsphere/model.go index 075b576db..a1d915dfb 100644 --- a/pkg/controller/provider/container/vsphere/model.go +++ b/pkg/controller/provider/container/vsphere/model.go @@ -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: @@ -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) @@ -723,7 +723,7 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) { } } disks = append(disks, md) - diskNum++ + //diskNum++ case *types.VirtualDiskFlatVer2BackingInfo: md := model.Disk{ Key: disk.Key, @@ -731,7 +731,7 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) { Capacity: disk.CapacityInBytes, Shared: backing.Sharing != "sharingNone", Mode: backing.DiskMode, - Number: diskNum, + //Number: diskNum, } if backing.Datastore != nil { datastoreId, _ := sanitize(backing.Datastore.Value) @@ -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, @@ -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) @@ -760,7 +760,7 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) { } } disks = append(disks, md) - diskNum++ + //diskNum++ case *types.VirtualDiskRawDiskVer2BackingInfo: md := model.Disk{ Key: disk.Key, @@ -768,10 +768,10 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) { Capacity: disk.CapacityInBytes, Shared: backing.Sharing != "sharingNone", RDM: true, - Number: diskNum, + //Number: diskNum, } disks = append(disks, md) - diskNum++ + //diskNum++ } } } diff --git a/pkg/controller/provider/model/vsphere/model.go b/pkg/controller/provider/model/vsphere/model.go index 649d6ed2a..c33f4cdb0 100644 --- a/pkg/controller/provider/model/vsphere/model.go +++ b/pkg/controller/provider/model/vsphere/model.go @@ -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. diff --git a/virt-v2v/cold/entrypoint.go b/virt-v2v/cold/entrypoint.go index abb312760..e3844637b 100644 --- a/virt-v2v/cold/entrypoint.go +++ b/virt-v2v/cold/entrypoint.go @@ -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"))