@@ -22,6 +22,7 @@ import (
22
22
"net/http"
23
23
"time"
24
24
25
+ "github.com/kcp-dev/apimachinery/v2/third_party/informers"
25
26
"golang.org/x/exp/maps"
26
27
corev1 "k8s.io/api/core/v1"
27
28
"k8s.io/apimachinery/pkg/api/meta"
@@ -170,6 +171,14 @@ type Options struct {
170
171
// instead of `reconcile.Result{}`.
171
172
SyncPeriod * time.Duration
172
173
174
+ // NewInformerFunc is a function that is used to create SharedIndexInformers.
175
+ // Defaults to cache.NewSharedIndexInformer from client-go
176
+ NewInformerFunc client.NewInformerFunc
177
+
178
+ // Indexers is the indexers that the informers will be configured to use.
179
+ // Will always have the standard NamespaceIndex.
180
+ Indexers toolscache.Indexers
181
+
173
182
// ReaderFailOnMissingInformer configures the cache to return a ErrResourceNotCached error when a user
174
183
// requests, using Get() and List(), a resource the cache does not already have an informer for.
175
184
//
@@ -223,9 +232,6 @@ type Options struct {
223
232
// ByObject restricts the cache's ListWatch to the desired fields per GVK at the specified object.
224
233
// object, this will fall through to Default* settings.
225
234
ByObject map [client.Object ]ByObject
226
-
227
- // newInformer allows overriding of NewSharedIndexInformer for testing.
228
- newInformer * func (toolscache.ListerWatcher , runtime.Object , time.Duration , toolscache.Indexers ) toolscache.SharedIndexInformer
229
235
}
230
236
231
237
// ByObject offers more fine-grained control over the cache's ListWatch by object.
@@ -382,7 +388,7 @@ func newCache(restConfig *rest.Config, opts Options) newCacheFunc {
382
388
Transform : config .Transform ,
383
389
WatchErrorHandler : opts .DefaultWatchErrorHandler ,
384
390
UnsafeDisableDeepCopy : ptr .Deref (config .UnsafeDisableDeepCopy , false ),
385
- NewInformer : opts .newInformer ,
391
+ NewInformer : opts .NewInformerFunc ,
386
392
}),
387
393
readerFailOnMissingInformer : opts .ReaderFailOnMissingInformer ,
388
394
}
@@ -478,6 +484,10 @@ func defaultOpts(config *rest.Config, opts Options) (Options, error) {
478
484
if opts .SyncPeriod == nil {
479
485
opts .SyncPeriod = & defaultSyncPeriod
480
486
}
487
+
488
+ if opts .NewInformerFunc == nil {
489
+ opts .NewInformerFunc = informers .NewSharedIndexInformer
490
+ }
481
491
return opts , nil
482
492
}
483
493
0 commit comments