@@ -10,19 +10,23 @@ import (
10
10
"k8s.io/apimachinery/pkg/runtime"
11
11
"k8s.io/client-go/kubernetes/scheme"
12
12
"k8s.io/client-go/rest"
13
+ toolscache "k8s.io/client-go/tools/cache"
13
14
"sigs.k8s.io/controller-runtime/pkg/cache"
14
15
"sigs.k8s.io/controller-runtime/pkg/client"
15
16
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
16
17
)
17
18
18
19
// Options defines options needed to generate a client.
19
20
type Options struct {
20
- syncPeriod * time.Duration
21
- scheme * runtime.Scheme
22
- cacheReader bool
23
- ctx context.Context
24
- httpClient * http.Client
25
- mapper meta.RESTMapper
21
+ syncPeriod * time.Duration
22
+ scheme * runtime.Scheme
23
+ cacheReader bool
24
+ ctx context.Context
25
+ httpClient * http.Client
26
+ mapper meta.RESTMapper
27
+ defaultNamespaces map [string ]cache.Config
28
+ defaultTransform toolscache.TransformFunc
29
+ byObject map [client.Object ]cache.ByObject
26
30
}
27
31
28
32
// WithSyncPeriod sets the SyncPeriod time option.
@@ -71,6 +75,27 @@ func WithMapper(mapper meta.RESTMapper) func(opts *Options) {
71
75
}
72
76
}
73
77
78
+ // WithDefaultNamespaces sets the DefaultNamespaces for the cache client.
79
+ func WithDefaultNamespaces (defaultNamespaces map [string ]cache.Config ) func (opts * Options ) {
80
+ return func (opts * Options ) {
81
+ opts .defaultNamespaces = defaultNamespaces
82
+ }
83
+ }
84
+
85
+ // WithDefaultTransform sets the DefaultTransform for the cache client.
86
+ func WithDefaultTransform (defaultTransform toolscache.TransformFunc ) func (opts * Options ) {
87
+ return func (opts * Options ) {
88
+ opts .defaultTransform = defaultTransform
89
+ }
90
+ }
91
+
92
+ // WithByObject sets the ByObject for the cache client.
93
+ func WithByObject (byObject map [client.Object ]cache.ByObject ) func (opts * Options ) {
94
+ return func (opts * Options ) {
95
+ opts .byObject = byObject
96
+ }
97
+ }
98
+
74
99
// NewCache returns a controller-runtime cache client implementation.
75
100
func NewCache (config * rest.Config , options ... func (* Options )) (cache.Cache , error ) {
76
101
opts := & Options {
@@ -97,10 +122,13 @@ func NewCache(config *rest.Config, options ...func(*Options)) (cache.Cache, erro
97
122
}
98
123
99
124
cacheClient , err := cache .New (config , cache.Options {
100
- HTTPClient : opts .httpClient ,
101
- Scheme : opts .scheme ,
102
- Mapper : opts .mapper ,
103
- SyncPeriod : opts .syncPeriod ,
125
+ HTTPClient : opts .httpClient ,
126
+ Scheme : opts .scheme ,
127
+ Mapper : opts .mapper ,
128
+ SyncPeriod : opts .syncPeriod ,
129
+ DefaultNamespaces : opts .defaultNamespaces ,
130
+ DefaultTransform : opts .defaultTransform ,
131
+ ByObject : opts .byObject ,
104
132
})
105
133
if err != nil {
106
134
return nil , err
0 commit comments