Files
cozystack/packages/system/backupstrategy-controller/tests/default_objects_gate_test.yaml
T
Mattia Eleuteri 51ad226706 fix(backupstrategy-controller): repair lookup-gated backup objects
The default Strategy CRs and the Velero BackupStorageLocation are
Helm-templated behind a `lookup` of the BucketClaim the same chart
creates, and the <bucket>-<user>-credentials Secret behind a `lookup` of
the COSI Secret. When those lookups are empty at install time the objects
were silently skipped, and helm-controller does not re-render a release
whose chart and values did not change (drift detection is off on
operator-generated HelmReleases), so the skip was permanent: clusters ran
for months with only BackupClass cozy-default and no Strategy CRs at all.
That also fail-closes the pre-adoption snapshot in the v1.6.0 etcd
migration, which reads the projected credentials Secret.

Add a DefaultObjectsGate runnable to backupstrategy-controller. Once the
bucket name is resolvable from the projector's source Secret, it checks
that every object cozy-default routes to exists and forces one real Helm
upgrade (reconcile.fluxcd.io/forceAt + requestedAt) when any is missing.
Helm remains the objects' only author; the gate only makes sure the render
that produces them actually happens. It cannot be a render-time `fail` in
this chart: the chart is the producer of the Bucket its own lookup reads,
so a failed render would deadlock the condition.

The bucket chart's user-credentials template CAN fail safely — the
BucketAccess that produces the COSI Secret belongs to the parent release
and that release retries forever — so make it fail loudly instead of
skipping, with requireUserCredentials=false as the offline-render escape.

Also correct the chart and doc comments that claimed Flux re-renders on
its interval, and document the two-release manual recovery for clusters
already affected.

Signed-off-by: Mattia Eleuteri <mattia@hidora.io>
2026-08-03 17:16:55 +02:00

92 lines
3.3 KiB
YAML

suite: DefaultObjectsGate wiring — the release the gate forces, and its RBAC
# The Strategy CRs and the Velero BSL are rendered behind a `lookup` of the
# BucketClaim this same chart creates, so a fresh install renders them empty
# and helm-controller never re-renders (unchanged chart + values, drift
# detection off) — the skip is permanent. The controller's DefaultObjectsGate
# repairs that by forcing a real Helm upgrade on THIS release, so the release
# coordinates it is given must be this chart's own release, and it must hold
# the verbs to do it.
templates:
- templates/deployment.yaml
- templates/rbac.yaml
release:
name: backupstrategy-controller
namespace: cozy-backup-controller
tests:
- it: "gate targets this chart's own HelmRelease and the cozy-default BackupClass"
template: templates/deployment.yaml
asserts:
- contains:
path: spec.template.spec.containers[0].env
content:
name: BACKUP_DEFAULT_OBJECTS_HELMRELEASE_NAME
value: backupstrategy-controller
- contains:
path: spec.template.spec.containers[0].env
content:
name: BACKUP_DEFAULT_OBJECTS_HELMRELEASE_NAMESPACE
value: cozy-backup-controller
- contains:
path: spec.template.spec.containers[0].env
content:
name: BACKUP_DEFAULT_OBJECTS_BACKUPCLASS
value: cozy-default
- contains:
path: spec.template.spec.containers[0].env
content:
name: BACKUP_DEFAULT_OBJECTS_VELERO_NAMESPACE
value: cozy-velero
- it: "velero.bslEnabled=false: the BSL is not rendered, so the gate must not look for it"
template: templates/deployment.yaml
set:
velero.bslEnabled: false
asserts:
- notContains:
path: spec.template.spec.containers[0].env
content:
name: BACKUP_DEFAULT_OBJECTS_VELERO_NAMESPACE
value: cozy-velero
# The rest of the gate stays wired: the Strategy CRs still need it.
- contains:
path: spec.template.spec.containers[0].env
content:
name: BACKUP_DEFAULT_OBJECTS_HELMRELEASE_NAME
value: backupstrategy-controller
- it: "reconcileDefaultObjects=false: the gate is fully unwired (main.go disables it on an empty release name)"
template: templates/deployment.yaml
set:
backupStorage.reconcileDefaultObjects: false
asserts:
- notContains:
path: spec.template.spec.containers[0].env
content:
name: BACKUP_DEFAULT_OBJECTS_HELMRELEASE_NAME
value: backupstrategy-controller
- notContains:
path: spec.template.spec.containers[0].env
content:
name: BACKUP_DEFAULT_OBJECTS_BACKUPCLASS
value: cozy-default
- it: "ClusterRole grants patch on helmreleases (forceAt stamp) and get on backupstoragelocations"
template: templates/rbac.yaml
asserts:
- contains:
path: rules
content:
apiGroups: ["helm.toolkit.fluxcd.io"]
resources: ["helmreleases"]
verbs: ["get", "create", "update", "patch", "delete"]
- contains:
path: rules
content:
apiGroups: ["velero.io"]
resources: ["backupstoragelocations"]
verbs: ["get"]