Skip to content

Commit 6beca87

Browse files
authored
Restore ManagedFields to operator-controller cache (#2318)
The Boxcutter library uses ManagedFields internally, so we need to keep them around, at least in operator-controller. Catalogd can still strip them from its cache. Signed-off-by: Todd Short <[email protected]>
1 parent c8526e9 commit 6beca87

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

cmd/operator-controller/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func run() error {
234234
},
235235
DefaultLabelSelector: k8slabels.Nothing(),
236236
// Memory optimization: strip managed fields and large annotations from cached objects
237-
DefaultTransform: cacheutil.StripManagedFieldsAndAnnotations(),
237+
DefaultTransform: cacheutil.StripAnnotations(),
238238
}
239239

240240
if features.OperatorControllerFeatureGate.Enabled(features.BoxcutterRuntime) {

internal/operator-controller/applier/boxcutter.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ func (r *SimpleRevisionGenerator) GenerateRevisionFromHelmRelease(
6666
obj.SetLabels(labels)
6767
obj.SetOwnerReferences(nil) // reset OwnerReferences for migration.
6868

69-
// Memory optimization: strip large annotations and managed fields
69+
// Memory optimization: strip large annotations
7070
// Note: ApplyStripTransform never returns an error in practice
71-
_ = cache.ApplyStripTransform(&obj)
71+
_ = cache.ApplyStripAnnotationsTransform(&obj)
7272

7373
objs = append(objs, ocv1.ClusterExtensionRevisionObject{
7474
Object: obj,
@@ -118,8 +118,8 @@ func (r *SimpleRevisionGenerator) GenerateRevision(
118118
unstr := unstructured.Unstructured{Object: unstrObj}
119119
unstr.SetGroupVersionKind(gvk)
120120

121-
// Memory optimization: strip large annotations and managed fields
122-
if err := cache.ApplyStripTransform(&unstr); err != nil {
121+
// Memory optimization: strip large annotations
122+
if err := cache.ApplyStripAnnotationsTransform(&unstr); err != nil {
123123
return nil, err
124124
}
125125

internal/shared/util/cache/transform.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,34 @@ func StripManagedFieldsAndAnnotations() toolscache.TransformFunc {
5858
}
5959
}
6060

61-
// ApplyStripTransform applies the strip transform directly to an object.
61+
// StripAnnotations returns a cache transform function that removes
62+
// memory-heavy annotation fields that aren't needed for controller operations.
63+
// This significantly reduces memory usage in informer caches by removing:
64+
// - kubectl.kubernetes.io/last-applied-configuration annotation (can be very large)
65+
//
66+
// Use this function as a DefaultTransform in controller-runtime cache.Options
67+
// to reduce memory overhead across all cached objects.
68+
//
69+
// Example:
70+
//
71+
// cacheOptions := cache.Options{
72+
// DefaultTransform: cacheutil.StripAnnotations(),
73+
// }
74+
func StripAnnotations() toolscache.TransformFunc {
75+
return func(obj interface{}) (interface{}, error) {
76+
// Strip the large annotations
77+
return stripAnnotations(obj)
78+
}
79+
}
80+
81+
// ApplyStripAnnotationsTransform applies the strip transform directly to an object.
6282
// This is a convenience function for cases where you need to strip fields
6383
// from an object outside of the cache transform context.
6484
//
6585
// Note: This function never returns an error in practice, but returns error
6686
// to satisfy the TransformFunc interface.
67-
func ApplyStripTransform(obj client.Object) error {
68-
transform := StripManagedFieldsAndAnnotations()
87+
func ApplyStripAnnotationsTransform(obj client.Object) error {
88+
transform := StripAnnotations()
6989
_, err := transform(obj)
7090
return err
7191
}

0 commit comments

Comments
 (0)