kubevirt: Can't add spec.nodeSelector in vmi object.

What happened: I want to select the target when migration vmi. Just like https://github.com/kubevirt/kubevirt/issues/7105 said, I try to edit or add spec.nodeSelector in VMI object, but update is restricted.

What you expected to happen: add or update spec.nodeSelector in VMI object succeed or someone can tell me how to select a target when migration vmi.

How to reproduce it (as minimally and precisely as possible): create a vm zal-cirros-vm

yaml

apiVersion: kubevirt.io/v1alpha3
kind: VirtualMachine
metadata:
  creationTimestamp: null
  labels:
    kubevirt.io/vm: vm-cirros-datavolume
  name: zal-cirros-vm
spec:
  running: false
  template:
    metadata:
      labels:
        kubevirt.io/vm: vm-datavolume
    spec:
      domain:
        devices:
          interfaces:
          - name: default
            masquerade: {}
          disks:
          - disk:
              bus: virtio
            name: datavolumevolume
        machine:
          type: ""
        resources:
          requests:
            memory: 64M
      terminationGracePeriodSeconds: 0
      volumes:
      - dataVolume:
          name: zal-upload-dv
        name: datavolumevolume
      networks:
      - name: default
        pod: {} # Stock pod network

virtctl start vm zal-cirros-vm

kubectl edit vmi zal-cirros-vm

just add spec.nodeSelector

image

but update is restricted

Additional context: I find some discussion may be related to my issue, https://github.com/kubevirt/kubevirt/pull/6550

Environment:

  • KubeVirt version (use virtctl version): N/A
  • Kubernetes version (use kubectl version): N/A
  • VM or VMI specifications: N/A
  • Cloud provider or hardware configuration: N/A
  • OS (e.g. from /etc/os-release): N/A
  • Kernel (e.g. uname -a): N/A
  • Install tools: N/A
  • Others: N/A

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 18 (18 by maintainers)

Most upvoted comments

BTW, I think we can bring this issue up for discussion in a google group or weekly meeting

Probably filling the design proposal is a good point to start implementing this feature

What I see here is that you define the VirtualMachine without any node selectors, and then attempt to update/patch the VirtualMachineInstance spec separately from the VirtualMachine spec.

Can you try updating/patching the VirtualMachine object instead of the VirtualMachineInstance object to add the nodeSelector? This should be allowable on the VirtualMachine object.

Note that you will still need to specifically start the vm migration after making the edit as there is no implied migration action from updating the nodeSelector field after pod scheduling.

I believe this should allow you to perform what you are attempting here.

Thank you for your tip, I think this method can only work to select the targe for the first time migration.

In my test, when I add nodeSelector on VirtualMachine and migrate vmi, the spec.nodeSelector will add on vmi. When this migration finished, I try to change the nodeSelector on VirtualMachine and start another migration. The new virt-launcher pod for the vmi can’t be scheduled successfully. The spec in this pod is generated from the old vmi while the spec.nodeSelector is also old. So I think the method you illustrated above can only work once. image

Also this issue https://github.com/kubevirt/kubevirt/pull/6550 may describe a similar problem, and I think kubevirt don’t think select targe for migration is a good idea. Therefor I want to confirm, are there any methods to select targe for migration with vmi running without code change rather than edit the code.