Skip to content

Commit a02083d

Browse files
Merge pull request #26 from fgiloux/options
✨ Add ClusterAwareBuilderWithOptions to the wrapper
2 parents 824b15a + 5044f38 commit a02083d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

pkg/kcp/wrappers.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,32 @@ func NewClusterAwareMapperProvider(c *rest.Config) (meta.RESTMapper, error) {
136136

137137
return apiutil.NewDynamicRESTMapper(mapperCfg)
138138
}
139+
140+
// ClusterAwareBuilderWithOptions returns a cluster aware Cache constructor that will build
141+
// a cache honoring the options argument, this is useful to specify options like
142+
// SelectorsByObject
143+
// WARNING: If SelectorsByObject is specified, filtered out resources are not
144+
// returned.
145+
// WARNING: If UnsafeDisableDeepCopy is enabled, you must DeepCopy any object
146+
// returned from cache get/list before mutating it.
147+
func ClusterAwareBuilderWithOptions(options cache.Options) cache.NewCacheFunc {
148+
return func(config *rest.Config, opts cache.Options) (cache.Cache, error) {
149+
if options.Scheme == nil {
150+
options.Scheme = opts.Scheme
151+
}
152+
if options.Mapper == nil {
153+
options.Mapper = opts.Mapper
154+
}
155+
if options.Resync == nil {
156+
options.Resync = opts.Resync
157+
}
158+
if options.Namespace == "" {
159+
options.Namespace = opts.Namespace
160+
}
161+
if opts.Resync == nil {
162+
opts.Resync = options.Resync
163+
}
164+
165+
return NewClusterAwareCache(config, options)
166+
}
167+
}

0 commit comments

Comments
 (0)