crbench//

← all cases

Trim managedFields in the controller-manager and scheduler informer transforms

Tier 2 hard go · cross-file · real merged PR from kubernetes/kubernetes #118455

Ground-truth defects

d1 · correctness · high
The informer transform `trim` calls `accessor.SetManagedFields(nil)` unconditionally on every resync, mutating the object that lives in the shared informer cache. Because that cached object is read concurrently by other informer consumers, the unconditional in-place mutation is a data race that can panic kube-controller-manager / scheduler. The fix guards it (`if accessor.GetManagedFields() != nil`) so the transform is idempotent and does not rewrite shared state when already trimmed.

The change under review

diff (truncated — full diff)
diff --git a/cmd/kube-controller-manager/app/controllermanager.go b/cmd/kube-controller-manager/app/controllermanager.go
index e0ebfc9dbba61..daa2020727038 100644
--- a/cmd/kube-controller-manager/app/controllermanager.go
+++ b/cmd/kube-controller-manager/app/controllermanager.go
@@ -29,6 +29,7 @@ import (
 
 	"github.com/spf13/cobra"
 
+	"k8s.io/apimachinery/pkg/api/meta"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/apimachinery/pkg/runtime/schema"
 	utilruntime "k8s.io/apimachinery/pkg/util/runtime"
@@ -524,11 +525,19 @@ func GetAvailableResources(clientBuilder clientbuilder.ControllerClientBuilder)
 // controllers such as the cloud provider and clientBuilder. rootClientBuilder is only used for
 // the shared-informers client and token controller.
 func CreateControllerContext(logger klog.Logger, s *config.CompletedConfig, rootClientBuilder, clientBuilder clientbuilder.ControllerClientBuilder, stop <-chan struct{}) (ControllerContext, error) {
+	// Informer transform to trim ManagedFields for memory efficiency.
+	trim := func(obj interface{}) (interface{}, error) {
+		if accessor, err := meta.Accessor(obj); err == nil {
+			accessor.SetManagedFields(nil)
+		}
+		return obj, nil
+	}
+
 	versionedClient := rootClientBuilder.ClientOrDie("shared-informers")
-	sharedInformers := informers.NewSharedInformerFactory(versionedClient, ResyncPeriod(s)())
+	sharedInformers := informers.NewSharedInformerFactoryWithOptions(versionedClient, ResyncPeriod(s)(), informers.WithTransform(trim))
 
 	metadataClient := metadata.NewForConfigOrDie(rootClientBuilder.ConfigOrDie("metadata-informers"))
-	metadataInformers := metadatainformer.NewSharedInformerFactory(metadataClient, ResyncPeriod(s)())
+	metadataInformers := metadatainformer.NewSharedInformerFactoryWithOptions(metadataClient, ResyncPeriod(s)(), metadatainformer.WithTransform(trim))
 
 	// If apiserver is not running we should wait for some time and fail only then. This is particularly
 	// important when we start apiserver and controller manager at the same time.
diff --git a/staging/src/k8s.io/apiextensions-apiserver/examples/client-go/pkg/client/informers/externalversions/factory.go b/staging/src/k8s.io/apiextensions-apiserver/examples/client-go/pkg/client/informers/externalversions/factory.go
index b68c739709fcc..6c473339eee66 100644
--- a/staging/src/k8s.io/apiextensions-apiserver/examples/client-go/pkg/client/informers/externalversions/factory.go
+++ b/staging/src/k8s.io/apiextensions-apiserver/examples/client-go/pkg/client/informers/externalversions/factory.go
@@ -42,6 +42,7 @@ type sharedInformerFactory struct {
 	lock             sync.Mutex
 	defaultResync    time.Duration
 	customResync     map[reflect.Type]time.Duration
+	transform        cache.TransformFunc
 
 	informers map[reflect.Type]cache.SharedIndexInformer
 	// startedInformers is used for tracking which informers have been started.
@@ -80,6 +81,14 @@ func WithNamespace(namespace string) SharedInformerOption {
 	}
 }
 
+// WithTransform sets a transform on all informers.
+func WithTransform(transform cache.TransformFunc) SharedInformerOption {
+	return func(factory *sharedInformerFactory) *sharedInformerFactory {
+		factory.transform = transform
+		return factory
+	}
+}
+
 // NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces.
 func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory {
 	return NewSharedInformerFactoryWithOptions(client, defaultResync)
@@ -184,6 +193,7 @@ func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internal
 	}
 
 	informer = newFunc(f.client, resyncPeriod)
+	informer.SetTransform(f.transform)
 	f.informers[informerType] = informer
 
 	return informer
diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions/factory.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions/factory.go
index 9ccfd710c9c53..90319bd215a76 100644
--- a/staging/src/k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions/factory.go
+++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions/factory.go
@@ -42,6 +42,7 @@ type sharedInformerFactory struct {
 	lock             sync.Mutex
 	defaultResync    time.Duration
 	customResync     map[reflect.Type]time.Duration
+	transform        cache.TransformFunc
 
 	informers map[reflect.Type]cache.SharedIndexInformer
 	// startedInformers is used for tracking which informers have been started.
@@ -80,6 +81,14 @@ func WithNamespace(namespace string) SharedInformerOption {
 	}
 }
 
+// WithTransform sets a transform on all informers.
+func WithTransform(transform cache.TransformFunc) SharedInformerOption {
+	return func(factory *sharedInformerFactory) *sharedInformerFactory {
+		factory.transform = transform
+		return factory
+	}
+}
+
 // NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces.
 func NewSharedInformerFactory(client clientset.Interface, defaultResync time.Duration) SharedInformerFactory {
 	return NewSharedInformerFactoryWithOptions(client, defaultResync)
@@ -184,6 +193,7 @@ func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internal
 	}
 
 	informer = newFunc(f.client, resyncPeriod)
+	informer.SetTransform(f.transform)
 	f.informers[informerType] = informer
 
 	return informer
diff --git a/staging/src/k8s.io/client-go/informers/factory.go b/staging/src/k8s.io/client-go/informers/factory.go
index 7dd0ae6353cc6..9fc86441a192a 100644
--- a/staging/src/k8s.io/client-go/informers/factory.go
+++ b/staging/src/k8s.io/client-go/informers/factory.go
@@ -60,6 +60,7 @@ type sharedInformerFactory struct {
 	lock             sync.Mutex
 	defaultResync    time.Duration
 	customResync     map[reflect.Type]time.Duration
+	transform        cache.TransformFunc
 
 	informers map[reflect.Type]cache.SharedIndexInformer
 	// startedInformers is used for tracking which informers have been started.
@@ -98,6 +99,14 @@ func WithNamespace(namespace string) SharedInformerOption {
 	}
 }
 
+// WithTransform sets a transform on all informers.
+func WithTransform(transform cache.TransformFunc) SharedInformerOption {
+	return func(factory *sharedInformerFactory) *sharedInformerFactory {
+		factory.transform = transform
+		return factory
+	}
+}
+
 // NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces.
 func NewSharedInformerFactory(client kubernetes.Interface, defaultResync time.Duration) SharedInformerFactory {
 	return NewSharedInformerFactoryWithOptions(client, defaultResync)
@@ -202,6 +211,7 @@ func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internal
 	}
 
 	informer = newFunc(f.client, resyncPeriod)
+	informer.SetTransform(f.transform)
 	f.informers[informerType] = informer
 
 	return informer
diff --git a/staging/src/k8s.io/client-go/metadata/metadatainformer/informer.go b/staging/src/k8s.io/client-go/metadata/metadatainformer/informer.go
index c211a4b7294eb..ff3537e98e6a7 100644
--- a/staging/src/k8s.io/client-go/metadata/metadatainformer/informer.go
+++ b/staging/src/k8s.io/client-go/metadata/metadatainformer/informer.go
@@ -21,6 +21,7 @@ import (
 	"sync"
 	"time"
 
+	v1 "k8s.io/api/core/v1"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/apimachinery/pkg/runtime"
 	"k8s.io/apimachinery/pkg/runtime/schema"
@@ -31,6 +32,17 @@ import (
 	"k8s.io/client-go/tools/cache"
 )
 
+// SharedInformerOption defines the functional option type for metadataSharedInformerFactory.
+type SharedInformerOption func(*metadataSharedInformerFactory) *metadataSharedInformerFactory
+
+// WithTransform sets a transform on all informers.
+func WithTransform(transform cache.TransformFunc) SharedInformerOption {
+	return func(factory *metadataSharedInformerFactory) *metadataSharedInformerFactory {
+		factory.transform = transform
+		return factory
+	}
+}
+
 // NewSharedInformerFactory constructs a new instance of metadataSharedInformerFactory for all namespaces.
 func NewSharedInformerFactory(client metadata.Interface, defaultResync time.Duration) SharedInformerFactory {
 	return NewFilteredSharedInformerFactory(client, defaultResync, metav1.NamespaceAll, nil)
@@ -49,10 +61,29 @@ func NewFilteredSharedInformerFactory(client metadata.Interface, defaultResync t
 	}
 }
 
+// NewSharedInformerFactoryWithOptions constructs a new instance of metadataSharedInformerFactory with additional options.
+func NewSharedInformerFactoryWithOptions(client metadata.Interface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory {
+	factory := &metadataSharedInformerFactory{
+		client:           client,
+		namespace:        v1.NamespaceAll,
+		defaultResync:    defaultResync,
+		informers:        map[schema.GroupVersionResource]informers.GenericInformer{},
+		startedInformers: make(map[schema.GroupVersionResource]bool),
+	}
+
+	// Apply all options
+	for _, opt := range options {
+		factory = opt(factory)
+	}
+
+	return factory
+}
+
 type metadataSharedInformerFactory struct {
 	client        metadata.Interface
 	defaultResync time.Duration
 	namespace     string
+	transform     cache.TransformFunc
 
 	lock      sync.Mutex
 	informers map[schema.GroupVersionResource]informers.GenericInformer
@@ -80,6 +111,7 @@ func (f *metadataSharedInformerFactory) ForResource(gvr schema.GroupVersionResou
 	}
 
 	informer = NewFilteredMetadataInformer(f.client, gvr, f.namespace, f.defaultResync, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions)
+	informer.Informer().SetTransform(f.transform)
 	f.informers[key] = informer
 
 	return informer
diff --git a/staging/src/k8s.io/code-generator/cmd/informer-gen/generators/factory.go b/staging/src/k8s.io/code-generator/cmd/informer-gen/generators/factory.go
index f8ee7d070907c..4875393913b96 100644
--- a/staging/src/k8s.io/code-generator/cmd/informer-gen/generators/factory.go
+++ b/staging/src/k8s.io/code-generator/cmd/informer-gen/generators/factory.go
@@ -75,6 +75,7 @@ func (g *factoryGenerator) GenerateType(c *generator.Context, t *types.Type, w i
 	}
 	m := map[string]interface{}{
 		"cacheSharedIndexInformer":       c.Universe.Type(cacheSharedIndexInformer),
+		"cacheTransformFunc":             c.Universe.Type(cacheTransformFunc),
 		"groupVersions":                  g.groupVersions,
 		"gvInterfaces":                   gvInterfaces,
 		"gvNewFuncs":                     gvNewFuncs,
@@ -109,6 +110,7 @@ type sharedInformerFactory struct {
 	lock {{.syncMutex|raw}}
 	defaultResync {{.timeDuration|raw}}
 	customResync map[{{.reflectType|raw}}]{{.timeDuration|raw}}
+	transform {{.cacheTransformFunc|raw}}
 
 	informers map[{{.reflectType|raw}}]{{.cacheSharedIndexInformer|raw}}
 	// startedInformers is used for tracking which informers have been started.
@@ -147,6 +149,14 @@ func WithNamespace(namespace string) SharedInformerOption {
 	}
 }
 
+// WithTransform sets a transform on all informers.
+func WithTransform(transform {{.cacheTransformFunc|raw}}) SharedInformerOption {
+	return func(factory *sharedInformerFactory) *sharedInformerFactory {
+		factory.transform = transform
+		return factory
+	}
+}
+
 // NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces.
 func NewSharedInformerFactory(client {{.clientSetInterface|raw}}, defaultResync {{.timeDuration|raw}}) SharedInformerFactory {
 	return NewSharedInformerFactoryWithOptions(client, defaultResync)
@@ -252,11 +262,11 @@ func (f *sharedInformerFactory) InformerFor(obj {{.runtimeObject|raw}}, newFunc
   }
 
   informer = newFunc(f.client, resyncPeriod)
+  informer.SetTransform(f.transform)
   f.informers[informerType] = informer
 
   return informer
 }
-
 `
 
 var sharedInformerFactoryInterface = `
diff --git a/staging/src/k8s.io/code-generator/cmd/informer-gen/generators/types.go b/staging/src/k8s.io/code-generator/cmd/informer-gen/generators/types.go
index 27d4bd51ab125..fc1f7786f663b 100644
--- a/staging/src/k8s.io/code-generator/cmd/informer-gen/generators/types.go
+++ b/staging/src/k8s.io/code-generator/cmd/informer-gen/generators/types.go
@@ -28,6 +28,7 @@ var (
 	cacheNewGenericLister       = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "NewGenericLister"}
 	cacheNewSharedIndexInformer = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "NewSharedIndexInformer"}
 	cacheSharedIndexInformer    = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "SharedIndexInformer"}
+	cacheTransformFunc          = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "TransformFunc"}
 	listOptions                 = types.Name{Package: "k8s.io/kubernetes/pkg/apis/core", Name: "ListOptions"}
 	reflectType                 = types.Name{Package: "reflect", Name: "Type"}
 	runtimeObject               = types.Name{Package: "k8s.io/apimachinery/pkg/runtime", Name: "Object"}
diff --git a/staging/src/k8s.io/code-generator/examples/HyphenGroup/informers/externalversions/factory.go b/staging/src/k8s.io/code-generator/examples/HyphenGroup/informers/externalversions/factory.go
index 8697f881b210f..17c25f261a9c0 100644
--- a/staging/src/k8s.io/code-generator/examples/HyphenGroup/informers/externalversions/factory.go
+++ b/staging/src/k8s.io/code-generator/examples/HyphenGroup/informers/externalversions/factory.go
@@ -42,6 +42,7 @@ type sharedInformerFactory struct {
 	lock             sync.Mutex
 	defaultResync    time.Duration
 	customResync     map[reflect.Type]time.Duration
+	transform        cache.TransformFunc
 
 	informers map[reflect.Type]cache.SharedIndexInformer
 	// startedInformers is used for tracking which informers have been started.
@@ -80,6 +81,14 @@ func WithNamespace(namespace string) SharedInformerOption {
 	}
 }
 
+// WithTransform sets a transform on all informers.
+func WithTransform(transform cache.TransformFunc) SharedInformerOption {
+	return func(factory *sharedInformerFactory) *sharedInformerFactory {
+		factory.transform = transform
+		return factory
+	}
+}
+
 // NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces.
 func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory {
 	return NewSharedInformerFactoryWithOptions(client, defaultResync)
@@ -184,6 +193,7 @@ func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internal
 	}
 
 	informer = newFunc(f.client, resyncPeriod)
+	informer.SetTransform(f.transform)
 	f.informers[informerType] = informer
 
 	return informer
diff --git a/staging/src/k8s.io/code-generator/examples/MixedCase/informers/externalversions/factory.go b/staging/src/k8s.io/code-generator/examples/MixedCase/informers/externalversions/factory.go
index 6aeb773e82e4d..9cefe3d0cc0d6 100644
--- a/staging/src/k8s.io/code-generator/examples/MixedCase/informers/externalversions/factory.go
+++ b/staging/src/k8s.io/code-generator/examples/MixedCase/informers/externalversions/factory.go
@@ -42,6 +42,7 @@ type sharedInformerFactory struct {
 	lock             sync.Mutex
 	defaultResync    time.Duration
 	customResync     map[reflect.Type]time.Duration
+	transform        cache.TransformFunc
 
 	informers map[reflect.Type]cache.SharedIndexInformer
 	// startedInformers is used for tracking which informers have been started.
@@ -80,6 +81,14 @@ func WithNamespace(namespace string) SharedInformerOption {
 	}
 }
 
+// WithTransform sets a transform on all informers.
+func WithTransform(transform cache.TransformFunc) SharedInformerOption {
+	return func(factory *sharedInformerFactory) *sharedInformerFactory {
+		factory.transform = transform
+		return factory
+	}
+}
+
 // NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces.
 func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory {
 	return NewSharedInformerFactoryWithOptions(client, defaultResync)
@@ -184,6 +193,7 @@ func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internal
 	}
 
 	informer = newFunc(f.client, resyncPeriod)
+	informer.SetTransform(f.transform)
 	f.informers[informerType] = informer
 
 	return informer
diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/factory.go b/staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/factory.go
index 9ffb4c31b7617..47bdaeb6027e7 100644
--- a/staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/factory.go
+++ b/staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/factory.go
@@ -44,6 +44,7 @@ type sharedInformerFactory struct {
 	lock             sync.Mutex
 	defaultResync    time.Duration
 	customResync     map[reflect.Type]time.Duration
+	transform        cache.TransformFunc
 
 	informers map[reflect.Type]cache.SharedIndexInformer
 	// startedInformers is used for tracking which informers have been started.
@@ -82,6 +83,14 @@ func WithNamespace(namespace string) SharedInformerOption {
 	}
 }
 
+// WithTransform sets a transform on all informers.
+func WithTransform(transform cache.TransformFunc) SharedInformerOption {
+	return func(factory *sharedInformerFactory) *sharedInformerFactory {
+		factory.transform = transform
+		return factory
+	}
+}
+
 // NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces.
 func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory {
 	return NewSharedInformerFactoryWithOptions(client, defaultResync)
@@ -186,6 +195,7 @@ func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internal
 	}
 
 	informer = newFunc(f.client, resyncPeriod)
+	informer.SetTransform(f.transform)
 	f.informers[informerType] = informer
 
 	return informer
diff --git a/staging/src/k8s.io/code-generator/examples/crd/informers/externalversions/factory.go b/staging/src/k8s.io/code-generator/examples/crd/informers/externalversions/factory.go
index 11fa9bed813f6..77e5c720e88b2 100644
--- a/staging/src/k8s.io/code-generator/examples/crd/informers/externalversions/factory.go
+++ b/staging/src/k8s.io/code-generator/examples/crd/informers/externalversions/factory.go
@@ -43,6 +43,7 @@ type sharedInformerFactory struct {
 	lock             sync.Mutex
 	defaultResync    time.Duration
 	customResync     map[reflect.Type]time.Duration
+	transform        cache.TransformFunc
 
 	informers map[reflect.Type]cache.SharedIndexInformer
 	// startedInformers is used for tracking which informers have been started.
@@ -81,6 +82,14 @@ func WithNamespace(namespace string) SharedInformerOption {
 	}
 }
 
+// WithTransform sets a transform on all informers.
+func WithTransform(transform cache.TransformFunc) SharedInformerOption {
+	return func(factory *sharedInformerFactory) *sharedInformerFactory {
+		factory.transform = transform
+		return factory
+	}
+}
+
 // NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces.
 func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory {
 	return NewSharedInformerFactoryWithOptions(client, defaultResync)
@@ -185,6 +194,7 @@ func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internal
 	}
 
 	informer = newFunc(f.client, resyncPeriod)
+	informer.SetTransform(f.transform)
 	f.informers[informerType] = informer
 
 	return informer
diff --git a/staging/src/k8s.io/kube-aggregator/pkg/client/informers/externalversions/factory.go b/staging/src/k8s.io/kube-aggregator/pkg/client/informers/externalversions/factory.go
index 3acb60f0b5a72..3cf42a74bd981 100644
--- a/staging/src/k8s.io/kube-aggregator/pkg/client/informers/externalversions/factory.go
+++ b/staging/src/k8s.io/kube-aggregator/pkg/client/informers/externalversions/factory.go
@@ -42,6 +42,7 @@ type sharedInformerFactory struct {
 	lock             sync.Mutex
 	defaultResync    time.Duration
 	customResync     map[reflect.Type]time.Duration
+	transform        cache.TransformFunc
 
 	informers map[reflect.Type]cache.SharedIndexInformer
 	// startedInformers is used for tracking which informers have been started.
@@ -80,6 +81,14 @@ func WithNamespace(namespace string) SharedInformerOption {
 	}
 }
 
+// WithTransform sets a transform on all informers.
+func WithTransform(transform cache.TransformFunc) SharedInformerOption {
+	return func(factory *sharedInformerFactory) *sharedInformerFactory {
+		factory.transform = transform
+		return factory
+	}
+}
+
 // NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces.
 func NewSharedInformerFactory(client clientset.Interface, defaultResync time.Duration) SharedInformerFactory {
 	return NewSharedInformerFactoryWithOptions(client, defaultResync)
@@ -184,6 +193,7 @@ func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internal
 	}
 
 	informer = newFunc(f.client, resyncPeriod)
+	informer.SetTransform(f.transform)
 	f.informers[informerType] = informer
 
 	return informer
diff --git a/staging/src/k8s.io/sample-apiserver/pkg/generated/informers/externalversions/factory.go b/staging/src/k8s.io/sample-apiserver/pkg/generated/informers/externalversions/factory.go
index b138f621c9764..52c8c24219ce9 100644
--- a/staging/src/k8s.io/sample-apiserver/pkg/generated/informers/externalversions/factory.go
+++ b/staging/src/k8s.io/sample-apiserver/pkg/generated/informers/externalversions/factory.go
@@ -42,6 +42,7 @@ type sharedInformerFactory struct {
 	lock             sync.Mutex
 	defaultResync    time.Duration
 	customResync     map[reflect.Type]time.Duration
+	transform        cache.TransformFunc
 
 	informers map[reflect.Type]cache.SharedIndexInformer
 	// startedInformers is used for tracking which informers have been started.
@@ -80,6 +81,14 @@ func WithNamespace(namespace string) SharedInformerOption {
 	}
 }
 
+// WithTransform sets a transform on all informers.
+func WithTransform(transform cache.TransformFunc) SharedInformerOption {
+	return func(factory *sharedInformerFactory) *sharedInformerFactory {
+		factory.transform = transform
+		return factory
+	}
+}
+
 // NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces.
 func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory {
 	return NewSharedInformerFactoryWithOptions(client, defaultResync)
@@ -184,6 +193,7 @@ func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internal
 	}
 
 	informer = newFunc(f.client, resyncPeriod)
+	informer.SetTransform(f.transform)
 	f.informers[informerType] = informer
 
 	return informer
diff --git a/staging/src/k8s.io/sample-controller/pkg/generated/informers/externalversions/factory.go b/staging/src/k8s.io/sample-controller/pkg/generated/informers/externalversions/factory.go
index a8f616c7b1438..ccdfc8a8ff197 100644
--- a/staging/src/k8s.io/sample-controller/pkg/generated/informers/externalversions/factory.go
+++ b/staging/src/k8s.io/sample-controller/pkg/generated/informers/externalversions/factory.go
@@ -42,6 +42,7 @@ type sharedInformerFactory struct {
 	lock             sync.Mutex
 	defaultResync    time.Duration
 	customResync     map[reflect.Type]time.Duration
+	transform        cache.TransformFunc
 
 	informers map[reflect.Type]cache.SharedIndexInformer
 	// startedInformers is used for tracking which informers have been started.
@@ -80,6 +81,14 @@ func WithNamespace(namespace string) SharedInformerOption {
 	}
 }
 
+// WithTransform sets a transform on all informers.
+func WithTransform(transform cache.TransformFunc) SharedInformerOption {
+	return func(factory *sharedInformerFactory) *sharedInformerFactory {
+		factory.transform = transform
+		return factory
+	}
+}

Leaderboard for this case

hard · 1 of 9 bots fully caught it (11% solve rate) · 11% avg coverage.

#BotResultCaughtCoverageFindingsFalse alarms
1 Mjolnir (Opus 5.5) solved 1/1 100.0% 1 0
2 Claude Code (Opus 5.5) miss 0/1 0.0% 1 0
3 Cubic miss 0/1 0.0% 0 0
4 cursor miss 0/1 0.0% 0 0
5 Drape (Deep Review) miss 0/1 0.0% 1 0
6 Drape (Review) miss 0/1 0.0% 1 0
7 greptile miss 0/1 0.0% 2 0
8 Mjolnir (Sonnet 5.5) miss 0/1 0.0% 0 0
9 qodo miss 0/1 0.0% 1 0

Bot results

Claude Code (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
minor · impact low
The finding is accurate but describes a style and API-completeness concern, not a behaviour bug. `v1.NamespaceAll` from core/v1 and `metav1.NamespaceAll` are both the empty string, so the import changes nothing at runtime, and client-go already depends on k8s.io/api. The missing WithNamespace/WithTweakListOptions options are an API gap; the code does not misbehave because of them. [grounded: diff] [consensus 3/3: minor=3]
raw comments (1)
staging/src/k8s.io/client-go/metadata/metadatainformer/informer.go:24
The new `NewSharedInformerFactoryWithOptions` imports `k8s.io/api/core/v1` only to use `v1.NamespaceAll`. The file already imports `metav1`, which provides `metav1.NamespaceAll`, and `NewSharedInformerFactory` already uses it. The extra import adds an unnecessary dependency from the metadata informer package on core API types. The metadata factory also has no `WithNamespace` or `WithTweakListOptions` options, so callers who need a transform cannot also filter by namespace or label. That makes it inconsistent with the generated typed factories.
Cubic · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
raw comments (1)
PR-level
<!-- cubic:review-summary:start --> **No issues found** across 14 files <!-- cubic:review-summary:end --> <sub>[Re-trigger cubic](https://www.cubic.dev/action/re-review/pr/drape-io/crbench-cubic-2026-09/47/ai_pr_review_github_delivery_ed473cb3ff253ce2ba8636a1397159ac86d4a0c389659fac823526bd04551e8e?returnTo=https%3A%2F%2Fgithub.com%2Fdrape-io%2Fcrbench-cubic-2026-09%2Fpull%2F47)</sub> <!-- cubic:review-post:ai_pr_review_github_delivery_ed473cb3ff253ce2ba8636a1397159ac86d4a0c389659fac823526bd04551e8e:3309458976c8c04e1a7d0facdcfbe895369e443b:6228d873-b455-5ecd-a8f2-1bdfde9ba5e4 -->
DefectSeverityFoundGrade
d1 high ✗ —
Drape (Deep Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
valid · impact low
InformerFor is public, and it takes a caller-supplied newFunc. The new line calls SetTransform with f.transform every time. When no WithTransform option is set, f.transform is nil, and SetTransform simply assigns s.transform = handler. So any transform that newFunc set before the informer started is replaced with nil. Before this change, that transform was kept. The same unconditional call is in the informer-gen template. No in-repo newFunc that sets a transform was found, so the real-world impact is small. [grounded: tree staging/src/k8s.io/client-go/informers/factory.go] [consensus 3/3: valid=3]
raw comments (1)
staging/src/k8s.io/client-go/informers/factory.go:214
**InformerFor erases transforms set by newFunc** `InformerFor` now always calls `SetTransform(f.transform)`. When the factory has no `WithTransform` option, this replaces any transform the caller's `newFunc` already put on the informer with nil, so that transform is silently lost. Call `SetTransform` only when `f.transform != nil`. The same mistake is at `staging/src/k8s.io/code-generator/cmd/informer-gen/generators/factory.go:265`. ``` staging/src/k8s.io/client-go/informers/factory.go:214 informer.SetTransform(f.transform) staging/src/k8s.io/client-go/tools/cache/shared_informer.go:443 func (s *sharedIndexInformer) SetTransform(handler TransformFunc) error { staging/src/k8s.io/client-go/tools/cache/shared_informer.go:444 s.startedLock.Lock() staging/src/k8s.io/client-go/tools/cache/shared_informer.go:445 defer s.startedLock.Unlock() staging/src/k8s.io/client-go/tools/cache/shared_informer.go:447 if s.started { staging/src/k8s.io/client-go/tools/cache/shared_informer.go:448 return fmt.Errorf("informer has already started") staging/src/k8s.io/client-go/tools/cache/shared_informer.go:449 } staging/src/k8s.io/client-go/tools/cache/shared_informer.go:451 s.transform = handler staging/src/k8s.io/client-go/tools/cache/shared_informer.go:452 return nil ```
Drape (Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
valid · impact low
InformerFor is public and takes a caller-supplied newFunc. If that newFunc returns an informer that already has a transform, the new unconditional SetTransform(f.transform) replaces it with nil whenever the factory had no WithTransform option. SetTransform just assigns `s.transform = handler` on an informer that hasn't started. Before this change the transform was kept. No caller in this repo sets a transform inside newFunc (the scheduler's newPodInformer doesn't), so the impact is low, but the behavior change can be reached through the public API. [grounded: diff] [consensus 3/3: valid=3]
raw comments (1)
staging/src/k8s.io/client-go/informers/factory.go:214
**Factory unconditionally overwrites informer transform** `InformerFor` calls `informer.SetTransform(f.transform)` even when no transform option was given. A nil `f.transform` therefore replaces any transform that `newFunc` had already set on the informer. The same pattern is in the metadata factory's `ForResource` and in every regenerated factory. Guard the call with `if f.transform != nil`. ``` staging/src/k8s.io/client-go/informers/factory.go:214 informer.SetTransform(f.transform) staging/src/k8s.io/client-go/metadata/metadatainformer/informer.go:114 informer.Informer().SetTransform(f.transform) staging/src/k8s.io/code-generator/cmd/informer-gen/generators/factory.go:265 informer.SetTransform(f.transform) staging/src/k8s.io/client-go/tools/cache/shared_informer.go:443 func (s *sharedIndexInformer) SetTransform(handler TransformFunc) error { staging/src/k8s.io/client-go/tools/cache/shared_informer.go:444 s.startedLock.Lock() staging/src/k8s.io/client-go/tools/cache/shared_informer.go:445 defer s.startedLock.Unlock() staging/src/k8s.io/client-go/tools/cache/shared_informer.go:447 if s.started { staging/src/k8s.io/client-go/tools/cache/shared_informer.go:448 return fmt.Errorf("informer has already started") staging/src/k8s.io/client-go/tools/cache/shared_informer.go:449 } staging/src/k8s.io/client-go/tools/cache/shared_informer.go:451 s.transform = handler ```
greptile · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
minor · impact low
The finding asks for test coverage. It does not claim the new constructor or WithTransform behaves incorrectly. [grounded: diff] [consensus 3/3: minor=3]
minor · impact low
Correct: the diff imports core/v1 only for NamespaceAll, and metav1.NamespaceAll is already imported. This is a consistency and dependency-hygiene point, not a behavior bug, since client-go already depends on k8s.io/api. [grounded: diff] [consensus 3/3: minor=3]
raw comments (3)
staging/src/k8s.io/client-go/metadata/metadatainformer/informer.go:46
<a href="#"><img alt="P2" src="https://greptile-static-assets.s3.amazonaws.com/badges/p2.svg?v=9" align="top"></a> **Transform Path Lacks Tests** The new metadata factory options path and `WithTransform` behavior have no focused test confirming that transforms are installed before startup and applied to list/watch objects. Existing tests exercise only the default constructor, so future constructor or informer-wiring regressions could go unnoticed. Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
staging/src/k8s.io/client-go/metadata/metadatainformer/informer.go:24
<a href="#"><img alt="P2" src="https://greptile-static-assets.s3.amazonaws.com/badges/p2.svg?v=9" align="top"></a> **Unnecessary Core API Dependency** This adds a dependency on `k8s.io/api/core/v1` solely for `v1.NamespaceAll`, although the already imported `metav1.NamespaceAll` is used by the adjacent constructor and has the same value. Reusing the existing constant would avoid an unnecessary package dependency and keep the constructors consistent. Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
PR-level
<h3>Greptile Summary</h3> This PR adds factory-wide informer transforms and configures kube-controller-manager’s typed and metadata informers to remove managed fields before objects enter their caches, reducing retained memory. - Adds `WithTransform` to typed and generated shared informer factories. - Adds an options-based constructor and transform support to metadata informers. - Updates informer-gen and its checked-in generated outputs. - Applies a managed-fields trimming transform in kube-controller-manager. - Leaves the new metadata options path without focused test coverage and introduces one unnecessary import. <h3>Confidence Score: 4/5</h3> The PR appears safe to merge, with only non-blocking test-coverage and dependency-cleanup concerns in the metadata informer factory. The transform is installed on fresh informers before startup, nil transforms are harmless, and in-place metadata trimming follows the informer transform contract; the remaining findings concern maintainability rather than runtime correctness. **Files Needing Attention:** staging/src/k8s.io/client-go/metadata/metadatainformer/informer.go <details><summary><h3>Important Files Changed</h3></summary> | Filename | Overview | |----------|----------| | cmd/kube-controller-manager/app/controllermanager.go | Configures typed and metadata informer factories to clear managed fields before caching; no behavioral defect was established. | | staging/src/k8s.io/client-go/informers/factory.go | Adds a factory-wide transform option and installs it on newly created informers. | | staging/src/k8s.io/client-go/metadata/metadatainformer/informer.go | Adds transform options and an options constructor, but lacks focused tests and adds an avoidable core/v1 import. | | staging/src/k8s.io/code-generator/cmd/informer-gen/generators/factory.go | Extends generated shared informer factories with the transform option and installation call. | | staging/src/k8s.io/code-generator/cmd/informer-gen/generators/types.go | Registers cache.TransformFunc for use by the informer factory template. | </details> <details open><summary><h3>Flowchart</h3></summary> ```mermaid %%{init: {'theme': 'neutral'}}%% flowchart LR A[CreateControllerContext] --> B[WithTransform trim] B --> C[Shared informer factory] C --> D[SetTransform before Start] D --> E[List and watch objects] E --> F[Clear ManagedFields] F --> G[DeltaFIFO] G --> H[Informer cache] H --> I[Controller event handlers] ``` </details> <!-- greptile_other_comments_section --> <sub>Reviews (1): Last reviewed commit: ["Update cmd/kube-controller-manager/app/c..."](https://github.com/drape-io/crbench-greptile-2026-09/commit/58f89bd7841de902922d9efc3fe46844c9af0ef9) | [Re-trigger Greptile](https://app.greptile.com/api/retrigger?id=64284532)</sub>
Mjolnir (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✓ off by one
valid · matches d1 · impact high
raw comments (1)
cmd/kube-controller-manager/app/controllermanager.go:529
[P2] The managedFields trim transform writes to cached objects during resync, causing a data race. In this tree, `DeltaFIFO.queueActionLocked` (`staging/src/k8s.io/client-go/tools/cache/delta_fifo.go:454`) runs the transformer on every action, Sync included. `syncKeyLocked` passes in the object it gets from `knownObjects.GetByKey`, and that object is the live one stored in the informer's indexer. kube-controller-manager always uses a non-zero resync period (`ResyncPeriod(s)()`). So on every periodic resync, the new `trim` func calls `accessor.SetManagedFields(nil)` on objects that controllers are reading concurrently through listers and event handlers. That is an unsynchronized write to shared cache state. Writing the same nil value again is still a data race under the Go memory model, and `-race` builds/tests will report it. This affects both the typed and the metadata shared informer factories. The transform should not mutate objects that are already cached, for example by skipping Sync deltas in DeltaFIFO or by making the transform a no-op when `GetManagedFields()` is already nil
Mjolnir (Sonnet 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
qodo · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
valid · impact low
`SetTransform` in shared_informer.go just assigns `s.transform = handler` when the informer hasn't started. The new unconditional call therefore replaces whatever transform a custom `NewInformerFunc` set, including with nil when the factory was built without `WithTransform`. Before this change that transform was kept, so the diff introduces the regression. It only affects callers whose `NewInformerFunc` sets its own transform, so it is an edge case. [grounded: diff] [consensus 3/3: valid=3]
raw comments (3)
staging/src/k8s.io/client-go/informers/factory.go:214
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended"> 1\. Custom informer transforms stop running <code>🐞 Bug</code> <code>≡ Correctness</code> <pre> <b><i>InformerFor</i></b> unconditionally calls <b><i>SetTransform(f.transform)</i></b>, so a factory created without <b><i>WithTransform</i></b> passes nil and overwrites any transform installed by a custom <b><i>NewInformerFunc</i></b>. This occurs when an existing caller returns a preconfigured unstarted informer; <b><i>DeltaFIFO</i></b> skips nil transformers, so normalization or memory-trimming behavior silently disappears across every generated factory. </pre> <details> <summary><strong>Agent Prompt</strong></summary> ``` ## Issue description Generated informer factories unconditionally install the factory transform, including when no `WithTransform` option was supplied. A nil factory transform therefore clears a transform previously installed by a custom `NewInformerFunc`. ## Fix Focus Areas - staging/src/k8s.io/code-generator/cmd/informer-gen/generators/factory.go[262-266] - staging/src/k8s.io/client-go/informers/factory.go[211-215] ## Recommended Fix Call `SetTransform` only when `f.transform` is non-nil, preserving transforms configured by custom informer constructors when the factory option is absent. Regenerate all checked-in informer factories from the updated template. ``` <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code> </details>
PR-level
<h3>PR Summary by Qodo</h3> Add factory-wide informer transforms to reduce controller memory <code>✨ Enhancement</code> <code>🕐 20-40 Minutes</code> <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider"> <details> <summary>AI Description</summary> <dl> <dd> <br/> ><pre> >• Adds factory-wide transforms to typed and metadata shared informer factories. >• Trims managed fields before controller-manager objects enter informer caches, reducing memory > usage. >• Regenerates staged clients and examples to expose the new transform option. ></pre> </dd> </dl> </details> <details> <summary>Diagram</summary> <dl> <dd> <br/> ```mermaid graph TD G["Informer Generator"] -->|emits API| F["Typed Factories"] -->|create| I["Shared Informers"] -->|apply| T["Trim ManagedFields"] -->|store| C[("Informer Cache")] -->|serve| K["Controllers"] M["Controller Manager"] -->|configures| D["Metadata Factory"] -->|create| I M -->|configures| F ``` </dd> </dl> </details> <details> <summary>High-Level Assessment</summary> <dl> <dd> <br/> >The factory-wide transform is the appropriate approach because it applies consistently before cache insertion without duplicating logic across controllers or individual informer registrations. Per-informer transforms would be error-prone, while changing API-server responses would affect unrelated clients; updating informer-gen also keeps generated factories consistent. </dd> </dl> </details> <details> <summary> Files changed (14) <code> +155 / -3 </code> </summary> <dl> <dd> <br/> <details> <summary>Enhancement (8) <code> +95 / -3 </code></summary> <dl> <dd> <details> <summary>controllermanager.go<code>Trim managed fields from controller-manager informer objects</code> <code>+11/-2</code></summary> <br/> >Trim managed fields from controller-manager informer objects > ><pre> >• Defines a metadata transform that clears managed fields and installs it on both typed and metadata shared informer factories. This reduces the memory retained by controller-manager caches. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/46/files#diff-9fdfe2bd53cd3d17d1cbef09eec9d7d3c2ad2338690b88c007a4f1284e747feb'>cmd/kube-controller-manager/app/controllermanager.go</a> </details> <details> <summary>factory.go<code>Expose transforms in the apiextensions client example factory</code> <code>+10/-0</code></summary> <br/> >Expose transforms in the apiextensions client example factory > ><pre> >• Adds a factory-wide transform option and applies it whenever the example client creates an informer. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/46/files#diff-cb8b8525fb8108c00582ce84bb791e7f19f090fd801386161428e73ead89fb0c'>staging/src/k8s.io/apiextensions-apiserver/examples/client-go/pkg/client/informers/externalversions/factory.go</a> </details> <details> <summary>factory.go<code>Add transform support to apiextensions informer factories</code> <code>+10/-0</code></summary> <br/> >Add transform support to apiextensions informer factories > ><pre> >• Stores an optional cache transform on the factory and installs it on newly created apiextensions informers. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/46/files#diff-f6ba9e4254a81e893cc98bc2549cf71c8db8b34e0974a6d7ef841d9fcfa64173'>staging/src/k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions/factory.go</a> </details> <details> <summary>factory.go<code>Add factory-wide transforms to client-go informers</code> <code>+10/-0</code></summary> <br/> >Add factory-wide transforms to client-go informers > ><pre> >• Introduces WithTransform for shared informer factories. Every newly created typed informer receives the configured transform before it can start. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/46/files#diff-b8b67dd65f52f732decee86edfe6ae4934aaed42269e76b5f0d04a687a496b42'>staging/src/k8s.io/client-go/informers/factory.go</a> </details> <details> <summary>informer.go<code>Add configurable metadata informer transforms</code> <code>+32/-0</code></summary> <br/> >Add configurable metadata informer transforms > ><pre> >• Adds metadata factory options, a WithTransform option, and an options-based constructor. Configured transforms are installed on each resource informer before caching begins. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/46/files#diff-a3c6fde154b7a91f6ac7d5c81d42e453d338b8483512a4cb04318d9864343938'>staging/src/k8s.io/client-go/metadata/metadatainformer/informer.go</a> </details> <details> <summary>factory.go<code>Generate transform-aware shared informer factories</code> <code>+11/-1</code></summary> <br/> >Generate transform-aware shared informer factories > ><pre> >• Extends the informer factory template with transform storage, WithTransform, and SetTransform calls. Future generated clients will consistently expose factory-wide transforms. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/46/files#diff-6b07ee5bafb92925a4d994d7cf5a9e83690cbb63949c115caed4babd01c0398c'>staging/src/k8s.io/code-generator/cmd/informer-gen/generators/factory.go</a> </details> <details> <summary>types.go<code>Register TransformFunc for informer generation</code> <code>+1/-0</code></summary> <br/> >Register TransformFunc for informer generation > ><pre> >• Adds the client-go cache TransformFunc type reference used by the informer factory template. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/46/files#diff-dcd84baa292c8a16a657dca9b8145a7ca9aecbb6c71c2adb21cafb705d0965be'>staging/src/k8s.io/code-generator/cmd/informer-gen/generators/types.go</a> </details> <details> <summary>factory.go<code>Add transform support to aggregator informer factories</code> <code>+10/-0</code></summary> <br/> >Add transform support to aggregator informer factories > ><pre> >• Adds a factory option for cache transforms and applies it to newly created kube-aggregator informers. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/46/files#diff-4b6685648135f7a6378036b1a7a51266c93a77fcc59b947de650b4d9ddaf1b0e'>staging/src/k8s.io/kube-aggregator/pkg/client/informers/externalversions/factory.go</a> </details> </dd> </dl> </details> <details> <summary>Other (6) <code> +60 / -0 </code></summary> <dl> <dd> <details> <summary>factory.go<code>Regenerate HyphenGroup factory with transform support</code> <code>+10/-0</code></summary> <br/> >Regenerate HyphenGroup factory with transform support > ><pre> >• Updates the generated HyphenGroup informer factory to accept and install a factory-wide transform. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/46/files#diff-c5b7e278997c3657efb3dcd2c02ecf671f3546a572e7a8e6059c63ab8ca7e462'>staging/src/k8s.io/code-generator/examples/HyphenGroup/informers/externalversions/factory.go</a> </details> <details> <summary>factory.go<code>Regenerate MixedCase factory with transform support</code> <code>+10/-0</code></summary> <br/> >Regenerate MixedCase factory with transform support > ><pre> >• Updates the generated MixedCase informer factory to accept and install a factory-wide transform. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/46/files#diff-81e79e770b1e69a8e62d93c13dc043a86c2d98c3f24b956e4c3d2f2f7cfbd615'>staging/src/k8s.io/code-generator/examples/MixedCase/informers/externalversions/factory.go</a> </details> <details> <summary>factory.go<code>Regenerate apiserver example factory with transforms</code> <code>+10/-0</code></summary> <br/> >Regenerate apiserver example factory with transforms > ><pre> >• Updates the generated apiserver example factory to propagate an optional transform to every informer. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/46/files#diff-35ad9bc3103075e29e7affe52ee3c6994d5ac0c4f84b85bcbcbfde37f1a54b16'>staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/factory.go</a> </details> <details> <summary>factory.go<code>Regenerate CRD example factory with transforms</code> <code>+10/-0</code></summary> <br/> >Regenerate CRD example factory with transforms > ><pre> >• Updates the generated CRD informer factory to expose WithTransform and configure created informers. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/46/files#diff-65b0ec211e80f85700c1aedaaf3786ca9a8c4eabe3df548e0fd021ab4a2d8974'>staging/src/k8s.io/code-generator/examples/crd/informers/externalversions/factory.go</a> </details> <details> <summary>factory.go<code>Regenerate sample apiserver factory with transforms</code> <code>+10/-0</code></summary> <br/> >Regenerate sample apiserver factory with transforms > ><pre> >• Updates the generated sample-apiserver informer factory to accept and install a shared transform. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/46/files#diff-113ff355ba7ddc5f441de133aaf2ccf3835bde88b0af318227474d54bb284d73'>staging/src/k8s.io/sample-apiserver/pkg/generated/informers/externalversions/factory.go</a> </details> <details> <summary>factory.go<code>Regenerate sample controller factory with transforms</code> <code>+10/-0</code></summary> <br/> >Regenerate sample controller factory with transforms > ><pre> >• Updates the generated sample-controller informer factory to propagate a factory-wide transform to created informers. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/46/files#diff-4fc091de664d41f15ee4cb915a52d532256014f073d10a2715f80a762b7decba'>staging/src/k8s.io/sample-controller/pkg/generated/informers/externalversions/factory.go</a> </details> </dd> </dl> </details> </dd> </dl> </details>
PR-level
<h3>Code Review by Qodo</h3> <code>🐞 Bugs (1)</code> <code>📘 Rule violations (0)</code> <code>📜 Skill insights (0)</code> <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider"> <br/> <img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended"> <details> <summary> 1. Custom informer transforms stop running <code>🐞 Bug</code> <code>≡ Correctness</code></summary> <br/> > <details open> ><summary>Description</summary> ><br/> > ><pre> ><b><i>InformerFor</i></b> unconditionally calls <b><i>SetTransform(f.transform)</i></b>, so a factory created without ><b><i>WithTransform</i></b> passes nil and overwrites any transform installed by a custom <b><i>NewInformerFunc</i></b>. >This occurs when an existing caller returns a preconfigured unstarted informer; <b><i>DeltaFIFO</i></b> skips >nil transformers, so normalization or memory-trimming behavior silently disappears across every >generated factory. ></pre> ></details> > <details> ><summary>Code</summary> ><br/> > ><code>[staging/src/k8s.io/client-go/informers/factory.go[214]](https://github.com/drape-io/crbench-qodo-2026-09/pull/46/files#diff-b8b67dd65f52f732decee86edfe6ae4934aaed42269e76b5f0d04a687a496b42R214-R214)</code> > >```diff >+ informer.SetTransform(f.transform) >``` ></details> > <details> ><summary>Evidence</summary> ><br/> > ><pre> >The public factory callback may return any <b><i>SharedIndexInformer</i></b>, and <b><i>SetTransform</i></b> directly >replaces its current handler. The newly added unconditional call therefore replaces a >callback-installed transform with nil under the default constructor, while the queue explicitly >invokes transformations only when the resulting handler is non-nil. ></pre> > > <code>[staging/src/k8s.io/client-go/informers/internalinterfaces/factory_interfaces.go[30-36]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4be2955c0f928a7a706872a4821cf07c46e9b6fa/staging/src/k8s.io/client-go/informers/internalinterfaces/factory_interfaces.go/#L30-L36)</code> > <code>[staging/src/k8s.io/client-go/informers/factory.go[211-215]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4be2955c0f928a7a706872a4821cf07c46e9b6fa/staging/src/k8s.io/client-go/informers/factory.go/#L211-L215)</code> > <code>[staging/src/k8s.io/client-go/tools/cache/shared_informer.go[443-452]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4be2955c0f928a7a706872a4821cf07c46e9b6fa/staging/src/k8s.io/client-go/tools/cache/shared_informer.go/#L443-L452)</code> > <code>[staging/src/k8s.io/client-go/tools/cache/delta_fifo.go[448-460]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4be2955c0f928a7a706872a4821cf07c46e9b6fa/staging/src/k8s.io/client-go/tools/cache/delta_fifo.go/#L448-L460)</code> ></details> > <details> ><summary>Agent prompt</summary> ><br/> > >``` >The issue below was found during a code review. Follow the provided context and guidance below and implement a solution > >## Issue description >Generated informer factories unconditionally install the factory transform, including when no `WithTransform` option was supplied. A nil factory transform therefore clears a transform previously installed by a custom `NewInformerFunc`. > >## Fix Focus Areas >- staging/src/k8s.io/code-generator/cmd/informer-gen/generators/factory.go[262-266] >- staging/src/k8s.io/client-go/informers/factory.go[211-215] > >## Recommended Fix >Call `SetTransform` only when `f.transform` is non-nil, preserving transforms configured by custom informer constructors when the factory option is absent. Regenerate all checked-in informer factories from the updated template. >``` > <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code> ></details> <hr/> </details> <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider"> <!-- qodo-context:start --> <details><summary><strong>Context sources</strong></summary> <div>Review mode: <code>⚖️ Balanced</code>: This changes shared informer behavior and generated APIs across multiple packages, with controller-manager memory semantics and compatibility implications, but is largely a coordinated implementation rather than an unusually bug-dense change warranting extended review.</div> <!-- qodo-context:end --> </details> <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider"> <!-- qodo-daily-tip:start --> <details> <summary><strong>Tip of the day</strong></summary> <br/> <pre>💡 Did you know, you can reply &#x27;qodo&#x27; on any finding to push back, ask questions, or dig deeper</pre> <a href="https://docs.qodo.ai/tips-and-tricks">More tips ↗</a> | <a href="https://app.qodo.ai/configurations?tab=display-preferences">Customize Qodo ↗</a> | <a href="https://docs.qodo.ai">Qodo docs ↗</a> </details> <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider"> <!-- qodo-daily-tip:end --> <!-- https://github.com/drape-io/crbench-qodo-2026-09/commit/4be2955c0f928a7a706872a4821cf07c46e9b6fa --> <a href="https://www.qodo.ai"><img src="https://www.qodo.ai/wp-content/uploads/2025/03/qodo-logo.svg" width="80" alt="Qodo Logo"></a>