@@ -194,34 +194,30 @@ func (ip *InformersMap) Get(gvk schema.GroupVersionKind, obj runtime.Object) (*M
194
194
195
195
// newListWatch returns a new ListWatch object that can be used to create a SharedIndexInformer.
196
196
func (ip * InformersMap ) newListWatch (gvk schema.GroupVersionKind , isUnstructured bool ) (* cache.ListWatch , error ) {
197
+ // Kubernetes APIs work against Resources, not GroupVersionKinds. Map the
198
+ // groupVersionKind to the Resource API we will use.
199
+ mapping , err := ip .mapper .RESTMapping (gvk .GroupKind (), gvk .Version )
200
+ if err != nil {
201
+ return nil , err
202
+ }
203
+
197
204
// Construct a RESTClient for the groupVersionKind that we will use to
198
205
// talk to the apiserver.
199
206
var client rest.Interface
200
- var err error
207
+ var listObj runtime. Object
201
208
if isUnstructured {
202
209
client , err = apiutil .RESTUnstructuredClientForGVK (gvk , ip .config )
210
+ listObj = & unstructured.UnstructuredList {}
203
211
} else {
204
212
client , err = apiutil .RESTClientForGVK (gvk , ip .config , ip .codecs )
213
+ listGVK := gvk .GroupVersion ().WithKind (gvk .Kind + "List" )
214
+ listObj , err = ip .Scheme .New (listGVK )
205
215
206
216
}
207
217
if err != nil {
208
218
return nil , err
209
219
}
210
220
211
- // Kubernetes APIs work against Resources, not GroupVersionKinds. Map the
212
- // groupVersionKind to the Resource API we will use.
213
- mapping , err := ip .mapper .RESTMapping (gvk .GroupKind (), gvk .Version )
214
- if err != nil {
215
- return nil , err
216
- }
217
-
218
- // Get a listObject for listing that the ListWatch can DeepCopy
219
- listGVK := gvk .GroupVersion ().WithKind (gvk .Kind + "List" )
220
- listObj , err := ip .Scheme .New (listGVK )
221
- if err != nil {
222
- return nil , err
223
- }
224
-
225
221
// Create a new ListWatch for the obj
226
222
return & cache.ListWatch {
227
223
ListFunc : func (opts metav1.ListOptions ) (runtime.Object , error ) {
0 commit comments