@@ -69,6 +69,8 @@ var ErrClusterLocked = errors.New("cluster is locked already")
69
69
type ClusterCacheTracker struct {
70
70
log logr.Logger
71
71
72
+ cacheByObject map [client.Object ]cache.ByObject
73
+
72
74
clientUncachedObjects []client.Object
73
75
clientQPS float32
74
76
clientBurst int
@@ -115,6 +117,9 @@ type ClusterCacheTrackerOptions struct {
115
117
// Defaults to a no-op logger if it's not set.
116
118
Log * logr.Logger
117
119
120
+ // CacheByObject restricts the cache's ListWatch to the desired fields per GVK at the specified object.
121
+ CacheByObject map [client.Object ]cache.ByObject
122
+
118
123
// ClientUncachedObjects instructs the Client to never cache the following objects,
119
124
// it'll instead query the API server directly.
120
125
// Defaults to never caching ConfigMap and Secret if not set.
@@ -191,6 +196,7 @@ func NewClusterCacheTracker(manager ctrl.Manager, options ClusterCacheTrackerOpt
191
196
controllerPodMetadata : controllerPodMetadata ,
192
197
log : * options .Log ,
193
198
clientUncachedObjects : options .ClientUncachedObjects ,
199
+ cacheByObject : options .CacheByObject ,
194
200
clientQPS : options .ClientQPS ,
195
201
clientBurst : options .ClientBurst ,
196
202
client : manager .GetClient (),
@@ -485,6 +491,7 @@ func (t *ClusterCacheTracker) createCachedClient(ctx context.Context, config *re
485
491
HTTPClient : httpClient ,
486
492
Scheme : t .scheme ,
487
493
Mapper : mapper ,
494
+ ByObject : t .cacheByObject ,
488
495
}
489
496
remoteCache , err := cache .New (config , cacheOptions )
490
497
if err != nil {
0 commit comments