From e6d7671b19a543cb361ea4fe93f039bfd59b53fa Mon Sep 17 00:00:00 2001 From: Timofei Larkin Date: Wed, 18 Nov 2026 12:21:29 +0100 Subject: [PATCH] fix(platform): keep tenant Gateways off an unserved class on cozyplane The guard against the bundled cilium GatewayClass on the cozyplane variant compared the raw gateway.className, while apps.yaml trims it and defaults an empty one to cilium before tenants see it, so "" and " cilium " passed and still resolved to a class nothing serves. It also ran only for the platform's gateway flag: a tenant enabling its own Gateway never reached it. The platform guard now compares the resolved class. For the tenant path, the platform lists the classes no controller serves in _cluster.gateway-unserved-classes, cilium on cozyplane, and the gateway chart refuses a resolved class in that list, whether the tenant chose it or inherited the default. Classes the operator makes selectable keep working. Assisted-by: LLM Signed-off-by: Timofei Larkin --- packages/core/platform/templates/apps.yaml | 4 + .../platform/templates/bundles/system.yaml | 8 +- .../tests/apps_gateway_class_wiring_test.yaml | 19 +++++ .../bundles_networking_variant_test.yaml | 31 ++++++++ .../gateway/templates/tenantgateway.yaml | 7 ++ .../gateway/tests/unserved_class_test.yaml | 73 +++++++++++++++++++ 6 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 packages/extra/gateway/tests/unserved_class_test.yaml diff --git a/packages/core/platform/templates/apps.yaml b/packages/core/platform/templates/apps.yaml index db6c7109b..d1987118c 100644 --- a/packages/core/platform/templates/apps.yaml +++ b/packages/core/platform/templates/apps.yaml @@ -249,6 +249,10 @@ stringData: {{- end }} gateway-edge-classes: {{ $edgeClasses | join "," | quote }} gateway-tenant-classes: {{ $tenantClasses | join "," | quote }} + {{- /* GatewayClasses no controller on this cluster serves. The bundled + cilium class has none on the cozyplane networking variant, and a + tenant Gateway on it would never program. */}} + gateway-unserved-classes: {{ ternary "cilium" "" (eq (.Values.bundles.system.networkingVariant | default "kubeovn-cilium") "cozyplane") | quote }} {{- /* Whether the root tenant hosts the platform monitoring stack (Tenant/root spec.monitoring). cozystack-basics gates the cozy-monitoring -> tenant-root vlinsert/vminsert ExternalName diff --git a/packages/core/platform/templates/bundles/system.yaml b/packages/core/platform/templates/bundles/system.yaml index 0853ae5de..ffb2df157 100644 --- a/packages/core/platform/templates/bundles/system.yaml +++ b/packages/core/platform/templates/bundles/system.yaml @@ -11,8 +11,12 @@ {{- end -}} {{- /* The default gateway.className is the Cilium class, and no Cilium runs on the cozyplane variant — every tenant Gateway would sit unserved with - nothing reporting why. */ -}} -{{- if and (eq $nv "cozyplane") .Values.gateway.enabled (eq .Values.gateway.className "cilium") -}} + nothing reporting why. Compared after the normalization apps.yaml + applies before handing the class to tenants, so an empty or padded + value cannot slip past. A tenant enabling its own Gateway is refused in + the gateway chart, through _cluster.gateway-unserved-classes. */ -}} +{{- $resolvedGatewayClass := .Values.gateway.className | default "" | toString | trim | default "cilium" -}} +{{- if and (eq $nv "cozyplane") .Values.gateway.enabled (eq $resolvedGatewayClass "cilium") -}} {{- fail "gateway.enabled needs a gateway.className another implementation serves on the cozyplane networking variant: nothing serves the \"cilium\" class there" -}} {{- end -}} {{- if .Values.bundles.system.enabled }} diff --git a/packages/core/platform/tests/apps_gateway_class_wiring_test.yaml b/packages/core/platform/tests/apps_gateway_class_wiring_test.yaml index ac001c3cb..52944f31d 100644 --- a/packages/core/platform/tests/apps_gateway_class_wiring_test.yaml +++ b/packages/core/platform/tests/apps_gateway_class_wiring_test.yaml @@ -142,3 +142,22 @@ tests: - matchRegex: path: stringData["values.yaml"] pattern: '(?m)^\s*gateway-tenant-classes:\s*""' + + # The gateway chart refuses a resolved class in this list, which is how a + # tenant that enables its own Gateway is kept off a class nothing serves. + - it: marks the cilium class unserved on the cozyplane variant + set: + bundles: + system: + networkingVariant: cozyplane + asserts: + - matchRegex: + path: stringData["values.yaml"] + pattern: '(?m)^\s*gateway-unserved-classes:\s*"cilium"' + + - it: marks no class unserved on the default variant + asserts: + - matchRegex: + path: stringData["values.yaml"] + pattern: '(?m)^\s*gateway-unserved-classes:\s*""' + diff --git a/packages/core/platform/tests/bundles_networking_variant_test.yaml b/packages/core/platform/tests/bundles_networking_variant_test.yaml index 7f89df68b..61d5113e6 100644 --- a/packages/core/platform/tests/bundles_networking_variant_test.yaml +++ b/packages/core/platform/tests/bundles_networking_variant_test.yaml @@ -402,3 +402,34 @@ tests: kind: Package name: cozystack.cozyplane-apiserver any: true + + # apps.yaml trims the class and defaults an empty one to cilium before + # tenants see it, so the guard compares the same resolved value. + - it: refuses an empty gateway class on cozyplane + set: + bundles: + system: + enabled: true + variant: isp-full + networkingVariant: cozyplane + gateway: + enabled: true + className: "" + asserts: + - failedTemplate: + errorPattern: 'nothing serves the "cilium" class' + + - it: refuses a padded cilium gateway class on cozyplane + set: + bundles: + system: + enabled: true + variant: isp-full + networkingVariant: cozyplane + gateway: + enabled: true + className: " cilium " + asserts: + - failedTemplate: + errorPattern: 'nothing serves the "cilium" class' + diff --git a/packages/extra/gateway/templates/tenantgateway.yaml b/packages/extra/gateway/templates/tenantgateway.yaml index f0d5ef5eb..5438a898b 100644 --- a/packages/extra/gateway/templates/tenantgateway.yaml +++ b/packages/extra/gateway/templates/tenantgateway.yaml @@ -34,6 +34,13 @@ {{- end }} {{- $defaultClass := $rawDefaultClass | trim | default "cilium" }} {{- $className := $rawClassName | trim | default $defaultClass }} +{{- /* Checked for the resolved class, so it holds whether the tenant chose + the class or inherited the platform default. */}} +{{- range splitList "," ((index .Values._cluster "gateway-unserved-classes") | default "") }} + {{- if eq (trim .) $className }} + {{- fail (printf "packages/extra/gateway: GatewayClass %q has no controller on this cluster, so this Gateway would never be programmed. Set tenant.spec.gatewayClass to a class the operator lists in gateway.tenantSelectableClasses, or have the operator set gateway.className to a served class." $className) }} + {{- end }} +{{- end }} {{- $edgeClasses := list }} {{- range splitList "," ((index .Values._cluster "gateway-edge-classes") | default "") }} {{- $c := . | trim }} diff --git a/packages/extra/gateway/tests/unserved_class_test.yaml b/packages/extra/gateway/tests/unserved_class_test.yaml new file mode 100644 index 000000000..e5c0addd2 --- /dev/null +++ b/packages/extra/gateway/tests/unserved_class_test.yaml @@ -0,0 +1,73 @@ +suite: a tenant Gateway refuses a class nothing serves +templates: + - templates/tenantgateway.yaml + +# On the cozyplane networking variant no controller serves the bundled cilium +# class, and the platform says so in _cluster.gateway-unserved-classes. The +# check runs on the resolved class, so it holds whether the tenant chose it or +# inherited the platform default, and whatever the platform's own gateway flag. +release: + name: gateway + namespace: tenant-alice + +tests: + - it: refuses an inherited default class nothing serves + set: + _cluster: + solver: http01 + expose-ingress: tenant-root + issuer-name: letsencrypt-prod + gateway-class-name: cilium + gateway-unserved-classes: cilium + _namespace: + host: alice.example.org + asserts: + - failedTemplate: + errorPattern: 'GatewayClass "cilium" has no controller on this cluster' + + - it: refuses a tenant-chosen class nothing serves + set: + _cluster: + solver: http01 + expose-ingress: tenant-root + issuer-name: letsencrypt-prod + gateway-class-name: envoy + gateway-tenant-classes: cilium + gateway-unserved-classes: cilium + _namespace: + host: alice.example.org + gatewayClassName: cilium + asserts: + - failedTemplate: + errorPattern: 'GatewayClass "cilium" has no controller on this cluster' + + - it: lets a tenant select a served class while the default is unserved + set: + _cluster: + solver: http01 + expose-ingress: tenant-root + issuer-name: letsencrypt-prod + gateway-class-name: cilium + gateway-tenant-classes: envoy + gateway-unserved-classes: cilium + _namespace: + host: alice.example.org + gatewayClassName: envoy + asserts: + - equal: + path: spec.gatewayClassName + value: envoy + + - it: renders the cilium class where nothing marks it unserved + set: + _cluster: + solver: http01 + expose-ingress: tenant-root + issuer-name: letsencrypt-prod + gateway-class-name: cilium + _namespace: + host: alice.example.org + asserts: + - equal: + path: spec.gatewayClassName + value: cilium