@@ -73,7 +73,7 @@ func NewRegistry() *Registry {
73
73
}
74
74
75
75
// MustNewFilteredDynamicSharedInformerFactory creates a new SharedInformerFactory
76
- // and registers it under the given RegistryKey . It panics if there is already
76
+ // and registers it under the given FactoryKey . It panics if there is already
77
77
// an entry with that key.
78
78
func (r * Registry ) MustNewFilteredDynamicSharedInformerFactory (key FactoryKey , client dynamic.Interface , defaultResync time.Duration , namespace string , tweakListOptions dynamicinformer.TweakListOptionsFunc ) dynamicinformer.DynamicSharedInformerFactory {
79
79
factory , err := r .NewFilteredDynamicSharedInformerFactory (key , client , defaultResync , namespace , tweakListOptions )
@@ -84,15 +84,13 @@ func (r *Registry) MustNewFilteredDynamicSharedInformerFactory(key FactoryKey, c
84
84
}
85
85
86
86
// NewFilteredDynamicSharedInformerFactory creates a new SharedInformerFactory
87
- // and registers it under the given RegistryKey
87
+ // and registers it under the given FactoryKey
88
88
func (r * Registry ) NewFilteredDynamicSharedInformerFactory (key FactoryKey , client dynamic.Interface , defaultResync time.Duration , namespace string , tweakListOptions dynamicinformer.TweakListOptionsFunc ) (dynamicinformer.DynamicSharedInformerFactory , error ) {
89
- r .Lock ()
90
- defer r .Unlock ()
91
- if _ , ok := r .factories [key ]; ok {
92
- return nil , fmt .Errorf ("cannot register two InformerFactories with the same key: %s" , key )
89
+ factory := dynamicinformer .NewFilteredDynamicSharedInformerFactory (client , defaultResync , namespace , tweakListOptions )
90
+ if err := r .Add (key , factory ); err != nil {
91
+ return nil , err
93
92
}
94
- r .factories [key ] = dynamicinformer .NewFilteredDynamicSharedInformerFactory (client , defaultResync , namespace , tweakListOptions )
95
- return r .factories [key ], nil
93
+ return factory , nil
96
94
}
97
95
98
96
// ListerFor returns a typed Lister from a Registry
@@ -105,17 +103,21 @@ func IndexerFor[K runtime.Object](r *Registry, key RegistryKey) *Indexer[K] {
105
103
return NewIndexer [K ](r .InformerFor (key ).GetIndexer ())
106
104
}
107
105
108
- // Add adds a factory to the registry under the given RegistryKey
109
- func (r * Registry ) Add (key RegistryKey , factory dynamicinformer.DynamicSharedInformerFactory ) {
106
+ // Add adds a factory to the registry under the given FactoryKey
107
+ func (r * Registry ) Add (key FactoryKey , factory dynamicinformer.DynamicSharedInformerFactory ) error {
110
108
r .Lock ()
111
109
defer r .Unlock ()
110
+ if _ , ok := r .factories [key ]; ok {
111
+ return fmt .Errorf ("cannot register two InformerFactories with the same key: %s" , key )
112
+ }
112
113
r .factories [key ] = factory
114
+ return nil
113
115
}
114
116
115
117
// Remove removes a factory from the registry. Note that it does not stop any
116
118
// informers that were started via the factory; they should be stopped via
117
119
// context cancellation.
118
- func (r * Registry ) Remove (key RegistryKey , factory dynamicinformer. DynamicSharedInformerFactory ) {
120
+ func (r * Registry ) Remove (key FactoryKey ) {
119
121
r .Lock ()
120
122
defer r .Unlock ()
121
123
delete (r .factories , key )
0 commit comments