feat: add TransformStripCRDSchema for reduced cache memory usage - #1058
Conversation
Signed-off-by: rafal-jan <rafal7jan@gmail.com>
📝 WalkthroughWalkthroughAdds a CRD cache transform that removes OpenAPI schemas and selected metadata while preserving non-CRD objects, with table-driven tests covering normal and edge cases. ChangesCRD cache transform
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/reconciler/customresourcesgate/cache_test.go`:
- Around line 241-243: Update the error comparison in the test around
TransformStripCRDSchema to pass cmpopts.EquateErrors() to cmp.Diff, and add the
corresponding github.com/google/go-cmp/cmp/cmpopts import while preserving the
existing error assertion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 0faf12c1-76d1-41f3-a1f9-fa0317e2e768
📒 Files selected for processing (2)
pkg/reconciler/customresourcesgate/cache.gopkg/reconciler/customresourcesgate/cache_test.go
…rror comparison Signed-off-by: rafal-jan <rafal7jan@gmail.com>
bobh66
left a comment
There was a problem hiding this comment.
This LGTM but I'm far from an expert in this area, so might want someone else to take a look.
|
Hi @rafal-jan thank you for contributing the PR! I've done a short safety verification against consumers of this code -
From my perspective it's ok to get this merged in the current state |
|
/backport |
|
Successfully created backport PR for |
Description of your changes
Fixes #1056
I have:
./nix.sh flake checkto ensure this PR is ready for review.backport release-x.ylabels to auto-backport this PR.Need help with this checklist? See the cheat sheet.
This PR introduces a new cache optimization function,
TransformStripCRDSchema, to reduce the memory footprint of Crossplane providers that watch CustomResourceDefinition (CRD) objects.By default, the controller-runtime cache stores the entire schema for every watched object. For clusters with a massive number of CRDs storing the OpenAPI v3 validation schemas in the informer cache leads to significant memory bloat (hundreds of megabytes per provider pod).
TransformStripCRDSchemais acache.TransformFuncthat safely strips the following fields from CRD objects before they enter the informer cache:Spec.Versions[].Schema(OpenAPI v3 validation schemas)ObjectMeta.ManagedFieldskubectl.kubernetes.io/last-applied-configurationannotationProviders can leverage this by wiring it into their manager's
cache.Options.ByObjectconfiguration. Since most controllers (like the CRD gate) only require basic metadata, group/version/kind names, and status conditions to function correctly, stripping these heavy fields is completely safe.How has this been tested?
pkg/reconciler/customresourcesgate/cache_test.goverifying that schemas, specific annotations, and managed fields are correctly stripped while leaving all other data and non-CRD objects intact.provider-template. Testing a provider against a cluster with 2,045 Upjet AWS CRDs showed controller memory usage dropping from ~630 MiB down to ~83 MiB after applying this cache transform.