From 19ab55c03031908f4419f4455d6f60908d46fc83 Mon Sep 17 00:00:00 2001 From: Yan Bondarenko <202671653+yankawai@users.noreply.github.com> Date: Tue, 24 Nov 2026 22:04:25 +0100 Subject: [PATCH] fix(platform): stop handing tenants a root S3 the root tenant does not run cozystack-basics wrote seaweedfs: tenant-root into the root values unconditionally, so every tenant without its own SeaweedFS inherited tenant-root as its S3 even when Tenant/root runs none. A Bucket there got a BucketClaim for a bucket class that never appears, and Harbor got its registry bucket the same way. seaweedfs.rootEnabled records that choice the way monitoring.rootEnabled does for monitoring, and the bucket and harbor charts refuse to render without S3 up the tenant chain rather than wait on a class that does not exist. Older configurations have no SeaweedFS flag. Keep their root S3 enabled. For an explicit value only true or the string "true" enables it. Assisted-by: LLM Signed-off-by: Yan Bondarenko <202671653+yankawai@users.noreply.github.com> --- hack/app-cleanup-hooks_test.bats | 12 +-- hack/check-render-matrix.sh | 2 + hack/check-tenant-secret-grants.bats | 1 + hack/testdata/render-fixtures/README.md | 2 +- .../apps/bucket/templates/bucketclaim.yaml | 3 + .../apps/bucket/tests/s3_backend_test.yaml | 25 ++++++ packages/apps/harbor/templates/bucket.yaml | 3 + .../apps/harbor/tests/s3_backend_test.yaml | 28 +++++++ packages/core/platform/templates/apps.yaml | 1 + .../apps_seaweedfs_enabled_wiring_test.yaml | 30 +++++++ .../core/platform/values-isp-hosted-slim.yaml | 4 + .../platform/values-isp-slim-generic.yaml | 4 + packages/core/platform/values-isp-slim.yaml | 4 + packages/core/platform/values.yaml | 7 ++ .../templates/cozystack-values-secret.yaml | 7 +- .../tests/cozystack-values-secret_test.yaml | 79 +++++++++++++++---- 16 files changed, 188 insertions(+), 24 deletions(-) create mode 100644 packages/apps/bucket/tests/s3_backend_test.yaml create mode 100644 packages/apps/harbor/tests/s3_backend_test.yaml create mode 100644 packages/core/platform/tests/apps_seaweedfs_enabled_wiring_test.yaml diff --git a/hack/app-cleanup-hooks_test.bats b/hack/app-cleanup-hooks_test.bats index 672dcc541..ba1b41bbb 100644 --- a/hack/app-cleanup-hooks_test.bats +++ b/hack/app-cleanup-hooks_test.bats @@ -286,7 +286,7 @@ persistentvolumeclaim/db-qdrant-test-0' tmp=$(mktemp -d) write_fake_kubectl "$tmp" render_hook "$HARBOR_CHART" harbor-test tenant-test harbor-test-cleanup "$tmp/hook.sh" \ - --set '_namespace.host=example.org' --set '_cluster.solver=http01' + --set '_namespace.host=example.org' --set '_namespace.seaweedfs=tenant-root' --set '_cluster.solver=http01' export KLOG="$tmp/calls" export CHALLENGE_LIST='harbor-test-cert-1 ' @@ -322,7 +322,7 @@ persistentvolumeclaim/db-qdrant-test-0' tmp=$(mktemp -d) write_fake_kubectl "$tmp" render_hook "$HARBOR_CHART" harbor-test tenant-test harbor-test-cleanup "$tmp/hook.sh" \ - --set '_namespace.host=example.org' --set '_cluster.solver=http01' + --set '_namespace.host=example.org' --set '_namespace.seaweedfs=tenant-root' --set '_cluster.solver=http01' export KLOG="$tmp/calls" export CHALLENGE_LIST='' @@ -350,7 +350,7 @@ persistentvolumeclaim/db-qdrant-test-0' tmp=$(mktemp -d) write_fake_kubectl "$tmp" render_hook "$HARBOR_CHART" harbor-test tenant-test harbor-test-cleanup "$tmp/hook.sh" \ - --set '_namespace.host=example.org' --set '_cluster.solver=http01' + --set '_namespace.host=example.org' --set '_namespace.seaweedfs=tenant-root' --set '_cluster.solver=http01' export KLOG="$tmp/calls" export CHALLENGE_LIST='harbor-test-cert-1 ' @@ -396,7 +396,7 @@ persistentvolumeclaim/db-qdrant-test-0' tmp=$(mktemp -d) write_fake_kubectl "$tmp" render_hook "$HARBOR_CHART" harbor-test tenant-test harbor-test-cleanup "$tmp/hook.sh" \ - --set '_namespace.host=example.org' --set '_cluster.solver=http01' + --set '_namespace.host=example.org' --set '_namespace.seaweedfs=tenant-root' --set '_cluster.solver=http01' export KLOG="$tmp/calls" export CHALLENGE_LIST='harbor-test-cert-1 ' @@ -438,7 +438,7 @@ persistentvolumeclaim/db-qdrant-test-0' tmp=$(mktemp -d) write_fake_kubectl "$tmp" render_hook "$HARBOR_CHART" harbor-test tenant-test harbor-test-cleanup "$tmp/hook.sh" \ - --set '_namespace.host=example.org' --set '_cluster.solver=http01' + --set '_namespace.host=example.org' --set '_namespace.seaweedfs=tenant-root' --set '_cluster.solver=http01' export KLOG="$tmp/calls" export CHALLENGE_LIST='harbor-test-cert-1 ' @@ -480,7 +480,7 @@ persistentvolumeclaim/db-qdrant-test-0' tmp=$(mktemp -d) write_fake_kubectl "$tmp" render_hook "$HARBOR_CHART" harbor-test tenant-test harbor-test-cleanup "$tmp/hook.sh" \ - --set '_namespace.host=example.org' --set '_cluster.solver=http01' + --set '_namespace.host=example.org' --set '_namespace.seaweedfs=tenant-root' --set '_cluster.solver=http01' export KLOG="$tmp/calls" export CHALLENGE_LIST='' diff --git a/hack/check-render-matrix.sh b/hack/check-render-matrix.sh index faff145b9..94c8ea7ae 100755 --- a/hack/check-render-matrix.sh +++ b/hack/check-render-matrix.sh @@ -25,6 +25,8 @@ render_chart() { tenant) set -- tenant-sub --api-versions v1.edp.epam.com/v1 ;; # Satisfy the parent-cluster and release-name contract before the lookup. kubernetes-nodes) set -- kubernetes-nodes-render-check --set-string cluster=render ;; + # Both refuse to render without S3 up the tenant chain. + bucket|harbor) set -- "$name-render-check" --set-string _namespace.seaweedfs=tenant-root ;; *) set -- "$name-render-check" ;; esac helm template "$@" "$chart" -n tenant-test -f "$fixture" diff --git a/hack/check-tenant-secret-grants.bats b/hack/check-tenant-secret-grants.bats index 41289cf74..932d20a12 100644 --- a/hack/check-tenant-secret-grants.bats +++ b/hack/check-tenant-secret-grants.bats @@ -57,6 +57,7 @@ render() { bootbox) set -- bootbox; namespace=tenant-root ;; computeplane|etcd|info|ingress|monitoring|seaweedfs|gateway) set -- "$name" ;; external-dns) set -- external-dns --set provider=inmemory ;; + bucket|harbor) set -- "$name-render-check" --set-string _namespace.seaweedfs=tenant-root ;; kubernetes-nodes) set -- kubernetes-nodes-render-check --set-string cluster=render \ --set-string resources.cpu=2 --set-string resources.memory=4Gi ;; tenant) set -- tenant-sub --api-versions v1.edp.epam.com/v1 ;; diff --git a/hack/testdata/render-fixtures/README.md b/hack/testdata/render-fixtures/README.md index 32661c899..9911c0539 100644 --- a/hack/testdata/render-fixtures/README.md +++ b/hack/testdata/render-fixtures/README.md @@ -14,7 +14,7 @@ The source of `_cluster` is `packages/core/platform/templates/apps.yaml`; `_name | `configured.yaml` | OIDC on, per-host ACME via http01, shared services and topology constraint | | `wildcard.yaml` | OIDC on, dns01 with a platform-issued wildcard certificate, shared services and topology constraint | -Each chart is attempted under every fixture. `vm-instance` and `kubernetes-nodes` require a `VirtualMachineClusterInstancetype` lookup on their defaults. The sweep accepts their skip only while every fixture fails with the recorded lookup diagnostic; a successful render or a different error fails the sweep. For kubernetes-nodes it supplies a parent cluster and matching release name first. For tenant it declares the Keycloak API with `--api-versions v1.edp.epam.com/v1`, allowing OIDC-enabled fixtures to render the realm groups. +Each chart is attempted under every fixture. `vm-instance` and `kubernetes-nodes` require a `VirtualMachineClusterInstancetype` lookup on their defaults. The sweep accepts their skip only while every fixture fails with the recorded lookup diagnostic; a successful render or a different error fails the sweep. For kubernetes-nodes it supplies a parent cluster and matching release name first. For bucket and harbor it names a SeaweedFS namespace, since both refuse to render without S3 up the tenant chain. For tenant it declares the Keycloak API with `--api-versions v1.edp.epam.com/v1`, allowing OIDC-enabled fixtures to render the realm groups. `lookup` returns an empty result during this check. Tests for existing objects belong in chart-specific helm-unittest suites using `kubernetesProvider`; `packages/apps/clickhouse/tests/backup_api_password_persistence_test.yaml` covers both password generation and preservation that way. Presets, replica counts and other app feature toggles are outside this sweep. diff --git a/packages/apps/bucket/templates/bucketclaim.yaml b/packages/apps/bucket/templates/bucketclaim.yaml index c5456dd96..0be116e15 100644 --- a/packages/apps/bucket/templates/bucketclaim.yaml +++ b/packages/apps/bucket/templates/bucketclaim.yaml @@ -1,4 +1,7 @@ {{- $seaweedfs := .Values._namespace.seaweedfs }} +{{- if not $seaweedfs }} +{{- fail "a bucket needs S3, and neither this tenant nor a tenant above it runs SeaweedFS" }} +{{- end }} {{- $pool := .Values.storagePool }} {{- /* COSI classes are cluster-scoped and named after the namespace of the instance diff --git a/packages/apps/bucket/tests/s3_backend_test.yaml b/packages/apps/bucket/tests/s3_backend_test.yaml new file mode 100644 index 000000000..94fab4a12 --- /dev/null +++ b/packages/apps/bucket/tests/s3_backend_test.yaml @@ -0,0 +1,25 @@ +suite: bucket needs an S3 backend in its tenant chain +templates: + - templates/bucketclaim.yaml + +release: + name: my-bucket + namespace: tenant-demo + +tests: + - it: claims the bucket class of the nearest tenant with SeaweedFS + set: + _namespace: + seaweedfs: tenant-root + asserts: + - equal: + path: spec.bucketClassName + value: tenant-root + + - it: refuses to render when no tenant up the chain runs SeaweedFS + set: + _namespace: + seaweedfs: "" + asserts: + - failedTemplate: + errorPattern: "a bucket needs S3, and neither this tenant nor a tenant above it runs SeaweedFS" diff --git a/packages/apps/harbor/templates/bucket.yaml b/packages/apps/harbor/templates/bucket.yaml index 5394ad229..2e3111e47 100644 --- a/packages/apps/harbor/templates/bucket.yaml +++ b/packages/apps/harbor/templates/bucket.yaml @@ -1,4 +1,7 @@ {{- $seaweedfs := .Values._namespace.seaweedfs }} +{{- if not $seaweedfs }} +{{- fail "harbor keeps images in S3, and neither this tenant nor a tenant above it runs SeaweedFS" }} +{{- end }} apiVersion: objectstorage.k8s.io/v1alpha1 kind: BucketClaim metadata: diff --git a/packages/apps/harbor/tests/s3_backend_test.yaml b/packages/apps/harbor/tests/s3_backend_test.yaml new file mode 100644 index 000000000..2c49b897f --- /dev/null +++ b/packages/apps/harbor/tests/s3_backend_test.yaml @@ -0,0 +1,28 @@ +suite: harbor needs an S3 backend in its tenant chain +templates: + - templates/bucket.yaml + +release: + name: harbor + namespace: tenant-demo + +tests: + - it: claims the registry bucket from the nearest tenant with SeaweedFS + set: + _namespace: + seaweedfs: tenant-root + documentSelector: + path: kind + value: BucketClaim + asserts: + - equal: + path: spec.bucketClassName + value: tenant-root + + - it: refuses to render when no tenant up the chain runs SeaweedFS + set: + _namespace: + seaweedfs: "" + asserts: + - failedTemplate: + errorPattern: "harbor keeps images in S3, and neither this tenant nor a tenant above it runs SeaweedFS" diff --git a/packages/core/platform/templates/apps.yaml b/packages/core/platform/templates/apps.yaml index e04fd89ff..6eb454564 100644 --- a/packages/core/platform/templates/apps.yaml +++ b/packages/core/platform/templates/apps.yaml @@ -290,6 +290,7 @@ stringData: (Tenant/root spec.ingress). `dig`, as for monitoring-enabled above, so an explicit false survives. */}} ingress-enabled: {{ dig "rootEnabled" true (.Values.ingress | default dict) | quote }} + seaweedfs-enabled: {{ dig "rootEnabled" true (.Values.seaweedfs | default dict) | quote }} {{- /* 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/tests/apps_seaweedfs_enabled_wiring_test.yaml b/packages/core/platform/tests/apps_seaweedfs_enabled_wiring_test.yaml new file mode 100644 index 000000000..472793a81 --- /dev/null +++ b/packages/core/platform/tests/apps_seaweedfs_enabled_wiring_test.yaml @@ -0,0 +1,30 @@ +suite: apps.yaml wires seaweedfs.rootEnabled into _cluster +templates: + - templates/apps.yaml + +release: + name: cozy-platform + namespace: cozy-system + +tests: + - it: writes seaweedfs-enabled true by default + asserts: + - matchRegex: + path: stringData["values.yaml"] + pattern: '(?m)^\s*seaweedfs-enabled:\s*"true"' + + - it: writes seaweedfs-enabled false when seaweedfs.rootEnabled is disabled + set: + seaweedfs.rootEnabled: false + asserts: + - matchRegex: + path: stringData["values.yaml"] + pattern: '(?m)^\s*seaweedfs-enabled:\s*"false"' + + - it: falls back to true (no panic) when seaweedfs is null + set: + seaweedfs: null + asserts: + - matchRegex: + path: stringData["values.yaml"] + pattern: '(?m)^\s*seaweedfs-enabled:\s*"true"' diff --git a/packages/core/platform/values-isp-hosted-slim.yaml b/packages/core/platform/values-isp-hosted-slim.yaml index cfd3adcc5..19391b3df 100644 --- a/packages/core/platform/values-isp-hosted-slim.yaml +++ b/packages/core/platform/values-isp-hosted-slim.yaml @@ -26,3 +26,7 @@ bundles: # into it would dead-end; see monitoring.rootEnabled in values.yaml. monitoring: rootEnabled: false +# Tenant/root does not run SeaweedFS here either, so tenants must not take it +# as their S3. See seaweedfs.rootEnabled in values.yaml. +seaweedfs: + rootEnabled: false diff --git a/packages/core/platform/values-isp-slim-generic.yaml b/packages/core/platform/values-isp-slim-generic.yaml index ef213893d..6c8b0b255 100644 --- a/packages/core/platform/values-isp-slim-generic.yaml +++ b/packages/core/platform/values-isp-slim-generic.yaml @@ -31,3 +31,7 @@ bundles: # into it would dead-end; see monitoring.rootEnabled in values.yaml. monitoring: rootEnabled: false +# Tenant/root does not run SeaweedFS here either, so tenants must not take it +# as their S3. See seaweedfs.rootEnabled in values.yaml. +seaweedfs: + rootEnabled: false diff --git a/packages/core/platform/values-isp-slim.yaml b/packages/core/platform/values-isp-slim.yaml index 41b494bd9..62148fe26 100644 --- a/packages/core/platform/values-isp-slim.yaml +++ b/packages/core/platform/values-isp-slim.yaml @@ -31,3 +31,7 @@ bundles: # into it would dead-end; see monitoring.rootEnabled in values.yaml. monitoring: rootEnabled: false +# Tenant/root does not run SeaweedFS here either, so tenants must not take it +# as their S3. See seaweedfs.rootEnabled in values.yaml. +seaweedfs: + rootEnabled: false diff --git a/packages/core/platform/values.yaml b/packages/core/platform/values.yaml index 2d963cb2c..51a8c517c 100644 --- a/packages/core/platform/values.yaml +++ b/packages/core/platform/values.yaml @@ -835,6 +835,13 @@ ingress: # to keep the value existing clusters already render. rootEnabled: true +# Platform object storage configuration. +seaweedfs: + # Whether the root tenant (tenant-root) runs SeaweedFS, i.e. Tenant/root + # spec.seaweedfs=true. Tenants without their own SeaweedFS take tenant-root + # as their S3 only when this is true. Keep it in sync with Tenant/root + # spec.seaweedfs, the default true preserves the historical behaviour. + rootEnabled: true # Platform monitoring configuration. monitoring: # Whether the root tenant (tenant-root) hosts the platform diff --git a/packages/system/cozystack-basics/templates/cozystack-values-secret.yaml b/packages/system/cozystack-basics/templates/cozystack-values-secret.yaml index 5c61a3942..41a0d0bdc 100644 --- a/packages/system/cozystack-basics/templates/cozystack-values-secret.yaml +++ b/packages/system/cozystack-basics/templates/cozystack-values-secret.yaml @@ -23,8 +23,8 @@ stringData: {{- if or (kindIs "invalid" $ingress) (eq (toString $ingress) "true") }} ingress: tenant-root {{- end }} - {{- /* `gateway` is conditional, the other four `_namespace` keys are - unconditional. The `apps/tenant` chart gates tenant-root via + {{- /* `gateway`, `ingress` and `seaweedfs` are conditional, `etcd` and + `monitoring` are unconditional. The `apps/tenant` chart gates tenant-root via `ne (include "tenant.name" .) "tenant-root"`, so the namespace.yaml propagation fix that consumes `tenant.gatewayEffective` never reaches tenant-root — and the `cozystack-values` Secret rendered @@ -42,4 +42,7 @@ stringData: gateway: tenant-root {{- end }} monitoring: tenant-root + {{- $seaweedfs := dig "seaweedfs-enabled" true (.Values._cluster | default dict) }} + {{- if eq (toString $seaweedfs) "true" }} seaweedfs: tenant-root + {{- end }} diff --git a/packages/system/cozystack-basics/tests/cozystack-values-secret_test.yaml b/packages/system/cozystack-basics/tests/cozystack-values-secret_test.yaml index 294049fcc..78310feab 100644 --- a/packages/system/cozystack-basics/tests/cozystack-values-secret_test.yaml +++ b/packages/system/cozystack-basics/tests/cozystack-values-secret_test.yaml @@ -19,16 +19,17 @@ set: # never reaches tenant-root — this Secret is the only place that # value gets set for the root tenant. # -# Three of the five `_namespace.*` keys (`etcd`, `monitoring`, -# `seaweedfs`) are always rendered, because their dependent platform -# apps are always installable in tenant-root. `gateway` is conditional -# on `_cluster.gateway-enabled`: when the platform-level flag is false -# (the default), Gateway is not installed, and writing -# `gateway: tenant-root` would point apps at a Gateway that doesn't -# exist. `ingress` is conditional on `_cluster.ingress-enabled` for the -# same reason: with ingress off on the root Tenant there is no -# ingress-nginx-system in tenant-root, and seaweedfs would wait on it -# forever. The fixtures below pin both halves of each contract. +# Two of the five `_namespace.*` keys (`etcd`, `monitoring`) are always +# rendered, because their dependent platform apps are always installable +# in tenant-root. `gateway` is conditional on `_cluster.gateway-enabled`: +# when the platform-level flag is false (the default), Gateway is not +# installed, and writing `gateway: tenant-root` would point apps at a +# Gateway that doesn't exist. `ingress` is conditional on +# `_cluster.ingress-enabled` for the same reason: with ingress off on the +# root Tenant there is no ingress-nginx-system in tenant-root, and +# seaweedfs would wait on it forever. `seaweedfs` follows +# `_cluster.seaweedfs-enabled`, so tenants do not inherit an S3 the root +# tenant does not run. The fixtures below pin both halves of each contract. tests: - it: omits _namespace.gateway when _cluster.gateway-enabled is missing (default) asserts: @@ -102,7 +103,7 @@ tests: path: stringData["values.yaml"] pattern: '(?m)^\s+seaweedfs: tenant-root$' - - it: keeps _namespace.{etcd,ingress,monitoring,seaweedfs} unconditional when Gateway is off — regression guard for a refactor that accidentally gates them on the same flag + - it: keeps _namespace.{etcd,ingress,monitoring} when Gateway is off — regression guard for a refactor that accidentally gates them on the same flag asserts: - matchRegex: path: stringData["values.yaml"] @@ -113,11 +114,8 @@ tests: - matchRegex: path: stringData["values.yaml"] pattern: '(?m)^\s+monitoring: tenant-root$' - - matchRegex: - path: stringData["values.yaml"] - pattern: '(?m)^\s+seaweedfs: tenant-root$' - - it: keeps _namespace.{etcd,ingress,monitoring,seaweedfs} unconditional when Gateway is on — same guard, opposite mode + - it: keeps _namespace.{etcd,ingress,monitoring} when Gateway is on — same guard, opposite mode set: _cluster: gateway-enabled: "true" @@ -131,6 +129,9 @@ tests: - matchRegex: path: stringData["values.yaml"] pattern: '(?m)^\s+monitoring: tenant-root$' + + - it: emits _namespace.seaweedfs=tenant-root when _cluster.seaweedfs-enabled is missing + asserts: - matchRegex: path: stringData["values.yaml"] pattern: '(?m)^\s+seaweedfs: tenant-root$' @@ -143,3 +144,51 @@ tests: - notMatchRegex: path: stringData["values.yaml"] pattern: '(?m)^\s+ingress:' + + - it: emits _namespace.seaweedfs=tenant-root when _cluster.seaweedfs-enabled is "true" + set: + _cluster: + seaweedfs-enabled: "true" + asserts: + - matchRegex: + path: stringData["values.yaml"] + pattern: '(?m)^\s+seaweedfs: tenant-root$' + + - it: omits _namespace.seaweedfs when _cluster.seaweedfs-enabled is "false" + set: + _cluster: + seaweedfs-enabled: "false" + asserts: + - notMatchRegex: + path: stringData["values.yaml"] + pattern: '(?m)^\s+seaweedfs:' + - matchRegex: + path: stringData["values.yaml"] + pattern: '(?m)^\s+monitoring: tenant-root$' + + - it: omits _namespace.seaweedfs when _cluster.seaweedfs-enabled is a bool false + set: + _cluster: + seaweedfs-enabled: false + asserts: + - notMatchRegex: + path: stringData["values.yaml"] + pattern: '(?m)^\s+seaweedfs:' + + - it: omits _namespace.seaweedfs when _cluster.seaweedfs-enabled is null + set: + _cluster: + seaweedfs-enabled: null + asserts: + - notMatchRegex: + path: stringData["values.yaml"] + pattern: '(?m)^\s+seaweedfs:' + + - it: omits _namespace.seaweedfs when _cluster.seaweedfs-enabled is neither missing nor true + set: + _cluster: + seaweedfs-enabled: "no" + asserts: + - notMatchRegex: + path: stringData["values.yaml"] + pattern: '(?m)^\s+seaweedfs:'