@@ -94,13 +94,43 @@ func (r *Registry) NewFilteredDynamicSharedInformerFactory(key FactoryKey, clien
9494}
9595
9696// ListerFor returns a typed Lister from a Registry
97+ // Deprecated: Use MustListerForKey instead
9798func ListerFor [K runtime.Object ](r * Registry , key RegistryKey ) * Lister [K ] {
98- return NewLister [K ](r .ListerFor (key ))
99+ return MustListerForKey [K ](r , key )
100+ }
101+
102+ // MustListerForKey returns a typed Lister from a Registry, or panics if the key is not found
103+ func MustListerForKey [K runtime.Object ](r * Registry , key RegistryKey ) * Lister [K ] {
104+ return NewLister [K ](r .MustListerForKey (key ))
105+ }
106+
107+ // ListerForKey returns a typed Lister from a Registry, or an error if the key is not found
108+ func ListerForKey [K runtime.Object ](r * Registry , key RegistryKey ) (* Lister [K ], error ) {
109+ lister , err := r .ListerForKey (key )
110+ if err != nil {
111+ return nil , err
112+ }
113+ return NewLister [K ](lister ), nil
99114}
100115
101116// IndexerFor returns a typed Indexer from a Registry
117+ // Deprecated: Use MustIndexerForKey instead
102118func IndexerFor [K runtime.Object ](r * Registry , key RegistryKey ) * Indexer [K ] {
103- return NewIndexer [K ](r .InformerFor (key ).GetIndexer ())
119+ return MustIndexerForKey [K ](r , key )
120+ }
121+
122+ // MustIndexerForKey returns a typed Indexer from a Registry, or panics if the key is not found
123+ func MustIndexerForKey [K runtime.Object ](r * Registry , key RegistryKey ) * Indexer [K ] {
124+ return NewIndexer [K ](r .MustIndexerForKey (key ))
125+ }
126+
127+ // IndexerForKey returns a typed Indexer from a Registry, or an error if the key is not found
128+ func IndexerForKey [K runtime.Object ](r * Registry , key RegistryKey ) (* Indexer [K ], error ) {
129+ indexer , err := r .IndexerForKey (key )
130+ if err != nil {
131+ return nil , err
132+ }
133+ return NewIndexer [K ](indexer ), nil
104134}
105135
106136// Add adds a factory to the registry under the given FactoryKey
@@ -124,27 +154,95 @@ func (r *Registry) Remove(key FactoryKey) {
124154}
125155
126156// InformerFactoryFor returns GVR-specific InformerFactory from the Registry.
157+ // Deprecated: use MustInformerFactoryForKey instead.
127158func (r * Registry ) InformerFactoryFor (key RegistryKey ) informers.GenericInformer {
159+ return r .MustInformerFactoryForKey (key )
160+ }
161+
162+ // MustInformerFactoryForKey returns GVR-specific InformerFactory from the Registry
163+ // or panics if the key is not found.
164+ func (r * Registry ) MustInformerFactoryForKey (key RegistryKey ) informers.GenericInformer {
165+ informer , err := r .InformerFactoryForKey (key )
166+ if err != nil {
167+ panic (err )
168+ }
169+ return informer
170+ }
171+
172+ // InformerFactoryForKey returns GVR-specific InformerFactory from the Registry
173+ // or returns an error if the key is not found.
174+ func (r * Registry ) InformerFactoryForKey (key RegistryKey ) (informers.GenericInformer , error ) {
128175 r .RLock ()
129176 defer r .RUnlock ()
130177 factory , ok := r .factories [key .FactoryKey ]
131178 if ! ok {
132- panic ( fmt .Errorf ("InformerFactoryFor called with unknown key %s" , key ) )
179+ return nil , fmt .Errorf ("InformerFactoryFor called with unknown key %s" , key )
133180 }
134- return factory .ForResource (key .GroupVersionResource )
181+ return factory .ForResource (key .GroupVersionResource ), nil
135182}
136183
137184// ListerFor returns the GVR-specific Lister from the Registry
185+ // Deprecated: use MustListerForKey instead.
138186func (r * Registry ) ListerFor (key RegistryKey ) cache.GenericLister {
139- return r .InformerFactoryFor (key ).Lister ()
187+ return r .MustInformerFactoryForKey (key ).Lister ()
188+ }
189+
190+ // MustListerForKey returns the GVR-specific Lister from the Registry, or panics
191+ // if the key is not found.
192+ func (r * Registry ) MustListerForKey (key RegistryKey ) cache.GenericLister {
193+ return r .MustInformerFactoryForKey (key ).Lister ()
194+ }
195+
196+ // ListerForKey returns the GVR-specific Lister from the Registry, or an error
197+ // if the key is not found.
198+ func (r * Registry ) ListerForKey (key RegistryKey ) (cache.GenericLister , error ) {
199+ factory , err := r .InformerFactoryForKey (key )
200+ if err != nil {
201+ return nil , err
202+ }
203+ return factory .Lister (), nil
140204}
141205
142206// InformerFor returns the GVR-specific Informer from the Registry
207+ // Deprecated: use MustInformerForKey instead.
143208func (r * Registry ) InformerFor (key RegistryKey ) cache.SharedIndexInformer {
144- return r .InformerFactoryFor (key ).Informer ()
209+ return r .MustInformerFactoryForKey (key ).Informer ()
210+ }
211+
212+ // MustInformerForKey returns the GVR-specific Informer from the Registry, or panics
213+ // if the key is not found.
214+ func (r * Registry ) MustInformerForKey (key RegistryKey ) cache.SharedIndexInformer {
215+ return r .MustInformerFactoryForKey (key ).Informer ()
216+ }
217+
218+ // InformerForKey returns the GVR-specific Informer from the Registry, or an error
219+ // if the key is not found.
220+ func (r * Registry ) InformerForKey (key RegistryKey ) (cache.SharedIndexInformer , error ) {
221+ factory , err := r .InformerFactoryForKey (key )
222+ if err != nil {
223+ return nil , err
224+ }
225+ return factory .Informer (), nil
145226}
146227
147228// IndexerFor returns the GVR-specific Indexer from the Registry
229+ // Deprecated: use MustIndexerForKey instead.
148230func (r * Registry ) IndexerFor (key RegistryKey ) cache.Indexer {
149- return r .InformerFactoryFor (key ).Informer ().GetIndexer ()
231+ return r .MustInformerForKey (key ).GetIndexer ()
232+ }
233+
234+ // MustIndexerForKey returns the GVR-specific Indexer from the Registry, or panics
235+ // if the key is not found.
236+ func (r * Registry ) MustIndexerForKey (key RegistryKey ) cache.Indexer {
237+ return r .MustInformerForKey (key ).GetIndexer ()
238+ }
239+
240+ // IndexerForKey returns the GVR-specific Indexer from the Registry, or an error
241+ // if the key is not found.
242+ func (r * Registry ) IndexerForKey (key RegistryKey ) (cache.Indexer , error ) {
243+ informer , err := r .InformerForKey (key )
244+ if err != nil {
245+ return nil , err
246+ }
247+ return informer .GetIndexer (), nil
150248}
0 commit comments