Skip to content

Commit 2b451f1

Browse files
authored
Merge pull request #11201 from vincepri/allow-cache-modifier
🌱 test/framework: allow users to modify cache.Options
2 parents c1c8833 + 8303ca6 commit 2b451f1

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

test/framework/cluster_proxy.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ func WithRESTConfigModifier(f func(*rest.Config)) Option {
150150
}
151151
}
152152

153+
// WithCacheOptionsModifier allows to modify the options passed to cache.New the first time it's created.
154+
func WithCacheOptionsModifier(f func(*cache.Options)) Option {
155+
return func(c *clusterProxy) {
156+
c.cacheOptionsModifier = f
157+
}
158+
}
159+
153160
// clusterProxy provides a base implementation of the ClusterProxy interface.
154161
type clusterProxy struct {
155162
name string
@@ -160,7 +167,8 @@ type clusterProxy struct {
160167
cache cache.Cache
161168
onceCache sync.Once
162169

163-
restConfigModifier func(*rest.Config)
170+
restConfigModifier func(*rest.Config)
171+
cacheOptionsModifier func(*cache.Options)
164172
}
165173

166174
// NewClusterProxy returns a clusterProxy given a KubeconfigPath and the scheme defining the types hosted in the cluster.
@@ -255,11 +263,16 @@ func (p *clusterProxy) GetClientSet() *kubernetes.Clientset {
255263

256264
func (p *clusterProxy) GetCache(ctx context.Context) cache.Cache {
257265
p.onceCache.Do(func() {
258-
var err error
259-
p.cache, err = cache.New(p.GetRESTConfig(), cache.Options{
266+
opts := &cache.Options{
260267
Scheme: p.scheme,
261268
Mapper: p.GetClient().RESTMapper(),
262-
})
269+
}
270+
if p.cacheOptionsModifier != nil {
271+
p.cacheOptionsModifier(opts)
272+
}
273+
274+
var err error
275+
p.cache, err = cache.New(p.GetRESTConfig(), *opts)
263276
Expect(err).ToNot(HaveOccurred(), "Failed to create controller-runtime cache")
264277

265278
go func() {

0 commit comments

Comments
 (0)