Skip to content

✨ Add ClusterAwareBuilderWithOptions to the wrapper #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions pkg/kcp/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}