From a56ef30df653d31b5c48c2ebaa7dfd9971d41e53 Mon Sep 17 00:00:00 2001 From: Kirill Ilin Date: Wed, 25 Mar 2026 09:56:29 +0500 Subject: [PATCH] [vm-instance] Fix review issues: validation, DRY, and regenerate CRD Add fail validation when both 'networks' and 'subnets' are set to prevent silent data loss during migration. Compute $networks variable once at template top level to eliminate DRY violation. Regenerate CRD via make generate instead of manual editing. Assisted-By: Claude AI Signed-off-by: Kirill Ilin --- packages/apps/vm-instance/README.md | 6 +++-- packages/apps/vm-instance/templates/vm.yaml | 6 +++-- packages/apps/vm-instance/values.schema.json | 28 ++++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/packages/apps/vm-instance/README.md b/packages/apps/vm-instance/README.md index 11d1441d..a2b6603e 100644 --- a/packages/apps/vm-instance/README.md +++ b/packages/apps/vm-instance/README.md @@ -47,8 +47,10 @@ virtctl ssh @ | `disks` | List of disks to attach. | `[]object` | `[]` | | `disks[i].name` | Disk name. | `string` | `""` | | `disks[i].bus` | Disk bus type (e.g. "sata"). | `string` | `""` | -| `subnets` | Additional subnets | `[]object` | `[]` | -| `subnets[i].name` | Subnet name | `string` | `""` | +| `networks` | Networks to attach the VM to. | `[]object` | `[]` | +| `networks[i].name` | Network attachment name. | `string` | `""` | +| `subnets` | Deprecated: use networks instead. | `[]object` | `[]` | +| `subnets[i].name` | Network attachment name. | `string` | `""` | | `gpus` | List of GPUs to attach (NVIDIA driver requires at least 4 GiB RAM). | `[]object` | `[]` | | `gpus[i].name` | The name of the GPU resource to attach. | `string` | `""` | | `cpuModel` | Model specifies the CPU model inside the VMI. List of available models https://github.com/libvirt/libvirt/tree/master/src/cpu_map | `string` | `""` | diff --git a/packages/apps/vm-instance/templates/vm.yaml b/packages/apps/vm-instance/templates/vm.yaml index d5c51ac9..23d9a1c4 100644 --- a/packages/apps/vm-instance/templates/vm.yaml +++ b/packages/apps/vm-instance/templates/vm.yaml @@ -7,6 +7,10 @@ {{- if and (not .Values.instanceType) (not (and .Values.resources .Values.resources.cpu .Values.resources.sockets .Values.resources.memory)) }} {{- fail "Either instanceType or resources (cpu, sockets, memory) must be specified" }} {{- end }} +{{- if and .Values.networks .Values.subnets }} +{{- fail "Both 'networks' and 'subnets' are set. Use only 'networks'; 'subnets' is deprecated." }} +{{- end }} +{{- $networks := .Values.networks | default .Values.subnets }} apiVersion: kubevirt.io/v1 kind: VirtualMachine @@ -86,7 +90,6 @@ spec: interfaces: - name: default bridge: {} - {{- $networks := .Values.networks | default .Values.subnets }} {{- range $i, $net := $networks }} - name: {{ $net.name }} bridge: {} @@ -122,7 +125,6 @@ spec: networks: - name: default pod: {} - {{- $networks := .Values.networks | default .Values.subnets }} {{- range $i, $net := $networks }} - name: {{ $net.name }} multus: diff --git a/packages/apps/vm-instance/values.schema.json b/packages/apps/vm-instance/values.schema.json index 1b2b3515..eae70e32 100644 --- a/packages/apps/vm-instance/values.schema.json +++ b/packages/apps/vm-instance/values.schema.json @@ -150,6 +150,20 @@ "type": "string", "default": "" }, + "networks": { + "description": "Networks to attach the VM to.", + "type": "array", + "default": [], + "items": { + "type": "object", + "properties": { + "name": { + "description": "Network attachment name.", + "type": "string" + } + } + } + }, "resources": { "description": "Resource configuration for the virtual machine.", "type": "object", @@ -204,6 +218,20 @@ "type": "string" } }, + "subnets": { + "description": "Deprecated: use networks instead.", + "type": "array", + "default": [], + "items": { + "type": "object", + "properties": { + "name": { + "description": "Network attachment name.", + "type": "string" + } + } + } + }, "cloudInit": { "description": "Cloud-init user data.", "type": "string",