From f318bac3436979ad948752a4faa2136ec74c0ae3 Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Tue, 3 Nov 2026 05:24:08 +0300 Subject: [PATCH] feat(cozystack-basics): take the root tenant vGPU flag from the platform A tenant is entitled to vGPU only when its parent is, and the root tenant's namespace and _namespace values are rendered here rather than by the tenant chart, so the chain has to start here. The value comes from _cluster.gpu-vgpu, which the platform fills from its gpu.vgpu. Like a tenant namespace, the root namespace always carries the label, and _namespace.vgpu appears only when entitled. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin --- .../templates/cozystack-values-secret.yaml | 3 + .../templates/tenant-root.yaml | 1 + .../tests/root-vgpu_test.yaml | 79 +++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 packages/system/cozystack-basics/tests/root-vgpu_test.yaml diff --git a/packages/system/cozystack-basics/templates/cozystack-values-secret.yaml b/packages/system/cozystack-basics/templates/cozystack-values-secret.yaml index 5c61a3942..e41ff08ab 100644 --- a/packages/system/cozystack-basics/templates/cozystack-values-secret.yaml +++ b/packages/system/cozystack-basics/templates/cozystack-values-secret.yaml @@ -43,3 +43,6 @@ stringData: {{- end }} monitoring: tenant-root seaweedfs: tenant-root + {{- if eq (toString (index .Values._cluster "gpu-vgpu" | default "false")) "true" }} + vgpu: true + {{- end }} diff --git a/packages/system/cozystack-basics/templates/tenant-root.yaml b/packages/system/cozystack-basics/templates/tenant-root.yaml index 43ba23fbc..aea0610f2 100644 --- a/packages/system/cozystack-basics/templates/tenant-root.yaml +++ b/packages/system/cozystack-basics/templates/tenant-root.yaml @@ -6,6 +6,7 @@ metadata: labels: platform.cozystack.io/no-delete: "true" namespace.cozystack.io/host: {{ index .Values._cluster "root-host" | quote }} + namespace.cozystack.io/vgpu: {{ eq (toString (index .Values._cluster "gpu-vgpu" | default "false")) "true" | quote }} {{- /* Gateway attach label: when platform-level Gateway is on, tenant-root owns the publishing Gateway, and its own namespace must carry the label so the Gateway's diff --git a/packages/system/cozystack-basics/tests/root-vgpu_test.yaml b/packages/system/cozystack-basics/tests/root-vgpu_test.yaml new file mode 100644 index 000000000..6b60199ea --- /dev/null +++ b/packages/system/cozystack-basics/tests/root-vgpu_test.yaml @@ -0,0 +1,79 @@ +suite: root tenant vGPU entitlement from platform values +# The root tenant is rendered here, not by the tenant chart, so its vGPU +# entitlement comes from the platform's gpu.vgpu through _cluster.gpu-vgpu. +# Every child's entitlement requires its parent's, so this is where the chain +# starts. +templates: + - templates/tenant-root.yaml + - templates/cozystack-values-secret.yaml +release: + name: cozystack-basics + namespace: cozy-system +set: + _cluster: + root-host: example.org +tests: + - it: labels the root namespace entitled when the platform turns vGPU on + set: + _cluster: + gpu-vgpu: "true" + template: templates/tenant-root.yaml + documentSelector: + path: kind + value: Namespace + asserts: + - equal: + path: metadata.labels["namespace.cozystack.io/vgpu"] + value: "true" + + - it: passes the entitlement to the root tenant's children + set: + _cluster: + gpu-vgpu: "true" + template: templates/cozystack-values-secret.yaml + asserts: + - matchRegex: + path: stringData["values.yaml"] + pattern: "(?m)^_namespace:\\n( .*\\n)* vgpu: true$" + + - it: labels the root namespace not entitled by default + template: templates/tenant-root.yaml + documentSelector: + path: kind + value: Namespace + asserts: + - equal: + path: metadata.labels["namespace.cozystack.io/vgpu"] + value: "false" + + - it: leaves _namespace.vgpu out by default + template: templates/cozystack-values-secret.yaml + asserts: + - notMatchRegex: + path: stringData["values.yaml"] + pattern: "(?m)^ vgpu:" + + # A bool set on the command line reaches here as a bool, a value from the + # platform's Secret as a string; only "true" in either form entitles. + - it: accepts a bool true + set: + _cluster: + gpu-vgpu: true + template: templates/tenant-root.yaml + documentSelector: + path: kind + value: Namespace + asserts: + - equal: + path: metadata.labels["namespace.cozystack.io/vgpu"] + value: "true" + + - it: treats the string "false" as not entitled + set: + _cluster: + gpu-vgpu: "false" + template: templates/cozystack-values-secret.yaml + asserts: + - notMatchRegex: + path: stringData["values.yaml"] + pattern: "(?m)^ vgpu:"