Bug 1835426 - [RFE] Provide a clear error message when VM and VMI name does not match
Summary: [RFE] Provide a clear error message when VM and VMI name does not match
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Container Native Virtualization (CNV)
Classification: Red Hat
Component: Virtualization
Version: 2.3.0
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: ---
: 2.4.0
Assignee: Roman Mohr
QA Contact: zhe peng
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2020-05-13 18:30 UTC by David Critch
Modified: 2020-07-28 19:10 UTC (History)
7 users (show)

Fixed In Version: virt-operator-container-v2.4.0-52 hco-bundle-registry-container-v2.3.0-429
Doc Type: Bug Fix
Doc Text:
If the name for a VMI is specified in the VMI template of the VM, it is correctly ignored now. The VM and VMI name will always match.
Clone Of:
Environment:
Last Closed: 2020-07-28 19:10:07 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github kubevirt kubevirt pull 3436 0 None closed Fix name handling of VMIs in VM templates 2020-12-16 22:00:56 UTC
Github kubevirt kubevirt pull 3643 0 None closed [release-0.30] Fix name handling of VMIs in VM templates 2020-12-16 22:00:56 UTC
Red Hat Product Errata RHSA-2020:3194 0 None None None 2020-07-28 19:10:18 UTC

Description David Critch 2020-05-13 18:30:55 UTC
Description of problem:
If the name in the top-level metadata section of a VirtualMachine definition does not match the name defined in the metadata of the 'template' section of the definition, both a VM and VMI will be created but with different names. 

This prevents the controller from reconciling the VM to the running VMI. The VM will be stuck in a pending state, even though the VMI is fine.



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

How reproducible:
Always

Steps to Reproduce:
1. Create a template where the metadata's do not match:

apiVersion: kubevirt.io/v1alpha3
kind: VirtualMachine
metadata:
  name: myfriendlyvmname
spec:
<...>
  running: true
  template:
    metadata:
      name: someothevmname
    spec:
      domain:
        resources:
<...>
2. oc create -f <vm file>


Actual results:
oc get vm reports:

  Warning  FailedCreate                41s (x17 over 61s)  virtualmachine-controller  Error creating virtual machine instance: The POST operation against VirtualMachineInstance.kubevirt.io could not be completed at this time, please try again.

The virt-controller logs show its confusion:

{"component":"virt-controller","kind":"","level":"info","msg":"Failed to create VirtualMachineInstance: /","name":"myfriendlyvmname","namespace":"default","pos":"vm.go:641","service":"http","timestamp":"2020-05-08T21:36:37.043785Z","uid":"bfde9daa-2bdf-44b6-bca3-9ad83fd9ab42"}
{"component":"virt-controller","kind":"","level":"error","msg":"Creating the VirtualMachine failed.","name":"myfriendlyvmname","namespace":"default","pos":"vm.go:265","service":"http","timestamp":"2020-05-08T21:36:37.043848Z","uid":"bfde9daa-2bdf-44b6-bca3-9ad83fd9ab42"}
{"component":"virt-controller","kind":"","level":"info","msg":"Reason to fail: FailedCreate","name":"myfriendlyvmname","namespace":"default","pos":"vm.go:1225","service":"http","timestamp":"2020-05-08T21:36:37.043887Z","uid":"bfde9daa-2bdf-44b6-bca3-9ad83fd9ab42"}
{"component":"virt-controller","level":"info","msg":"reenqueuing VirtualMachineInstance default/someothevmname","pos":"vmi.go:201","reason":"Operation cannot be fulfilled on virtualmachineinstances.kubevirt.io \"someothevmname\": the object has been modified; please apply your changes to the latest version and try again","service":"http","timestamp":"2020-05-08T21:36:37.058788Z"}
{"component":"virt-controller","level":"info","msg":"re-enqueuing VirtualMachine default/myfriendlyvmname","pos":"vm.go:143","reason":"The POST operation against VirtualMachineInstance.kubevirt.io could not be completed at this time, please try again.","service":"http","timestamp":"2020-05-08T21:36:37.061318Z"}
{"component":"virt-controller","level":"info","msg":"reenqueuing VirtualMachineInstance default/someothevmname","pos":"vmi.go:201","reason":"Operation cannot be fulfilled on virtualmachineinstances.kubevirt.io \"someothevmname\": the object has been modified; please apply your changes to the latest version and try again","service":"http","timestamp":"2020-05-08T21:36:37.067814Z"}


(note the different names)

The result is VM myfriendlyvmname is in a pending state, while VMI someothevmname is running fine.

Expected results:
VM resultant VMI are created and associated with each other

Additional info:

Not sure if this is a template validation issue, or a doc issue. Omitting a name in the metadata section of the VM template also works fine, since it must inherit from the top-level spec. It seems optional, put possible to override in the VM template and cause a bit of a split-brain.

Perhaps a name shouldn't be allowed in the VM template's metadata?

Comment 1 sgott 2020-05-13 19:35:29 UTC
I am able to reproduce this on both the CNV 2.3.0 code as well as the latest code on the master branch.

Everything does appear to be operating normally, however there is a Failure condition on the VM:

  status:
    conditions:
    - lastProbeTime: null
      lastTransitionTime: "2020-05-13T19:25:38Z"
      message: The POST operation against VirtualMachineInstance.kubevirt.io could
        not be completed at this time, please try again.
      reason: FailedCreate
      status: "True"
      type: Failure

Vatsal, would you mind taking a look at this? You recently touched the VM/VMI naming logic so might have some insights.

Comment 2 Omer Yahud 2020-05-19 14:32:40 UTC
Is this a special case we support (different names for parent VM and child VMI)?
If not, a validating webhook would solve the issue, or completely omitting the 'template.name` field and letting
a mutating webhook insert the parent VM to the 'template` section.

Comment 3 Kedar Bidarkar 2020-05-20 12:09:51 UTC
Roman has this PR for this, https://github.com/kubevirt/kubevirt/pull/3436

Comment 5 Roman Mohr 2020-06-24 12:33:18 UTC
Backport created: https://github.com/kubevirt/kubevirt/pull/3643

Comment 7 Roman Mohr 2020-06-25 08:17:07 UTC
PRs are merged.

The new behaviour is now consistend with Pod templates on other controllers like Deployments, ReplicaSets and with VMI templates on the VirtualMachineInstanceReplicaSet.

In all cases generateName and name are now ignored on the template.

Comment 8 sgott 2020-06-25 15:08:38 UTC
Fixed-in version was applied in error.

Comment 9 zhe peng 2020-07-09 05:29:00 UTC
I can reproduce this.
verify with build  virt-operator-container-v2.4.0-52

$ virtctl version
Server Version: version.Info{GitVersion:"v0.30.3", GitCommit:"bf49699ddf2639f5d40d8cff5db49be632a165bd", GitTreeState:"clean", BuildDate:"2020-07-01T01:28:15Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"

step:
create a vm like bug description, and start the vm
...
metadata:
  labels:
    kubevirt.io/vm: vm-cirros-nfs
  name: vm-cirros-nfs
spec:
  running: false
  template:
    metadata:
      name: someothervmname
      labels:
        kubevirt.io/vm: vm-cirros-nfs
...

check Virt-controller logs, there is no fail msg.
check vm status
$ oc get vmi
NAME            AGE     PHASE     IP            NODENAME
vm-cirros-nfs   8m14s   Running   10.131.0.35   zpeng-cnv24-jvfn5-worker-l7fmw

the name in template is ignored. move to verified.

Comment 10 Lavanya Mandavilli 2020-07-20 21:22:16 UTC
I have added a placeholder in the 2.4 release notes for this defect. Requested for doc text, in waiting mode. Thank.

Comment 11 Roman Mohr 2020-07-21 08:53:52 UTC
(In reply to Lavanya Mandavilli from comment #10)
> I have added a placeholder in the 2.4 release notes for this defect.
> Requested for doc text, in waiting mode. Thank.

You mean a release note that it is fixed?

How about:

```
If the name for a VMI is specified in the VMI template of the VM, it is correctly ignored now. The VM and VMI name will always match.
```

Comment 12 Lavanya Mandavilli 2020-07-21 15:49:47 UTC
@rmohr, @fabiand - This PR is ready for review:https://github.com/openshift/openshift-docs/pull/23994
Please add your edits/comments.

Comment 14 Lavanya Mandavilli 2020-07-27 19:25:17 UTC
Feedback from @rmohr was incorporated.

Comment 15 Lavanya Mandavilli 2020-07-27 19:28:06 UTC
Updating this defect. After conferring with @aburdenhand, it was noted that this defect was fixed - therefore, this does not fall into the classification of known issues. Removing this info from the Known Issues section of the release notes.

Comment 17 errata-xmlrpc 2020-07-28 19:10:07 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, 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-2020:3194


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