Strip managedFields from cached objects - #5108
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Reduces the Tigera operator’s in-memory footprint by stripping metadata.managedFields from objects as they enter the shared controller-runtime informer cache, without changing any on-cluster resources or behavior.
Changes:
- Configure the manager’s cache with
DefaultTransform: cache.TransformStripManagedFields()to dropmanagedFieldsat cache ingest time. - Add the controller-runtime
pkg/cacheimport to support the new cache option.
caseydavenport
approved these changes
Jul 24, 2026
Cached objects are only read by the operator's own controllers, which never consult managedFields. Setting the cache's DefaultTransform to TransformStripManagedFields drops that metadata at informer ingest time. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
alexh-tigera
force-pushed
the
strip-managedfields
branch
from
July 27, 2026 21:48
0232ac1 to
3b80f89
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Performance enhancement (memory) — no functional change.
Sets
DefaultTransform: cache.TransformStripManagedFields()on the manager's informer cache incmd/main.go, droppingmetadata.managedFieldsfrom every object at informer ingest time.The operator's controllers never consult managedFields: there are no readers of
ManagedFieldsanywhere in the codebase, and the operator does no server-side apply (noFieldManager/ApplyPatchTypeusage), which is the only write pattern that consumes field-ownership data at runtime. The change is read-side only — anUpdatethat carries empty managedFields leaves the server-side tracking untouched, so nothing changes in etcd orkubectloutput; only the operator's in-memory copies shrink.This is the documented intended use of the API: the controller-runtime godoc for
TransformStripManagedFieldsnotes that "setting this asDefaultTransformon the cache can lead to a significant reduction in memory usage", andOptions.DefaultTransformcalls it out as the typical use case.Measured impact — envtest micro-benchmark (kube-apiserver 1.34.1, controller-runtime v0.24.1; same method as #5082): a cluster-wide informer cache over N namespaces × (2 Secrets + 1 ConfigMap + 1 Service, 2 KiB payloads, two field managers per object), heap read after 2× GC, runs identical except for
DefaultTransform:Savings are a stable ~750 B HeapInuse (~505 B live heap) per cached object and scale linearly with cache size. Serialized, managedFields accounted for 19.5% of Secret bytes, 14.3% of ConfigMap, and 52.2% of Service in this workload. The numbers are conservative: benchmark objects carry two field managers, while objects touched by
kubectl applyplus controllers typically carry more.Testing:
make ut— all 82 suites pass with the transform active.Affected components: the shared manager cache — i.e. every controller's cached reads (Calico and Enterprise).
Related: #5082 (informer cache memory work whose measurement method this replicates).
Release Note
For PR author
make gen-filesmake gen-versionsFor PR reviewers
A note for code reviewers - all pull requests must have the following:
kind/bugif this is a bugfix.kind/enhancementif this is a a new feature.enterpriseif this PR applies to Calico Enterprise only.