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:
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?
> 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