diff --git a/pkg/controller/plan/kubevirt.go b/pkg/controller/plan/kubevirt.go index 22dbf9784..72f9c367c 100644 --- a/pkg/controller/plan/kubevirt.go +++ b/pkg/controller/plan/kubevirt.go @@ -464,18 +464,6 @@ func (r *KubeVirt) DeleteVM(vm *plan.VMStatus) (err error) { return } -// Set the Running state on a Kubevirt VirtualMachine. -func (r *KubeVirt) SetRunning(vmCr *VirtualMachine, running bool) (err error) { - vmCopy := vmCr.VirtualMachine.DeepCopy() - vmCr.VirtualMachine.Spec.Running = &running - patch := client.MergeFrom(vmCopy) - err = r.Destination.Client.Patch(context.TODO(), vmCr.VirtualMachine, patch) - if err != nil { - err = liberr.Wrap(err) - } - return -} - func (r *KubeVirt) DataVolumes(vm *plan.VMStatus) (dataVolumes []cdi.DataVolume, err error) { secret, err := r.ensureSecret(vm.Ref, r.secretDataSetterForCDI(vm.Ref)) if err != nil { @@ -1091,7 +1079,8 @@ func (r *KubeVirt) virtualMachine(vm *plan.VMStatus) (object *cnv.VirtualMachine object.ObjectMeta.Annotations = annotations } - running := false + // Power on the destination VM if the source VM was originally powered on. + running := vm.RestorePowerState == On object.Spec.Running = &running err = r.Builder.VirtualMachine(vm.Ref, &object.Spec, pvcs) diff --git a/pkg/controller/plan/migration.go b/pkg/controller/plan/migration.go index 66c550c5d..0e9506bb4 100644 --- a/pkg/controller/plan/migration.go +++ b/pkg/controller/plan/migration.go @@ -1066,15 +1066,6 @@ func (r *Migration) execute(vm *plan.VMStatus) (err error) { Durable: true, }) - // Power on the destination VM if the source VM was originally powered on. - err = r.setRunning(vm, vm.RestorePowerState == On) - if err != nil { - r.Log.Error(err, - "Could not power on destination VM.", - "vm", - vm.String()) - err = nil - } } else if vm.Error != nil { vm.Phase = Completed vm.SetCondition( @@ -1331,38 +1322,6 @@ func (r *Migration) ensureGuestConversionPod(vm *plan.VMStatus) (err error) { return } -// Set the running state of the kubevirt VM. -func (r *Migration) setRunning(vm *plan.VMStatus, running bool) (err error) { - if r.vmMap == nil { - r.vmMap, err = r.kubevirt.VirtualMachineMap() - if err != nil { - return - } - } - var vmCr VirtualMachine - found := false - if vmCr, found = r.vmMap[vm.ID]; !found { - // Recreate the map and check again, the map may be stale - r.vmMap, err = r.kubevirt.VirtualMachineMap() - if err != nil { - return - } - - if vmCr, found = r.vmMap[vm.ID]; !found { - msg := "VirtualMachine CR not found." - vm.AddError(msg) - return - } - } - - if vmCr.Spec.Running != nil && *vmCr.Spec.Running == running { - return - } - - err = r.kubevirt.SetRunning(&vmCr, running) - return -} - // Update the progress of the appropriate disk copy step. (DiskTransfer, Cutover) func (r *Migration) updateCopyProgress(vm *plan.VMStatus, step *plan.Step) (err error) { var pendingReason string