From 26af1dafe50407773a34eaa38ef301caa292ccc0 Mon Sep 17 00:00:00 2001 From: Andrei Kvapil Date: Tue, 1 Dec 2026 13:50:07 +0100 Subject: [PATCH] fix(vm-instance): render empty disk lists as arrays A VMInstance with no disks and no cloud-init rendered `disks:` and `volumes:` as null, and the KubeVirt webhook refused the VirtualMachine because both fields must be arrays. Assisted-by: LLM Signed-off-by: Andrei Kvapil --- packages/apps/vm-instance/templates/vm.yaml | 4 +-- .../tests/disk_boot_order_test.yaml | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/packages/apps/vm-instance/templates/vm.yaml b/packages/apps/vm-instance/templates/vm.yaml index d7288a61e..e3682e3c5 100644 --- a/packages/apps/vm-instance/templates/vm.yaml +++ b/packages/apps/vm-instance/templates/vm.yaml @@ -116,7 +116,7 @@ spec: deviceName: {{ $gpu.name }} {{- end }} {{- end }} - disks: + disks:{{ if not (or .Values.disks .Values.cloudInit .Values.sshKeys .Values.netplanDhcp) }} []{{ end }} {{- /* KubeVirt rejects two devices sharing a bootOrder, so a clash is reported here with the disk names rather than surfacing as a webhook denial on the VirtualMachine. */}} @@ -172,7 +172,7 @@ spec: {{- include "virtual-machine.nodeAffinity" . | nindent 6 }} - volumes: + volumes:{{ if not (or .Values.disks .Values.cloudInit .Values.sshKeys .Values.netplanDhcp) }} []{{ end }} {{- range .Values.disks }} - name: disk-{{ .name }} dataVolume: diff --git a/packages/apps/vm-instance/tests/disk_boot_order_test.yaml b/packages/apps/vm-instance/tests/disk_boot_order_test.yaml index 146cbaf53..ee4eee320 100644 --- a/packages/apps/vm-instance/tests/disk_boot_order_test.yaml +++ b/packages/apps/vm-instance/tests/disk_boot_order_test.yaml @@ -126,3 +126,30 @@ tests: asserts: - failedTemplate: errorPattern: "minimum" + + # KubeVirt's schema wants arrays here; an empty block renders as null and + # the VirtualMachine is refused ("must be of type array"). + - it: renders an empty disk and volume list for a VM without disks + set: + disks: [] + asserts: + - equal: + path: spec.template.spec.domain.devices.disks + value: [] + - equal: + path: spec.template.spec.volumes + value: [] + + - it: keeps only the cloud-init disk for a VM without disks but with cloud-init + set: + disks: [] + cloudInit: "#cloud-config" + asserts: + - equal: + path: spec.template.spec.domain.devices.disks + value: + - name: cloudinitdisk + disk: {} + - lengthEqual: + path: spec.template.spec.volumes + count: 1