From 5044f38123bcaa5f652235bcb8c7a021a0a3a422 Mon Sep 17 00:00:00 2001 From: Frederic Giloux Date: Wed, 28 Sep 2022 07:06:09 +0200 Subject: [PATCH] Add ClusterAwareBuilderWithOptions to the wrapper Signed-off-by: Frederic Giloux --- pkg/kcp/wrappers.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/pkg/kcp/wrappers.go b/pkg/kcp/wrappers.go index 5d20bfd9b7..6b714c8aae 100644 --- a/pkg/kcp/wrappers.go +++ b/pkg/kcp/wrappers.go @@ -136,3 +136,32 @@ func NewClusterAwareMapperProvider(c *rest.Config) (meta.RESTMapper, error) { return apiutil.NewDynamicRESTMapper(mapperCfg) } + +// ClusterAwareBuilderWithOptions returns a cluster aware Cache constructor that will build +// a cache honoring the options argument, this is useful to specify options like +// SelectorsByObject +// WARNING: If SelectorsByObject is specified, filtered out resources are not +// returned. +// WARNING: If UnsafeDisableDeepCopy is enabled, you must DeepCopy any object +// returned from cache get/list before mutating it. +func ClusterAwareBuilderWithOptions(options cache.Options) cache.NewCacheFunc { + return func(config *rest.Config, opts cache.Options) (cache.Cache, error) { + if options.Scheme == nil { + options.Scheme = opts.Scheme + } + if options.Mapper == nil { + options.Mapper = opts.Mapper + } + if options.Resync == nil { + options.Resync = opts.Resync + } + if options.Namespace == "" { + options.Namespace = opts.Namespace + } + if opts.Resync == nil { + opts.Resync = options.Resync + } + + return NewClusterAwareCache(config, options) + } +}