Skip to content

Commit 4f9c20c

Browse files
fix(backupstrategy-controller): gate the default MongoDB strategy on bootstrap
A fresh install of packages/system/backupstrategy-controller fails permanently and applies nothing: Helm install failed for release cozy-backup-controller/backupstrategy-controller resource mapping not found for name: "cozy-default-mongodb" no matches for kind "MongoDB" in version "strategy.backups.cozystack.io/v1alpha1" The chart ships its own strategy.backups.cozystack.io CRDs as ordinary templates (templates/crds.yaml globs definitions/*.yaml), and Helm resolves every document in a release manifest through the cluster's RESTMapper in Build() before it applies any of them. An ungated Strategy CR therefore has no mapping on the first install, Build() fails, and the release applies ZERO objects, including the CRDs that would have made the mapping resolve. Nothing recovers: every retry renders the same manifest, so this is permanent rather than a race, and Helm's kind sorter cannot help because it orders the apply, not the Build. The seven sibling strategies never hit this because each gates on a resolved $bucketName, which is empty until the COSI BucketClaim status is reconciled. That gate is documented as "the CR needs the bucket name", and it silently doubles as the CRD-ordering guard. MongoDB genuinely does not need the bucket name, so the gate was left off and the accidental protection went with it. Gate it too, for the ordering reason rather than the value, and record that reason in the template so the next bucket-independent strategy keeps the gate. Convergence is unchanged: DefaultObjectsGate already routes apps.cozystack.io/MongoDB to cozy-default-mongodb and forces a second revision once any routed object is missing, which is how the seven siblings materialise today. Verified by rendering both windows. Before: the bootstrap render emits one Strategy, MongoDB, alongside the eight not-yet-applied CRDs. After: it emits none, and with backupStorage.bucketNameOverride set it emits all eight. tests/rendering_test.yaml asserted count: 1 for MongoDB under a case named "bootstrap window (no resolvable bucket name)", so the defect was codified green. helm-unittest has no RESTMapper and cannot see it. Assisted-By: Claude <[email protected]> Signed-off-by: Myasnikov Daniil <[email protected]>
1 parent 15459c9 commit 4f9c20c

2 files changed

Lines changed: 33 additions & 8 deletions

File tree

‎packages/system/backupstrategy-controller/templates/strategy-mongodb-default.yaml‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,34 @@
44
Percona psmdb operator resolves the on-demand backup's storageName against
55
the source PerconaServerMongoDB CR's spec.backup.storages, so the S3 target
66
lives on the MongoDB application (declared by the chart as "s3-storage" when
7-
backup.enabled=true), not here. That makes this template independent of the
8-
COSI BucketClaim, so it renders unconditionally — there is nothing to gate on
9-
a populated $bucketName.
7+
backup.enabled=true), not here.
8+
9+
It is gated on $bucketName all the same, and NOT because it needs the value.
10+
The gate is what keeps this chart installable on a fresh cluster. This chart
11+
ships its own strategy.backups.cozystack.io CRDs as ordinary templates
12+
(templates/crds.yaml globs definitions/*.yaml), and Helm resolves every
13+
document in a release manifest through the cluster's RESTMapper in Build()
14+
BEFORE it applies any of them. An ungated Strategy CR therefore has no
15+
mapping on the first install, Build() fails with "no matches for kind", and
16+
the release applies ZERO objects — including the CRDs that would have made
17+
the mapping resolve. Nothing recovers from that: every retry renders the same
18+
manifest, so the failure is permanent rather than a race, and Helm's kind
19+
sorter cannot help because it orders the apply, not the Build.
20+
21+
So every default Strategy in this chart must be absent from the first render.
22+
$bucketName is empty until the COSI BucketClaim status is reconciled (see
23+
templates/_helpers.tpl), which is exactly the window where the CRDs are being
24+
applied; by the time DefaultObjectsGate forces a second revision the CRDs
25+
exist and the mapping resolves. The seven sibling strategies got this for
26+
free by needing the bucket name. This one has to ask for it.
1027

1128
Precondition (surfaced by the driver as a clear Ready=False, not a silent
1229
hang): the MongoDB application must be deployed with backup.enabled=true so
1330
the percona-backup-mongodb agents run and the "s3-storage" entry exists. See
1431
docs/operations/backup-classes.md.
1532
*/}}
33+
{{- $bucketName := include "backupstrategy-controller.bucketName" . -}}
34+
{{- if $bucketName -}}
1635
apiVersion: strategy.backups.cozystack.io/v1alpha1
1736
kind: MongoDB
1837
metadata:
@@ -22,3 +41,4 @@ spec:
2241
storageName: s3-storage
2342
type: logical
2443
compressionType: gzip
44+
{{- end -}}

‎packages/system/backupstrategy-controller/tests/rendering_test.yaml‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,17 @@ tests:
5050
- hasDocuments:
5151
count: 0
5252
template: templates/strategy-altinity-default.yaml
53-
# MongoDB is the exception: its Strategy carries no bucket coordinates
54-
# (the S3 target lives on the MongoDB application's spec.backup, the
55-
# driver only names the storage), so it renders unconditionally — there
56-
# is nothing to gate on a resolved $bucketName.
53+
# MongoDB is gated like every sibling, and this count is the assertion
54+
# that keeps the chart installable. Its Strategy needs no bucket
55+
# coordinates (the S3 target lives on the MongoDB application's
56+
# spec.backup, the driver only names the storage), so the gate is there
57+
# purely for ordering: this chart ships its own CRDs as templates, Helm
58+
# resolves the whole manifest through the RESTMapper before applying any
59+
# of it, and one ungated Strategy CR makes the first install apply zero
60+
# objects with "no matches for kind" and never recover. A count of 1 here
61+
# is that bug, green, which is how it shipped once already.
5762
- hasDocuments:
58-
count: 1
63+
count: 0
5964
template: templates/strategy-mongodb-default.yaml
6065
- hasDocuments:
6166
count: 0

0 commit comments

Comments
 (0)