From c1d67b02dac59b8fe5ac6aa7ba0144e1f11ef472 Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Tue, 3 Nov 2026 06:27:47 +0300 Subject: [PATCH] feat(platform): pass gpu.resourceNames and gpu-vm-enabled on A pod-only GPU resource may have no GPUClass or KubeVirt table entry. The hoster needs to identify those resources explicitly so admission can detect requests that bypass class entries. Commas in a name would corrupt the controller's comma-separated flag; native resource names would misclassify CPU or memory as GPUs. A class reference is unusable where no GPU webhook will resolve it. Charts need that cluster capability to refuse such inputs rather than boot a VM without GPUs. Keeping the capability key absent while disabled avoids unnecessary upgrades through the shared tenant values channel. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin --- packages/core/platform/templates/_helpers.tpl | 25 +++++++ packages/core/platform/templates/apps.yaml | 6 ++ .../platform/templates/bundles/system.yaml | 7 +- .../apps_gpu_vm_enabled_wiring_test.yaml | 48 ++++++++++++++ .../bundles_gpu_resource_names_test.yaml | 66 +++++++++++++++++++ packages/core/platform/values.yaml | 5 ++ 6 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 packages/core/platform/tests/apps_gpu_vm_enabled_wiring_test.yaml create mode 100644 packages/core/platform/tests/bundles_gpu_resource_names_test.yaml diff --git a/packages/core/platform/templates/_helpers.tpl b/packages/core/platform/templates/_helpers.tpl index 728f82c47..dfc8bed2c 100644 --- a/packages/core/platform/templates/_helpers.tpl +++ b/packages/core/platform/templates/_helpers.tpl @@ -463,3 +463,28 @@ serves GPUs to pods only, which no GPUClass describes. true {{- end -}} {{- end }} + +{{/* +Validated gpu.resourceNames, as YAML. The controller takes the list as one +comma-separated flag, so a name carrying a comma would arrive as two names. +*/}} +{{- define "cozystack.platform.gpu.resourceNames" -}} +{{- $names := (.Values.gpu | default dict).resourceNames | default (list) -}} +{{- if not (kindIs "slice" $names) -}} +{{- fail (printf "gpu.resourceNames must be a list of resource names, got %v" $names) -}} +{{- end -}} +{{- range $names -}} +{{- if not (kindIs "string" .) -}} +{{- fail (printf "gpu.resourceNames must be a list of resource names, got %v" .) -}} +{{- end -}} +{{- if contains "," . -}} +{{- fail (printf "gpu.resourceNames entry %q contains a comma; the list travels comma-joined and the name would be split" .) -}} +{{- end -}} +{{- /* Kubernetes treats a name without a domain, or one containing + kubernetes.io/, as a native resource such as memory. */ -}} +{{- if or (not (regexMatch "^[a-z0-9]([-a-z0-9.]*[a-z0-9])?/[A-Za-z0-9]([-A-Za-z0-9_.]*[A-Za-z0-9])?$" .)) (contains "kubernetes.io/" .) -}} +{{- fail (printf "gpu.resourceNames entry %q is not an extended resource name, such as nvidia.com/gpu" .) -}} +{{- end -}} +{{- end -}} +{{- toYaml $names -}} +{{- end }} diff --git a/packages/core/platform/templates/apps.yaml b/packages/core/platform/templates/apps.yaml index a146e8554..3484b13c5 100644 --- a/packages/core/platform/templates/apps.yaml +++ b/packages/core/platform/templates/apps.yaml @@ -296,6 +296,12 @@ stringData: {{- if eq (printf "%v" ((.Values.gpu).vgpu | default false)) "true" }} gpu-vgpu: "true" {{- end }} + {{- /* Whether GPUs serve VMs, so that vm-instance and kubernetes-nodes + refuse class entries where no webhook would resolve them. + Written only when on, like the other optional keys. */}} + {{- if eq (include "cozystack.platform.gpu.vmEnabled" .) "true" }} + gpu-vm-enabled: "true" + {{- end }} {{- /* The rate each shared-central tracing tenant's collector holds it to. Only written when set: every release in every tenant reads this Secret, and a key appearing would upgrade all of them. */}} diff --git a/packages/core/platform/templates/bundles/system.yaml b/packages/core/platform/templates/bundles/system.yaml index 432bcea8e..5c25e6710 100644 --- a/packages/core/platform/templates/bundles/system.yaml +++ b/packages/core/platform/templates/bundles/system.yaml @@ -256,8 +256,13 @@ {{- if .Values.telemetry.disabled -}} {{- $_ := set $controllerValues "disableTelemetry" true -}} {{- end -}} +{{- $gpuResourceNames := include "cozystack.platform.gpu.resourceNames" $ | fromYamlArray -}} {{- if eq (include "cozystack.platform.gpu.vmEnabled" $) "true" -}} -{{- $_ := set $controllerValues "gpu" (dict "enabled" true) -}} +{{- $gpu := dict "enabled" true -}} +{{- with $gpuResourceNames -}} +{{- $_ := set $gpu "resourceNames" . -}} +{{- end -}} +{{- $_ := set $controllerValues "gpu" $gpu -}} {{- end -}} {{- /* EndpointAttachment's method: WholeIP|PortList modes render the Service contract cozy-proxy implements. A proxy skips a Service delegated to a diff --git a/packages/core/platform/tests/apps_gpu_vm_enabled_wiring_test.yaml b/packages/core/platform/tests/apps_gpu_vm_enabled_wiring_test.yaml new file mode 100644 index 000000000..8990d964a --- /dev/null +++ b/packages/core/platform/tests/apps_gpu_vm_enabled_wiring_test.yaml @@ -0,0 +1,48 @@ +suite: apps.yaml gpu-vm-enabled → _cluster wiring +templates: + - templates/apps.yaml +release: + name: cozy-platform + namespace: cozy-system + +# vm-instance and kubernetes-nodes refuse class entries at render where no +# webhook would resolve them. The key is written only when on: _cluster is +# copied into every tenant's cozystack-values, so a key that is always +# present would upgrade every release in every tenant. +tests: + - it: writes gpu-vm-enabled when gpu-operator serves GPUs to VMs + set: + bundles: + system: + enabled: true + variant: isp-full + iaas: + enabled: true + enabledPackages: + - cozystack.gpu-operator + asserts: + - matchRegex: + path: stringData["values.yaml"] + pattern: '(?m)^_cluster:\n( .*\n)* gpu-vm-enabled: "true"$' + + - it: leaves it out for the container variant + set: + bundles: + system: + enabled: true + variant: isp-full + iaas: + enabled: true + gpuOperatorVariant: container + enabledPackages: + - cozystack.gpu-operator + asserts: + - notMatchRegex: + path: stringData["values.yaml"] + pattern: gpu-vm-enabled + + - it: leaves it out by default + asserts: + - notMatchRegex: + path: stringData["values.yaml"] + pattern: gpu-vm-enabled diff --git a/packages/core/platform/tests/bundles_gpu_resource_names_test.yaml b/packages/core/platform/tests/bundles_gpu_resource_names_test.yaml new file mode 100644 index 000000000..3baccb817 --- /dev/null +++ b/packages/core/platform/tests/bundles_gpu_resource_names_test.yaml @@ -0,0 +1,66 @@ +suite: gpu.resourceNames reaches the GPU controller +templates: + - templates/bundles/system.yaml +release: + name: cozystack + namespace: cozy-system +set: + bundles: + system: + enabled: true + variant: isp-full + iaas: + enabled: true + enabledPackages: + - cozystack.gpu-operator +tests: + - it: passes the hoster's GPU resource names + set: + gpu.resourceNames: [nvidia.com/gpu, amd.com/gpu] + documentSelector: + path: metadata.name + value: cozystack.cozystack-engine + asserts: + - equal: + path: spec.components.cozystack-controller.values.cozystackController.gpu + value: + enabled: true + resourceNames: [nvidia.com/gpu, amd.com/gpu] + + - it: passes no list when it is empty + documentSelector: + path: metadata.name + value: cozystack.cozystack-engine + asserts: + - notExists: + path: spec.components.cozystack-controller.values.cozystackController.gpu.resourceNames + + # The controller takes the list as one comma-separated flag, so a comma + # inside a name would split it in two. + - it: refuses a name with a comma + set: + gpu.resourceNames: ["nvidia.com/a,b"] + asserts: + - failedTemplate: + errorPattern: gpu.resourceNames entry "nvidia.com/a,b" contains a comma + + - it: refuses a name that is not an extended resource + set: + gpu.resourceNames: [memory] + asserts: + - failedTemplate: + errorPattern: gpu.resourceNames entry "memory" is not an extended resource name + + - it: refuses a name in kubernetes.io + set: + gpu.resourceNames: [kubernetes.io/gpu] + asserts: + - failedTemplate: + errorPattern: gpu.resourceNames entry "kubernetes.io/gpu" is not an extended resource name + + - it: refuses a list that is not one + set: + gpu.resourceNames: nvidia.com/gpu + asserts: + - failedTemplate: + errorPattern: gpu.resourceNames must be a list of resource names diff --git a/packages/core/platform/values.yaml b/packages/core/platform/values.yaml index 0b4d89a44..2d5a0a09a 100644 --- a/packages/core/platform/values.yaml +++ b/packages/core/platform/values.yaml @@ -1040,6 +1040,11 @@ gpu: # only when its own Tenant sets gpu.vgpu and its parent is entitled, so # vGPU reaches no tenant until this is on. vgpu: false + # GPU resource names that only pods request, such as nvidia.com/gpu of the + # container variant, besides the names of GPUClass objects and the NVIDIA + # and mediated entries of the KubeVirt permittedHostDevices table. A VM + # with class entries may carry no GPU entry of its own under any of them. + resourceNames: [] # VM import from external virtualization platforms (opt-in; see the iaas bundle). vmImport: