Files
cozystack/packages/system/backupstrategy-controller/tests/endpoint_form_test.yaml
T
Andrey Kolkov 9545bee233 fix(mongodb): correct system-bucket prose, pin strategy rendering, make restore credential swap flow-aware
Several comments and the useSystemBucket field description had drifted from
what the code does.

The strategy header still said the $bucketName gate was "not because it
needs the value" and that the sibling strategies needed the bucket name
while this one only asked for ordering, but the strategy now renders
bucket: {{ $bucketName }} for the injected coordinates, so it needs the
value; the precondition comment claimed the s3-storage entry exists on
backup.enabled=true, which is only the legacy flow. The rendering-test
comment carried the same "needs no bucket coordinates" claim. The
useSystemBucket field description said injection happens "at first BackupJob
time" (it now runs on every BackupJob) and that backups scope to
<namespace>/<release> (the prefix templates the application name, not the
release), and it ran ~700 chars of implementation detail into the CRD that
backup-classes.md already carries; trimmed and corrected, then regenerated
schema/README/types/cozyrds. Same <release> slip fixed in the driver
comment and the docs.

Nothing asserted the new strategy rendering. Added the MongoDB row to the
endpoint-form suite (s3.endpointUrl, scheme preserved both ways) and field
assertions to the rendering suite — bucket, endpointUrl, region,
credentialsSecret, forcePathStyle, and prefix, which must reach the CR as a
literal go-template string so the driver can template it per-application;
a stray brace would empty it with every doc-count test still green.

The restore credential swap broke across flows. It replaced the source
credentialsSecret with whatever the target declared, comparing no buckets,
so a system-bucket backup restored into a legacy target kept the platform
bucket against the tenant's own -s3-creds, and a legacy backup restored
into a system-bucket target got cozy-backups-creds against the tenant
bucket - both AccessDenied. Skip the swap when the source already names the
platform-projected cozy-backups-creds (it outlives the source app, nothing
to repair), and only adopt a target credential whose storage is on the
same bucket as the archive. psmdbStorageS3 now reads .s3.bucket alongside
.s3.credentialsSecret; TestPsmdbTargetCredentialsSecret covers the match,
the cross-bucket refusal, and the empty-bucket no-op.

Also drop the post-apply re-Get: the typed SSA Patch decodes the server's
merged object back into the passed struct, so the precondition reads the
injected storage from it instead of a follow-up Get that hit the informer
cache and briefly reported Ready=False on the happy path.

Signed-off-by: Andrey Kolkov <androndo@gmail.com>
Assisted-By: LLM
2026-09-22 12:03:58 +04:00

106 lines
4.3 KiB
YAML

suite: endpoint scheme → per-driver derivations (TLS / secure_connection / scheme stripping)
# The S3 endpoint is resolved by the "backupstrategy-controller.endpoint"
# helper and shared by every driver: CNPG/Etcd want a full URL (scheme
# included), MariaDB/FoundationDB want a bare host:port and derive their secure
# flag from the scheme, and the Velero BSL wants a full URL. Flipping
# http<->https must flip tls.enabled / secure_connection without leaking the
# scheme into the host fields, and must reach every consumer identically.
#
# NOTE: the provisionBucket:true derivation (read the external ACME endpoint
# from the COSI system Secret and force https://) uses `lookup`, which returns
# nothing under `helm template` / helm-unittest. These offline tests therefore
# exercise the FALLBACK path — where the helper returns
# .Values.backupStorage.endpoint verbatim — which is exactly what runs on the
# pre-reconcile first install and for external S3 (provisionBucket:false).
templates:
- templates/strategy-etcd-default.yaml
- templates/strategy-cnpg-default.yaml
- templates/strategy-mariadb-default.yaml
- templates/strategy-foundationdb-default.yaml
- templates/strategy-mongodb-default.yaml
- templates/velero-bsl.yaml
release:
name: t
namespace: cozy-backup-controller
set:
# a resolvable bucket name so the gated strategies render at all
backupStorage.bucketNameOverride: test-bucket
tests:
- it: "https endpoint: full URL reaches CNPG/Etcd/Velero; MariaDB TLS on, FDB secure_connection=1, scheme stripped from host fields"
set:
backupStorage.endpoint: https://s3.example.com:8333
asserts:
- equal:
path: spec.template.destination.s3.endpoint
value: https://s3.example.com:8333
template: templates/strategy-etcd-default.yaml
- equal:
path: spec.template.barmanObjectStore.endpointURL
value: https://s3.example.com:8333
template: templates/strategy-cnpg-default.yaml
- equal:
path: spec.config.s3Url
value: https://s3.example.com:8333
template: templates/velero-bsl.yaml
- equal:
path: spec.template.storage.s3.endpoint
value: s3.example.com:8333
template: templates/strategy-mariadb-default.yaml
- equal:
path: spec.template.storage.s3.tls.enabled
value: true
template: templates/strategy-mariadb-default.yaml
- equal:
path: spec.template.blobStoreConfiguration.accountName
value: s3.example.com:8333
template: templates/strategy-foundationdb-default.yaml
- contains:
path: spec.template.blobStoreConfiguration.urlParameters
content: secure_connection=1
template: templates/strategy-foundationdb-default.yaml
- equal:
path: spec.template.s3.endpointUrl
value: https://s3.example.com:8333
template: templates/strategy-mongodb-default.yaml
- it: "http endpoint: MariaDB TLS off, FDB secure_connection=0, Etcd keeps scheme"
set:
backupStorage.endpoint: http://s3.example.com:8333
asserts:
- equal:
path: spec.template.destination.s3.endpoint
value: http://s3.example.com:8333
template: templates/strategy-etcd-default.yaml
- equal:
path: spec.template.storage.s3.tls.enabled
value: false
template: templates/strategy-mariadb-default.yaml
- contains:
path: spec.template.blobStoreConfiguration.urlParameters
content: secure_connection=0
template: templates/strategy-foundationdb-default.yaml
- equal:
path: spec.template.s3.endpointUrl
value: http://s3.example.com:8333
template: templates/strategy-mongodb-default.yaml
- it: "external S3 (provisionBucket:false): endpoint is used verbatim (no derivation)"
set:
backupStorage.provisionBucket: false
backupStorage.bucketName: ext-bucket
backupStorage.endpoint: https://minio.example.internal:9000
asserts:
- equal:
path: spec.template.destination.s3.endpoint
value: https://minio.example.internal:9000
template: templates/strategy-etcd-default.yaml
- equal:
path: spec.config.s3Url
value: https://minio.example.internal:9000
template: templates/velero-bsl.yaml