Repository navigation
fix(backupstrategy-controller): gate the default MongoDB strategy on bootstrap - #3815
Conversation
…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]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe MongoDB default strategy template now requires a resolved bucket name before rendering. The bootstrap rendering test now expects zero documents when the bucket name is unavailable. ChangesMongoDB strategy bootstrap
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The change gates the default MongoDB strategy during bootstrap to prevent fresh installs from failing before its CRDs are available; no actionable merge-blocking risk remains after normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Aleksei Sviridkin (lexfrei)
left a comment
There was a problem hiding this comment.
No blockers, this fixes it. I rendered the chart with the lookup unresolved at the merge base and at this head: the base emits exactly one strategy CR, MongoDB/cozy-default-mongodb, in the same manifest as the CRDs that would map it, and this head emits none. All eight come back once a bucket name resolves. Removing the gate again turns the flipped assertion red on that template alone, so it catches a revert.
Two things I would not block on.
With provisionBucket: false the helper returns the configured bucket name right away, so all eight strategies still render on the first install and the ordering problem is untouched in that configuration. Same before and after this PR, so not yours to fix here, but the template comment reads wider than the gate actually reaches.
On a cluster whose BucketClaim never resolved, upgrading drops an existing cozy-default-mongodb, since it is the one strategy that worked without a bucket name. The gate puts it back as soon as the bucket resolves.
What this PR does
Closes #3814.
Unblocks a fresh install of
main. Since #3562 thebackupstrategy-controllerchart renders one default Strategy CR ungated, and that makes the whole release fail on a cluster where its CRDs are not yet applied:The chart ships its own eight
strategy.backups.cozystack.ioCRDs as ordinary templates, sincetemplates/crds.yamlglobsdefinitions/*.yaml, and Helm pre-applies only acrds/directory. Helm then resolves every document in the release manifest through the cluster's RESTMapper inBuild()before it applies any of them, so an ungated Strategy CR 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 from that. Every retry renders the same manifest, so it is permanent rather than a race, and Helm's kind sorter cannot help because it orders the apply and the failure is before the apply. The install log shows
Warning InstallFailed 43s (x36 over 20m)and thenInstall failed (no retry).Why the seven siblings never hit this
Each of them gates on a resolved
$bucketName, which is empty until the COSI BucketClaim status is reconciled, so they are simply absent from the first render. By the timeDefaultObjectsGateforces a second revision the CRDs from revision 1 exist and the mapping resolves.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, the template argues that correctly, so the gate was left off and the accidental protection went with it. This gates it too, for the ordering reason rather than the value, and records that reason in the template so the next bucket-independent strategy keeps it.
Convergence is unchanged.
DefaultObjectsGatealready routesapps.cozystack.io/MongoDBtocozy-default-mongodband forces a revision once any routed object is missing, which is exactly how the seven siblings materialise today.Why this was invisible
tests/rendering_test.yamlassertedcount: 1for the MongoDB template under a case named "bootstrap window (no resolvable bucket name)", so the defect was codified as the expected behaviour and shipped green. helm-unittest has no RESTMapper and cannot see the consequence. That assertion is flipped here, with the ordering reason written next to it.It was also masked in CI until yesterday by #3806.
StreamVisitor.Visitreturns immediately on a validation error but only continues on a mapping error, so the OpenAPI defect aborted the manifest stream at the first document and the mapping check was never reached. #3808 fixed that and this surfaced underneath it.Screenshots
Not applicable.
Downstream repositories
Testing
Verified by rendering both windows, since the whole bug is which documents appear in the first render and a cluster adds nothing to that.
Before, bootstrap window: one Strategy document,
MongoDB, alongside the eight not-yet-applied CRDs. After: none. WithbackupStorage.bucketNameOverride=b, which stands in for a resolved BucketClaim: all eight, MongoDB included.helm unittest packages/system/backupstrategy-controllerpasses, 4 suites, 18 tests.Follow-up, not in this PR
The durable fix is to stop shipping these CRDs as templates and split
definitions/into abackupstrategy-controller-crdspackage with adependsOnedge, which is the convention six other packages already follow. That cannot be a hotfix: none of the eight definitions carrieshelm.sh/resource-policy: keep, so the upgrade that removes them from this chart's manifest would have Helm delete the eight CRDs and cascade-delete every live Strategy CR on existing clusters. It needs thekeepannotation shipped a release ahead.Release note
Summary by CodeRabbit
Bug Fixes
Tests