Skip to content

Commit f0c054d

Browse files
committed
✨ Add NewClientFunc to create client caching Unstructured
1 parent accd262 commit f0c054d

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

pkg/cluster/cluster.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ type Options struct {
112112
// NewClient is the func that creates the client to be used by the manager.
113113
// If not set this will create the default DelegatingClient that will
114114
// use the cache for reads and the client for writes.
115+
// NOTE: The default client will not cache Unstructured.
115116
NewClient NewClientFunc
116117

117118
// ClientDisableCacheFor tells the client that, if any cache is used, to bypass it
@@ -255,16 +256,28 @@ func setOptionsDefaults(options Options) Options {
255256
// NewClientFunc allows a user to define how to create a client.
256257
type NewClientFunc func(cache cache.Cache, config *rest.Config, options client.Options, uncachedObjects ...client.Object) (client.Client, error)
257258

258-
// DefaultNewClient creates the default caching client.
259+
// DefaultNewClient creates the default caching client, that will not cache Unstructured.
259260
func DefaultNewClient(cache cache.Cache, config *rest.Config, options client.Options, uncachedObjects ...client.Object) (client.Client, error) {
261+
return newClient(cache, config, options, false, uncachedObjects)
262+
}
263+
264+
// CacheUnstructuredNewClient creates a caching client that will cache Unstructured.
265+
func CacheUnstructuredNewClient(cache cache.Cache, config *rest.Config, options client.Options, uncachedObjects ...client.Object) (client.Client, error) {
266+
return newClient(cache, config, options, true, uncachedObjects)
267+
}
268+
269+
var _ NewClientFunc = CacheUnstructuredNewClient
270+
271+
func newClient(cache cache.Cache, config *rest.Config, options client.Options, cacheUnstructured bool, uncachedObjects []client.Object) (client.Client, error) {
260272
c, err := client.New(config, options)
261273
if err != nil {
262274
return nil, err
263275
}
264276

265277
return client.NewDelegatingClient(client.NewDelegatingClientInput{
266-
CacheReader: cache,
267-
Client: c,
268-
UncachedObjects: uncachedObjects,
278+
CacheReader: cache,
279+
Client: c,
280+
UncachedObjects: uncachedObjects,
281+
CacheUnstructured: cacheUnstructured,
269282
})
270283
}

0 commit comments

Comments
 (0)