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 <f@lex.la>
This commit is contained in:
Aleksei Sviridkin committed 2026-11-28 09:25:42 +03:00
1 parent 1a5ce01fd5
commit c1d67b02da
6 files changed
+156 -1

No files matched your search

@@ -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 }}
@@ -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. */}}
@@ -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
@@ -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
@@ -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
+5
View File
@@ -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: