Bug 2222978 - VM Cloning does not verify if the target VM already exists
Summary: VM Cloning does not verify if the target VM already exists
Keywords:
Status: NEW
Alias: None
Product: Container Native Virtualization (CNV)
Classification: Red Hat
Component: Virtualization
Version: 4.14.0
Hardware: Unspecified
OS: Unspecified
high
high
Target Milestone: ---
: 4.15.0
Assignee: Itamar Holder
QA Contact: Kedar Bidarkar
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-07-14 17:05 UTC by Denys Shchedrivyi
Modified: 2023-08-02 13:01 UTC (History)
0 users

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed:
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker CNV-30975 0 None None None 2023-07-14 17:05:52 UTC

Description Denys Shchedrivyi 2023-07-14 17:05:34 UTC
Description of problem:
 Currently, vm cloning job does not verify if the target VM already exists on a cluster. 

> $ oc get vm
> NAME         AGE   STATUS    READY
> vm-fedora    17m   Running   True
> vm-fedora2   13m   Running   True


VirtualMachineClone stuck in `VirtualMachineClone` phase:

> $ oc get vmclone
> NAME                   PHASE               SOURCEVIRTUALMACHINE   TARGETVIRTUALMACHINE
> clone-to-existing-vm   RestoreInProgress   vm-fedora              vm-fedora2

>   Normal  SnapshotCreated  5m30s  clone-controller  created snapshot clone-clone-to-existing-vm-snapshot-vm-fedora-m2grh for clone clone-to-existing-vm
>   Normal  SnapshotReady    5m28s  clone-controller  snapshot clone-clone-to-existing-vm-snapshot-vm-fedora-m2grh for clone clone-to-existing-vm is ready to use


 Also, it is possible to create cloning job with the same source/target VM:

> $ oc get vmclone
> NAME                   PHASE               SOURCEVIRTUALMACHINE   TARGETVIRTUALMACHINE
> clone-to-itself        RestoreInProgress   vm-fedora              vm-fedora



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

How reproducible:
100%

Steps to Reproduce:
1. create 2 VMs
2. try to clone the first VM with the target pointed to second VM
3.

Actual results:
 VirtualMachineClone created and stuck in `VirtualMachineClone` phase


Expected results:
 Seems, we need to have a validation and prevent creation of vmclone jobs if the target already exists

Additional info:

Comment 1 sgott 2023-07-19 12:32:28 UTC
I'm just not convinced this is a bug. Here's my rationale. If you created two VMs with the same name, wouldn't the same thing happen?

a VM clone job is not an atomic operation. Deciding whether or not to create a job isn't going to solve this. We'll still get into the same situation sometimes. Picture these events in rapid succession:

1) VM clone is created. Check for name passes. clone can proceed.
2) VM with conflicting name is created.
3) clone job gets stuck.

----------

Because k8s is eventually consistent and declarative, this situation seems ok. If you delete the VM that has the problematic name, would the clone then succeed?

What do you think Denys?

Comment 2 Denys Shchedrivyi 2023-07-20 18:46:37 UTC
> Because k8s is eventually consistent and declarative, this situation seems ok. If you delete the VM that has the problematic name, would the clone then succeed?
Yes, when the VM with target name deleted - the new VM automatically created:

$ oc get vm --watch
NAME         AGE   STATUS    READY
vm-fedora    75s   Running   True
vm-fedora2   70s   Running   True
vm-fedora2   93s   Terminating   True
vm-fedora2   93s   Terminating   False
vm-fedora2   0s                  
vm-fedora2   0s    Stopped       False

 

 I would agree - it probably can be considered as not_a_bug, however may be we have some options for improvements. Couple comments:

1) the VirtualMachineClone status is a bit confusing - it says `RestoreInProgress`, however no any real restoring in process.
May be we can add some event message in vmclone object says that the VM with target name already exists?

2) allow vmclone with same source/target names seems weird, it will not be completed, but will keep the snapshot while vmclone job exists

3) not sure how harmful it is, but if the vmclone job stuck (or failed) - it keeps the source vmsnapshot even if all VMs deleted:

$ oc get vm
No resources found in test-clone namespace.

$ oc get vmclone
NAME                   PHASE    SOURCEVIRTUALMACHINE   TARGETVIRTUALMACHINE
clone-to-existing-vm   Failed   vm-fedora-pvc          vm-fedora2

$ oc get vmsnapshot
NAME                                                      SOURCEKIND       SOURCENAME      PHASE       READYTOUSE   CREATIONTIME   ERROR
clone-clone-to-existing-vm-snapshot-vm-fedora-pvc-s57kb   VirtualMachine   vm-fedora-pvc   Succeeded   true         7m13s


Note You need to log in before you can comment on or make changes to this bug.