feat: support cdrom hotplug volume#153
Conversation
Signed-off-by: Tim Liou <tim.liou@suse.com>
Signed-off-by: Tim Liou <tim.liou@suse.com>
cdb6c3c to
4ff7305
Compare
Signed-off-by: Tim Liou <tim.liou@suse.com>
| }, | ||
| }, | ||
| }) | ||
| } |
There was a problem hiding this comment.
Although we got the "Complex Method" notice from CodeFactor, it's intentional to have TestAccVirtualMachine_hotplug_cdrom_volume perform
- create VM with empty cdrom
- create a VM image and insert it into the VM
- eject the media out of the VM
Therefore, I think we can ignore this warning from CodeFactor.
m-ildefons
left a comment
There was a problem hiding this comment.
LGTM, but I'd prefer if the "Complex Method" warning got fixed.
Signed-off-by: Tim Liou <tim.liou@suse.com>
Signed-off-by: Tim Liou <tim.liou@suse.com>
Signed-off-by: Tim Liou <tim.liou@suse.com>
Signed-off-by: Tim Liou <tim.liou@suse.com>
|
@m-ildefons sorry that I found that I tried it after the fix, it pass. Could you help me review it again? Thanks. |
brandboat
left a comment
There was a problem hiding this comment.
Overall LGTM, only have some questions.
Thanks for the thorough e2e test!
| if volume.Name != disk.Name { | ||
| continue | ||
| } |
There was a problem hiding this comment.
So this fixed the missing hotplug disk issue, right? The original behavior is iterating over volumes, and skip disk if its name not match the volume name. That could be a problem since hotplug empty cd-rom is not defined in the volume section.
There was a problem hiding this comment.
Exactly! This change is for empty cdrom.
| if oldFirmware := vmBuilder.VirtualMachine.Spec.Template.Spec.Domain.Firmware; oldFirmware != nil { | ||
| if firmware == nil { | ||
| firmware = &kubevirtv1.Firmware{} | ||
| } | ||
| firmware.UUID = oldFirmware.UUID | ||
| firmware.Serial = oldFirmware.Serial | ||
| } |
There was a problem hiding this comment.
could you please explain a bit more about this? Is this related to cdrom hotplug?
There was a problem hiding this comment.
This change is important for hotplug actions (not just for the cdrom hotplug but also for the existing hotplug volume). Without this change, the updated VM will have different firmware serial and uuid, causing the RestartRequired condition.
Take this example using binary from master branch (hotplug volume),
❯ cat main.tf
resource "harvester_volume" "mount-disk" {
name = "mount-disk"
namespace = "default"
size = "1Gi"
}
resource "harvester_virtualmachine" "fedora" {
name = "fedora"
namespace = "default"
cpu = 1
memory = "2Gi"
efi = true
secure_boot = true
hostname = "fedora"
network_interface {
name = "nic-1"
wait_for_lease = true
}
disk {
name = "rootdisk"
type = "disk"
bus = "virtio"
boot_order = 1
container_image_name = "kubevirt/fedora-cloud-container-disk-demo:v0.35.0"
}
# uncomment for the second terraform apply to do volume hotplug
# disk {
# name = "mount-disk"
# type = "disk"
# bus = "scsi"
#
# existing_volume_name = harvester_volume.mount-disk.name
# auto_delete = false
# hot_plug = true
# }
}
❯ terraform apply
❯ kubectl get vm fedora -o yaml > /tmp/first.yaml
/* edit main.tf to uncomment for the second terraform apply to do volume hotplug */
❯ terraform apply
❯ kubectl get vm fedora -o yaml > /tmp/second.yaml
❯ diff /tmp/first.yaml /tmp/second.yaml
6a7
> harvesterhci.io/volumeClaimTemplates: '[]'
13c14
< generation: 1
---
> generation: 3
19c20
< resourceVersion: "1157979"
---
> resourceVersion: "1161276"
26c27
< harvesterhci.io/sshNames: '[]'
---
> harvesterhci.io/sshNames: "null"
55a57,59
> - disk:
> bus: scsi
> name: mount-disk
69,70c73
< serial: 78ff9029-d200-4ed7-972f-8222e81d3de4
< uuid: 8c491cef-9ab6-4644-abe8-22876906a927
---
> uuid: 98f07cdd-96da-5880-b6c7-1a5700b73dc4
92a96,99
> - name: mount-disk
> persistentVolumeClaim:
> claimName: mount-disk
> hotpluggable: true
106a114,118
> - lastProbeTime: null
> lastTransitionTime: "2026-02-13T00:42:15Z"
> message: a non-live-updatable field was changed in the template spec
> status: "True"
> type: RestartRequired
108c120
< desiredGeneration: 1
---
> desiredGeneration: 3
116a129,130
> - enabled: true
> name: mount-disk
For cdrom hotplug, check the integration test.
This change fixed it by preserving the old firmware's uuid and serial.
Problem:
To support cdrom hotplug volume: image insertion and ejection.
Solution:
Related Issue(s):
harvester/harvester#9261
Test plan:
Check out integration test:
TestAccVirtualMachine_hotplug_cdrom_volume.Additional documentation or context
HEP: harvester/harvester#9840
BE: harvester/harvester#9937