Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#11201 from vincepri/allow-cache-mo…
Browse files Browse the repository at this point in the history
…difier

🌱 test/framework: allow users to modify cache.Options
  • Loading branch information
k8s-ci-robot authored Sep 19, 2024
2 parents c1c8833 + 8303ca6 commit 2b451f1
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions test/framework/cluster_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 2b451f1

Please sign in to comment.