Skip to content

Commit 0f3d2fa

Browse files
fix(vm-instance): emit empty disk object so KubeVirt accepts disks without bus
When a disk entry has no bus set (the schema default), the previous template rendered `disk:` with no value — YAML parses that as `disk: null` and KubeVirt's virtualmachines-mutator webhook denies the request with: "spec.template.spec.domain.devices.disks.disk in body must be of type object: null". Restructure the disk loop so the disk/cdrom value is always a valid object: `disk: {}` when bus is empty, `disk: {bus: <x>}` when set. Mirrors how `cloudinitdisk` already does it in the same template. Signed-off-by: Myasnikov Daniil <[email protected]>
1 parent 70693ff commit 0f3d2fa

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

  • packages/apps/vm-instance/templates

‎packages/apps/vm-instance/templates/vm.yaml‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ spec:
6767
- name: disk-{{ $disk.name }}
6868
{{- $dv := lookup "cdi.kubevirt.io/v1beta1" "DataVolume" $.Release.Namespace (printf "vm-disk-%s" $disk.name) }}
6969
{{- if $dv }}
70-
{{- if and (hasKey $dv.metadata.annotations "vm-disk.cozystack.io/optical") (eq (index $dv.metadata.annotations "vm-disk.cozystack.io/optical") "true") }}
71-
cdrom:
70+
{{- $isOptical := and (hasKey $dv.metadata.annotations "vm-disk.cozystack.io/optical") (eq (index $dv.metadata.annotations "vm-disk.cozystack.io/optical") "true") }}
71+
{{- $deviceKey := ternary "cdrom" "disk" $isOptical }}
72+
{{- if $disk.bus }}
73+
{{ $deviceKey }}:
74+
bus: {{ $disk.bus }}
7275
{{- else }}
73-
disk:
76+
{{ $deviceKey }}: {}
7477
{{- end }}
75-
{{- with $disk.bus }}
76-
bus: {{ . }}
77-
{{- end }}
7878
bootOrder: {{ add $i 1 }}
7979
{{- else }}
8080
{{- fail (printf "Specified disk not exists in cluster: %s" .name) }}

0 commit comments

Comments
 (0)