Skip to content

Commit

Permalink
Add support for users to specify rootDisk in multiboot VM.
Browse files Browse the repository at this point in the history
Signed-off-by: Bella Khizgiyaev <[email protected]>
  • Loading branch information
bkhizgiy committed Jun 19, 2024
1 parent e722c42 commit 544e2d8
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions operator/config/crd/bases/forklift.konveyor.io_plans.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/forklift/v1beta1/plan/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down
25 changes: 25 additions & 0 deletions pkg/controller/plan/kubevirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1607,6 +1608,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 {
Expand Down
9 changes: 9 additions & 0 deletions pkg/controller/provider/container/vsphere/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -721,13 +723,15 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) {
}
}
disks = append(disks, md)
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,
}
if backing.Datastore != nil {
datastoreId, _ := sanitize(backing.Datastore.Value)
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -754,15 +760,18 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) {
}
}
disks = append(disks, md)
diskNum++
case *types.VirtualDiskRawDiskVer2BackingInfo:
md := model.Disk{
Key: disk.Key,
File: backing.DescriptorFileName,
Capacity: disk.CapacityInBytes,
Shared: backing.Sharing != "sharingNone",
RDM: true,
Number: diskNum,
}
disks = append(disks, md)
diskNum++
}
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/provider/model/vsphere/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion virt-v2v/cold/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,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"))
}
Expand Down

0 comments on commit 544e2d8

Please sign in to comment.