@@ -112,6 +112,7 @@ type Options struct {
112
112
// NewClient is the func that creates the client to be used by the manager.
113
113
// If not set this will create the default DelegatingClient that will
114
114
// use the cache for reads and the client for writes.
115
+ // NOTE: The default client will not cache Unstructured.
115
116
NewClient NewClientFunc
116
117
117
118
// ClientDisableCacheFor tells the client that, if any cache is used, to bypass it
@@ -255,16 +256,35 @@ func setOptionsDefaults(options Options) Options {
255
256
// NewClientFunc allows a user to define how to create a client.
256
257
type NewClientFunc func (cache cache.Cache , config * rest.Config , options client.Options , uncachedObjects ... client.Object ) (client.Client , error )
257
258
258
- // DefaultNewClient creates the default caching client.
259
+ // ClientOptions are the optional arguments for tuning the caching client.
260
+ type ClientOptions struct {
261
+ UncachedObjects []client.Object
262
+ CacheUnstructured bool
263
+ }
264
+
265
+ // DefaultNewClient creates the default caching client, that will never cache Unstructured.
259
266
func DefaultNewClient (cache cache.Cache , config * rest.Config , options client.Options , uncachedObjects ... client.Object ) (client.Client , error ) {
260
- c , err := client .New (config , options )
261
- if err != nil {
262
- return nil , err
263
- }
267
+ return ClientBuilderWithOptions (ClientOptions {})(cache , config , options , uncachedObjects ... )
268
+ }
264
269
265
- return client .NewDelegatingClient (client.NewDelegatingClientInput {
266
- CacheReader : cache ,
267
- Client : c ,
268
- UncachedObjects : uncachedObjects ,
269
- })
270
+ // ClientBuilderWithOptions returns a Client constructor that will build a client
271
+ // honoring the options argument
272
+ func ClientBuilderWithOptions (options ClientOptions ) NewClientFunc {
273
+ return func (cache cache.Cache , config * rest.Config , clientOpts client.Options , uncachedObjects ... client.Object ) (client.Client , error ) {
274
+ if uncachedObjects != nil {
275
+ options .UncachedObjects = append (options .UncachedObjects , uncachedObjects ... )
276
+ }
277
+
278
+ c , err := client .New (config , clientOpts )
279
+ if err != nil {
280
+ return nil , err
281
+ }
282
+
283
+ return client .NewDelegatingClient (client.NewDelegatingClientInput {
284
+ CacheReader : cache ,
285
+ Client : c ,
286
+ UncachedObjects : options .UncachedObjects ,
287
+ CacheUnstructured : options .CacheUnstructured ,
288
+ })
289
+ }
270
290
}
0 commit comments