Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/operator-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func run() error {
},
DefaultLabelSelector: k8slabels.Nothing(),
// Memory optimization: strip managed fields and large annotations from cached objects
DefaultTransform: cacheutil.StripManagedFieldsAndAnnotations(),
DefaultTransform: cacheutil.StripAnnotations(),
}

if features.OperatorControllerFeatureGate.Enabled(features.BoxcutterRuntime) {
Expand Down
8 changes: 4 additions & 4 deletions internal/operator-controller/applier/boxcutter.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ func (r *SimpleRevisionGenerator) GenerateRevisionFromHelmRelease(
obj.SetLabels(labels)
obj.SetOwnerReferences(nil) // reset OwnerReferences for migration.

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

objs = append(objs, ocv1.ClusterExtensionRevisionObject{
Object: obj,
Expand Down Expand Up @@ -118,8 +118,8 @@ func (r *SimpleRevisionGenerator) GenerateRevision(
unstr := unstructured.Unstructured{Object: unstrObj}
unstr.SetGroupVersionKind(gvk)

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

Expand Down
26 changes: 23 additions & 3 deletions internal/shared/util/cache/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,34 @@ func StripManagedFieldsAndAnnotations() toolscache.TransformFunc {
}
}

// ApplyStripTransform applies the strip transform directly to an object.
// StripAnnotations returns a cache transform function that removes
// memory-heavy annotation fields that aren't needed for controller operations.
// This significantly reduces memory usage in informer caches by removing:
// - kubectl.kubernetes.io/last-applied-configuration annotation (can be very large)
//
// Use this function as a DefaultTransform in controller-runtime cache.Options
// to reduce memory overhead across all cached objects.
//
// Example:
//
// cacheOptions := cache.Options{
// DefaultTransform: cacheutil.StripAnnotations(),
// }
func StripAnnotations() toolscache.TransformFunc {
return func(obj interface{}) (interface{}, error) {
// Strip the large annotations
return stripAnnotations(obj)
}
}

// ApplyStripAnnotationsTransform applies the strip transform directly to an object.
// This is a convenience function for cases where you need to strip fields
// from an object outside of the cache transform context.
//
// Note: This function never returns an error in practice, but returns error
// to satisfy the TransformFunc interface.
func ApplyStripTransform(obj client.Object) error {
transform := StripManagedFieldsAndAnnotations()
func ApplyStripAnnotationsTransform(obj client.Object) error {
transform := StripAnnotations()
_, err := transform(obj)
return err
}
Loading