Bug 1719190

Summary: Unable to cancel live-migration if virt-launcher pod in pending state
Product: Container Native Virtualization (CNV) Reporter: Asher Shoshan <ashoshan>
Component: VirtualizationAssignee: Itamar Holder <iholder>
Status: CLOSED ERRATA QA Contact: Akriti Gupta <akrgupta>
Severity: medium Docs Contact:
Priority: medium    
Version: 2.0CC: acardace, awax, dshchedr, fdeutsch, gouyang, kbidarka, sgott, vromanso
Target Milestone: ---   
Target Release: 4.12.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: hco-bundle-registry-container-v4.12.0-308 virt-handler-4.12.0-110 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-01-24 13:36:05 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Asher Shoshan 2019-06-11 09:32:42 UTC
Description of problem:
After starting a live-migration and if the process has not been started due to new node availability (virt-launcher pod in 'pending' state), then trying to cancel the live-migration (delete the resource VirtualMachineInstanceMigration kind) hangs forever.

Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:
1. oc adm cordon <all-nodes-except-the-vmi-running-node>
2. start a live-migration (oc create -f vmim.yaml...)
3. watch a new pod virt-launcher is created and in 'pending' state
4. try delete the vmim cr (oc delete vmim...)

Actual results:
step 4 above hangs forever

Expected results:
live-migration to be cancelled 


Additional info:
The way to mitigate this is to first delete the pod then delete the vmim cr.

Comment 3 sgott 2020-03-16 17:21:35 UTC
*** Bug 1812775 has been marked as a duplicate of this bug. ***

Comment 5 sgott 2020-05-13 18:02:32 UTC
I did some digging into this, as well as talked it over with Vladik. This is a bit tricky to solve, but it might be possible. The issue we'd like to avoid is a race condition. The basic (successful) workflow is this:

1) a VMI is running
2) a VMI migration object is created
3) migration controller schedules a pod on a target node
4) once that pod is running, the migration controller will coordinate handoff between the virt-handlers of the respective nodes

The breakdown here is with step 3. The controller has no way of differentiating between a pod that can't be scheduled due to cluster constraints (e.g. no nodes available) and a pod that is in the process of being scheduled and is about to run. The scenario that we'd like to avoid is to have a zombie virt-launcher pod that's running on a node, but no entity is responsible for it. This could happen if e.g. the migration object were deleted as the pod was being scheduled--there would be no VMI representing the pod, so virt-handler on that node would not recognize it.

Currently KubeVirt has a finalizer that forbids migrations be deleted if they're not in a final state. This normally works fine, but in a case like the scenario in this BZ, the migration can't enter a final state because the destination pod is waiting to be scheduled.

While we work on the best path forward, there does exist a workaround. Delete the target virt-launcher pod. the VMI Migration object will immediately enter the "failed" state. This meets the criterion of the finalizer, and the cluster will allow the migration object to be deleted.

In order to ensure you delete the correct pod, there is an activePods stanza in the VMI's status. This is a mapping of pod's UID to node. the one with an empty node is the UID of interest (since that's the one not scheduled). The pod with the name "virt-launcher-XXXX" that is in a pending state with that UID is the target pod.

Because there exists a workaround, and there is no danger of data loss with this workflow, I'm lowering the severity of this BZ to medium.

Comment 10 sgott 2022-01-28 22:22:52 UTC
*** Bug 2035924 has been marked as a duplicate of this bug. ***

Comment 11 Roman Mohr 2022-03-09 13:33:36 UTC
Since 2020 a lot has changed. If we still see migrations hanging when the new target pod is in pending state, we should be able properly abort nowadays. Let's check this out again. Properly setting the abort request on the VMI by the migration controller should give the source virt-handler and virt-controller all the info needed to abort in this stage in a race-free way. It can of course still happen that a migration can't be aborted anymore and still succeeds, but that is logically fine.

Comment 12 Itamar Holder 2022-04-20 13:56:53 UTC
PR: https://github.com/kubevirt/kubevirt/pull/7599

Comment 18 Akriti Gupta 2022-10-10 09:07:36 UTC
verified with cnv v4.12.0-548, virt-handler v4.12.0-201

[akrgupta@fedora ~]$ oc get vmi
NAME         AGE   PHASE     IP             NODENAME                            READY
vm-example   29s   Running   10.128.2.177   virt-den-412-pqfpv-worker-0-mjg69   True
[akrgupta@fedora ~]$ oc adm cordon virt-den-412-pqfpv-worker-0-bg7n4 virt-den-412-pqfpv-worker-0-4tgwh
node/virt-den-412-pqfpv-worker-0-bg7n4 cordoned
node/virt-den-412-pqfpv-worker-0-4tgwh cordoned
[akrgupta@fedora ~]$ virtctl migrate vm-example
VM vm-example was scheduled to migrate
[akrgupta@fedora ~]$ oc get vmim
NAME                        PHASE        VMI
kubevirt-migrate-vm-n4dc2   Scheduling   vm-example
[akrgupta@fedora ~]$ oc get pods
NAME                             READY   STATUS    RESTARTS   AGE
virt-launcher-vm-example-dp55v   0/2     Pending   0          102s
virt-launcher-vm-example-wwznb   2/2     Running   0          6m41s
[akrgupta@fedora ~]$ oc get vmim
NAME                        PHASE        VMI
kubevirt-migrate-vm-n4dc2   Scheduling   vm-example
[akrgupta@fedora ~]$ oc delete vmim kubevirt-migrate-vm-n4dc2
virtualmachineinstancemigration.kubevirt.io "kubevirt-migrate-vm-n4dc2" deleted
[akrgupta@fedora ~]$ oc get vmim
No resources found in default namespace.
[akrgupta@fedora ~]$ oc get vmi
NAME         AGE   PHASE     IP             NODENAME                            READY
vm-example   10m   Running   10.128.2.177   virt-den-412-pqfpv-worker-0-mjg69   True

able to cancel live-migration if virt-launcher pod in pending state , by deleting the vmim object

Comment 21 errata-xmlrpc 2023-01-24 13:36:05 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Important: OpenShift Virtualization 4.12.0 Images security update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2023:0408