@@ -22,6 +22,7 @@ import (
2222"net/http"
2323"time"
2424
25+ "github.com/kcp-dev/apimachinery/v2/third_party/informers"
2526corev1 "k8s.io/api/core/v1"
2627"k8s.io/apimachinery/pkg/api/meta"
2728"k8s.io/apimachinery/pkg/fields"
@@ -159,6 +160,14 @@ type Options struct {
159160// instead of `reconcile.Result{}`.
160161SyncPeriod * time.Duration
161162
163+ // NewInformerFunc is a function that is used to create SharedIndexInformers.
164+ // Defaults to cache.NewSharedIndexInformer from client-go
165+ NewInformerFunc client.NewInformerFunc
166+
167+ // Indexers is the indexers that the informers will be configured to use.
168+ // Will always have the standard NamespaceIndex.
169+ Indexers toolscache.Indexers
170+
162171// ReaderFailOnMissingInformer configures the cache to return a ErrResourceNotCached error when a user
163172// requests, using Get() and List(), a resource the cache does not already have an informer for.
164173//
@@ -201,9 +210,6 @@ type Options struct {
201210// ByObject restricts the cache's ListWatch to the desired fields per GVK at the specified object.
202211// object, this will fall through to Default* settings.
203212ByObject map [client.Object ]ByObject
204-
205- // newInformer allows overriding of NewSharedIndexInformer for testing.
206- newInformer * func (toolscache.ListerWatcher , runtime.Object , time.Duration , toolscache.Indexers ) toolscache.SharedIndexInformer
207213}
208214
209215// ByObject offers more fine-grained control over the cache's ListWatch by object.
@@ -354,7 +360,7 @@ func newCache(restConfig *rest.Config, opts Options) newCacheFunc {
354360},
355361Transform : config .Transform ,
356362UnsafeDisableDeepCopy : pointer .BoolDeref (config .UnsafeDisableDeepCopy , false ),
357- NewInformer : opts .newInformer ,
363+ NewInformer : opts .NewInformerFunc ,
358364}),
359365readerFailOnMissingInformer : opts .ReaderFailOnMissingInformer ,
360366}
@@ -438,6 +444,10 @@ func defaultOpts(config *rest.Config, opts Options) (Options, error) {
438444if opts .SyncPeriod == nil {
439445opts .SyncPeriod = & defaultSyncPeriod
440446}
447+
448+ if opts .NewInformerFunc == nil {
449+ opts .NewInformerFunc = informers .NewSharedIndexInformer
450+ }
441451return opts , nil
442452}
443453
0 commit comments