Skip to content

Commit 0c7dc03

Browse files
informergen: use an options struct for options
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
1 parent 779e809 commit 0c7dc03

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

pkg/internal/informergen/factory.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ import (
9191
)
9292
9393
// SharedInformerOption defines the functional option type for SharedInformerFactory.
94-
type SharedInformerOption func(*sharedInformerFactory) *sharedInformerFactory
94+
type SharedInformerOption func(*SharedInformerOptions) *SharedInformerOptions
95+
96+
type SharedInformerOptions struct {
97+
customResync map[reflect.Type]time.Duration
98+
tweakListOptions internalinterfaces.TweakListOptionsFunc
99+
}
95100
96101
type sharedInformerFactory struct {
97102
client clientset.ClusterInterface
@@ -108,19 +113,19 @@ type sharedInformerFactory struct {
108113
109114
// WithCustomResyncConfig sets a custom resync period for the specified informer types.
110115
func WithCustomResyncConfig(resyncConfig map[metav1.Object]time.Duration) SharedInformerOption {
111-
return func(factory *sharedInformerFactory) *sharedInformerFactory {
116+
return func(opts *SharedInformerOptions) *SharedInformerOptions {
112117
for k, v := range resyncConfig {
113-
factory.customResync[reflect.TypeOf(k)] = v
118+
opts.customResync[reflect.TypeOf(k)] = v
114119
}
115-
return factory
120+
return opts
116121
}
117122
}
118123
119124
// WithTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory.
120125
func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerOption {
121-
return func(factory *sharedInformerFactory) *sharedInformerFactory {
122-
factory.tweakListOptions = tweakListOptions
123-
return factory
126+
return func(opts *SharedInformerOptions) *SharedInformerOptions {
127+
opts.tweakListOptions = tweakListOptions
128+
return opts
124129
}
125130
}
126131
@@ -139,11 +144,19 @@ func NewSharedInformerFactoryWithOptions(client clientset.ClusterInterface, defa
139144
customResync: make(map[reflect.Type]time.Duration),
140145
}
141146
147+
opts := &SharedInformerOptions{
148+
customResync: make(map[reflect.Type]time.Duration),
149+
}
150+
142151
// Apply all options
143152
for _, opt := range options {
144-
factory = opt(factory)
153+
opts = opt(opts)
145154
}
146155
156+
// Forward options to the factory
157+
factory.customResync = opts.customResync
158+
factory.tweakListOptions = opts.tweakListOptions
159+
147160
return factory
148161
}
149162
@@ -182,7 +195,7 @@ func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[ref
182195
return res
183196
}
184197
185-
// InternalInformerFor returns the SharedIndexInformer for obj using an internal
198+
// InformerFor returns the SharedIndexInformer for obj using an internal
186199
// client.
187200
func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) kcpcache.ScopeableSharedIndexInformer {
188201
f.lock.Lock()

0 commit comments

Comments
 (0)