From 8303ca61a1713d3d26fc4c596e3af3d1ac81e06e Mon Sep 17 00:00:00 2001 From: Vince Prignano Date: Thu, 19 Sep 2024 07:49:52 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=B1=20test/framework:=20allow=20users?= =?UTF-8?q?=20to=20modify=20cache.Options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Vince Prignano --- test/framework/cluster_proxy.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/test/framework/cluster_proxy.go b/test/framework/cluster_proxy.go index c32a683d5c41..88e25f5355bf 100644 --- a/test/framework/cluster_proxy.go +++ b/test/framework/cluster_proxy.go @@ -150,6 +150,13 @@ func WithRESTConfigModifier(f func(*rest.Config)) Option { } } +// WithCacheOptionsModifier allows to modify the options passed to cache.New the first time it's created. +func WithCacheOptionsModifier(f func(*cache.Options)) Option { + return func(c *clusterProxy) { + c.cacheOptionsModifier = f + } +} + // clusterProxy provides a base implementation of the ClusterProxy interface. type clusterProxy struct { name string @@ -160,7 +167,8 @@ type clusterProxy struct { cache cache.Cache onceCache sync.Once - restConfigModifier func(*rest.Config) + restConfigModifier func(*rest.Config) + cacheOptionsModifier func(*cache.Options) } // 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 { func (p *clusterProxy) GetCache(ctx context.Context) cache.Cache { p.onceCache.Do(func() { - var err error - p.cache, err = cache.New(p.GetRESTConfig(), cache.Options{ + opts := &cache.Options{ Scheme: p.scheme, Mapper: p.GetClient().RESTMapper(), - }) + } + if p.cacheOptionsModifier != nil { + p.cacheOptionsModifier(opts) + } + + var err error + p.cache, err = cache.New(p.GetRESTConfig(), *opts) Expect(err).ToNot(HaveOccurred(), "Failed to create controller-runtime cache") go func() {