Skip to content

Commit 3c1f121

Browse files
committed
fix kubev2v#437: Post VMs with desired 'Running' state
Long time ago, we posted VMs at the beginning of the migration and then started and stopped them during the migration and therefore in order to restore their original power state, we had to initiate another call to patch the VM with its desired power state. However, now that we post the VMs at the very last steps of the migration, we can set their desired power state in their specification and avoid another call to the target environment. Signed-off-by: Arik Hadas <ahadas@redhat.com>
1 parent a5c5400 commit 3c1f121

File tree

2 files changed

+2
-54
lines changed

2 files changed

+2
-54
lines changed

pkg/controller/plan/kubevirt.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -427,18 +427,6 @@ func (r *KubeVirt) DeleteVM(vm *plan.VMStatus) (err error) {
427427
return
428428
}
429429

430-
// Set the Running state on a Kubevirt VirtualMachine.
431-
func (r *KubeVirt) SetRunning(vmCr *VirtualMachine, running bool) (err error) {
432-
vmCopy := vmCr.VirtualMachine.DeepCopy()
433-
vmCr.VirtualMachine.Spec.Running = &running
434-
patch := client.MergeFrom(vmCopy)
435-
err = r.Destination.Client.Patch(context.TODO(), vmCr.VirtualMachine, patch)
436-
if err != nil {
437-
err = liberr.Wrap(err)
438-
}
439-
return
440-
}
441-
442430
func (r *KubeVirt) DataVolumes(vm *plan.VMStatus) (dataVolumes []cdi.DataVolume, err error) {
443431
secret, err := r.ensureSecret(vm.Ref, r.secretDataSetterForCDI(vm.Ref))
444432
if err != nil {
@@ -1006,7 +994,8 @@ func (r *KubeVirt) virtualMachine(vm *plan.VMStatus) (object *cnv.VirtualMachine
1006994
object.ObjectMeta.Annotations = annotations
1007995
}
1008996

1009-
running := false
997+
// Power on the destination VM if the source VM was originally powered on.
998+
running := vm.RestorePowerState == On
1010999
object.Spec.Running = &running
10111000

10121001
err = r.Builder.VirtualMachine(vm.Ref, &object.Spec, pvcs)

pkg/controller/plan/migration.go

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,15 +1052,6 @@ func (r *Migration) execute(vm *plan.VMStatus) (err error) {
10521052
Durable: true,
10531053
})
10541054

1055-
// Power on the destination VM if the source VM was originally powered on.
1056-
err = r.setRunning(vm, vm.RestorePowerState == On)
1057-
if err != nil {
1058-
r.Log.Error(err,
1059-
"Could not power on destination VM.",
1060-
"vm",
1061-
vm.String())
1062-
err = nil
1063-
}
10641055
} else if vm.Error != nil {
10651056
vm.Phase = Completed
10661057
vm.SetCondition(
@@ -1317,38 +1308,6 @@ func (r *Migration) ensureGuestConversionPod(vm *plan.VMStatus) (err error) {
13171308
return
13181309
}
13191310

1320-
// Set the running state of the kubevirt VM.
1321-
func (r *Migration) setRunning(vm *plan.VMStatus, running bool) (err error) {
1322-
if r.vmMap == nil {
1323-
r.vmMap, err = r.kubevirt.VirtualMachineMap()
1324-
if err != nil {
1325-
return
1326-
}
1327-
}
1328-
var vmCr VirtualMachine
1329-
found := false
1330-
if vmCr, found = r.vmMap[vm.ID]; !found {
1331-
// Recreate the map and check again, the map may be stale
1332-
r.vmMap, err = r.kubevirt.VirtualMachineMap()
1333-
if err != nil {
1334-
return
1335-
}
1336-
1337-
if vmCr, found = r.vmMap[vm.ID]; !found {
1338-
msg := "VirtualMachine CR not found."
1339-
vm.AddError(msg)
1340-
return
1341-
}
1342-
}
1343-
1344-
if vmCr.Spec.Running != nil && *vmCr.Spec.Running == running {
1345-
return
1346-
}
1347-
1348-
err = r.kubevirt.SetRunning(&vmCr, running)
1349-
return
1350-
}
1351-
13521311
// Update the progress of the appropriate disk copy step. (DiskTransfer, Cutover)
13531312
func (r *Migration) updateCopyProgress(vm *plan.VMStatus, step *plan.Step) (err error) {
13541313
var pendingReason string

0 commit comments

Comments
 (0)