@@ -86,11 +86,10 @@ func NewForConfig(inConfig *rest.Config) (*DynamicClient, error) {
86
86
// Note the http client provided takes precedence over the configured transport values.
87
87
func NewForConfigAndClient (inConfig * rest.Config , h * http.Client ) (* DynamicClient , error ) {
88
88
config := ConfigFor (inConfig )
89
- // for serializing the options
90
- config .GroupVersion = & schema.GroupVersion {}
89
+ config .GroupVersion = nil
91
90
config .APIPath = "/if-you-see-this-search-for-the-break"
92
91
93
- restClient , err := rest .RESTClientForConfigAndClient (config , h )
92
+ restClient , err := rest .UnversionedRESTClientForConfigAndClient (config , h )
94
93
if err != nil {
95
94
return nil , err
96
95
}
@@ -114,10 +113,6 @@ func (c *dynamicResourceClient) Namespace(ns string) ResourceInterface {
114
113
}
115
114
116
115
func (c * dynamicResourceClient ) Create (ctx context.Context , obj * unstructured.Unstructured , opts metav1.CreateOptions , subresources ... string ) (* unstructured.Unstructured , error ) {
117
- outBytes , err := runtime .Encode (unstructured .UnstructuredJSONScheme , obj )
118
- if err != nil {
119
- return nil , err
120
- }
121
116
name := ""
122
117
if len (subresources ) > 0 {
123
118
accessor , err := meta .Accessor (obj )
@@ -133,26 +128,17 @@ func (c *dynamicResourceClient) Create(ctx context.Context, obj *unstructured.Un
133
128
return nil , err
134
129
}
135
130
136
- result := c .client .client .
131
+ var out unstructured.Unstructured
132
+ if err := c .client .client .
137
133
Post ().
138
134
AbsPath (append (c .makeURLSegments (name ), subresources ... )... ).
139
- SetHeader ("Content-Type" , runtime .ContentTypeJSON ).
140
- Body (outBytes ).
135
+ Body (obj ).
141
136
SpecificallyVersionedParams (& opts , dynamicParameterCodec , versionV1 ).
142
- Do (ctx )
143
- if err := result .Error (); err != nil {
137
+ Do (ctx ).Into (& out ); err != nil {
144
138
return nil , err
145
139
}
146
140
147
- retBytes , err := result .Raw ()
148
- if err != nil {
149
- return nil , err
150
- }
151
- uncastObj , err := runtime .Decode (unstructured .UnstructuredJSONScheme , retBytes )
152
- if err != nil {
153
- return nil , err
154
- }
155
- return uncastObj .(* unstructured.Unstructured ), nil
141
+ return & out , nil
156
142
}
157
143
158
144
func (c * dynamicResourceClient ) Update (ctx context.Context , obj * unstructured.Unstructured , opts metav1.UpdateOptions , subresources ... string ) (* unstructured.Unstructured , error ) {
@@ -167,31 +153,18 @@ func (c *dynamicResourceClient) Update(ctx context.Context, obj *unstructured.Un
167
153
if err := validateNamespaceWithOptionalName (c .namespace , name ); err != nil {
168
154
return nil , err
169
155
}
170
- outBytes , err := runtime .Encode (unstructured .UnstructuredJSONScheme , obj )
171
- if err != nil {
172
- return nil , err
173
- }
174
156
175
- result := c .client .client .
157
+ var out unstructured.Unstructured
158
+ if err := c .client .client .
176
159
Put ().
177
160
AbsPath (append (c .makeURLSegments (name ), subresources ... )... ).
178
- SetHeader ("Content-Type" , runtime .ContentTypeJSON ).
179
- Body (outBytes ).
161
+ Body (obj ).
180
162
SpecificallyVersionedParams (& opts , dynamicParameterCodec , versionV1 ).
181
- Do (ctx )
182
- if err := result .Error (); err != nil {
163
+ Do (ctx ).Into (& out ); err != nil {
183
164
return nil , err
184
165
}
185
166
186
- retBytes , err := result .Raw ()
187
- if err != nil {
188
- return nil , err
189
- }
190
- uncastObj , err := runtime .Decode (unstructured .UnstructuredJSONScheme , retBytes )
191
- if err != nil {
192
- return nil , err
193
- }
194
- return uncastObj .(* unstructured.Unstructured ), nil
167
+ return & out , nil
195
168
}
196
169
197
170
func (c * dynamicResourceClient ) UpdateStatus (ctx context.Context , obj * unstructured.Unstructured , opts metav1.UpdateOptions ) (* unstructured.Unstructured , error ) {
@@ -206,31 +179,18 @@ func (c *dynamicResourceClient) UpdateStatus(ctx context.Context, obj *unstructu
206
179
if err := validateNamespaceWithOptionalName (c .namespace , name ); err != nil {
207
180
return nil , err
208
181
}
209
- outBytes , err := runtime .Encode (unstructured .UnstructuredJSONScheme , obj )
210
- if err != nil {
211
- return nil , err
212
- }
213
182
214
- result := c .client .client .
183
+ var out unstructured.Unstructured
184
+ if err := c .client .client .
215
185
Put ().
216
186
AbsPath (append (c .makeURLSegments (name ), "status" )... ).
217
- SetHeader ("Content-Type" , runtime .ContentTypeJSON ).
218
- Body (outBytes ).
187
+ Body (obj ).
219
188
SpecificallyVersionedParams (& opts , dynamicParameterCodec , versionV1 ).
220
- Do (ctx )
221
- if err := result .Error (); err != nil {
189
+ Do (ctx ).Into (& out ); err != nil {
222
190
return nil , err
223
191
}
224
192
225
- retBytes , err := result .Raw ()
226
- if err != nil {
227
- return nil , err
228
- }
229
- uncastObj , err := runtime .Decode (unstructured .UnstructuredJSONScheme , retBytes )
230
- if err != nil {
231
- return nil , err
232
- }
233
- return uncastObj .(* unstructured.Unstructured ), nil
193
+ return & out , nil
234
194
}
235
195
236
196
func (c * dynamicResourceClient ) Delete (ctx context.Context , name string , opts metav1.DeleteOptions , subresources ... string ) error {
@@ -240,16 +200,11 @@ func (c *dynamicResourceClient) Delete(ctx context.Context, name string, opts me
240
200
if err := validateNamespaceWithOptionalName (c .namespace , name ); err != nil {
241
201
return err
242
202
}
243
- deleteOptionsByte , err := runtime .Encode (deleteOptionsCodec .LegacyCodec (schema.GroupVersion {Version : "v1" }), & opts )
244
- if err != nil {
245
- return err
246
- }
247
203
248
204
result := c .client .client .
249
205
Delete ().
250
206
AbsPath (append (c .makeURLSegments (name ), subresources ... )... ).
251
- SetHeader ("Content-Type" , runtime .ContentTypeJSON ).
252
- Body (deleteOptionsByte ).
207
+ Body (& opts ).
253
208
Do (ctx )
254
209
return result .Error ()
255
210
}
@@ -259,16 +214,10 @@ func (c *dynamicResourceClient) DeleteCollection(ctx context.Context, opts metav
259
214
return err
260
215
}
261
216
262
- deleteOptionsByte , err := runtime .Encode (deleteOptionsCodec .LegacyCodec (schema.GroupVersion {Version : "v1" }), & opts )
263
- if err != nil {
264
- return err
265
- }
266
-
267
217
result := c .client .client .
268
218
Delete ().
269
219
AbsPath (c .makeURLSegments ("" )... ).
270
- SetHeader ("Content-Type" , runtime .ContentTypeJSON ).
271
- Body (deleteOptionsByte ).
220
+ Body (& opts ).
272
221
SpecificallyVersionedParams (& listOptions , dynamicParameterCodec , versionV1 ).
273
222
Do (ctx )
274
223
return result .Error ()
@@ -281,20 +230,15 @@ func (c *dynamicResourceClient) Get(ctx context.Context, name string, opts metav
281
230
if err := validateNamespaceWithOptionalName (c .namespace , name ); err != nil {
282
231
return nil , err
283
232
}
284
- result := c .client .client .Get ().AbsPath (append (c .makeURLSegments (name ), subresources ... )... ).SpecificallyVersionedParams (& opts , dynamicParameterCodec , versionV1 ).Do (ctx )
285
- if err := result .Error (); err != nil {
286
- return nil , err
287
- }
288
- retBytes , err := result .Raw ()
289
- if err != nil {
290
- return nil , err
291
- }
292
- obj := & unstructured.Unstructured {}
293
- err = runtime .DecodeInto (unstructured .UnstructuredJSONScheme , retBytes , obj )
294
- if err != nil {
233
+ var out unstructured.Unstructured
234
+ if err := c .client .client .
235
+ Get ().
236
+ AbsPath (append (c .makeURLSegments (name ), subresources ... )... ).
237
+ SpecificallyVersionedParams (& opts , dynamicParameterCodec , versionV1 ).
238
+ Do (ctx ).Into (& out ); err != nil {
295
239
return nil , err
296
240
}
297
- return obj , nil
241
+ return & out , nil
298
242
}
299
243
300
244
func (c * dynamicResourceClient ) List (ctx context.Context , opts metav1.ListOptions ) (* unstructured.UnstructuredList , error ) {
@@ -319,27 +263,15 @@ func (c *dynamicResourceClient) list(ctx context.Context, opts metav1.ListOption
319
263
if err := validateNamespaceWithOptionalName (c .namespace ); err != nil {
320
264
return nil , err
321
265
}
322
- result := c .client .client .Get ().AbsPath (c .makeURLSegments ("" )... ).SpecificallyVersionedParams (& opts , dynamicParameterCodec , versionV1 ).Do (ctx )
323
- if err := result .Error (); err != nil {
324
- return nil , err
325
- }
326
- retBytes , err := result .Raw ()
327
- if err != nil {
328
- return nil , err
329
- }
330
- uncastObj , err := runtime .Decode (unstructured .UnstructuredJSONScheme , retBytes )
331
- if err != nil {
332
- return nil , err
333
- }
334
- if list , ok := uncastObj .(* unstructured.UnstructuredList ); ok {
335
- return list , nil
336
- }
337
-
338
- list , err := uncastObj .(* unstructured.Unstructured ).ToList ()
339
- if err != nil {
266
+ var out unstructured.UnstructuredList
267
+ if err := c .client .client .
268
+ Get ().
269
+ AbsPath (c .makeURLSegments ("" )... ).
270
+ SpecificallyVersionedParams (& opts , dynamicParameterCodec , versionV1 ).
271
+ Do (ctx ).Into (& out ); err != nil {
340
272
return nil , err
341
273
}
342
- return list , nil
274
+ return & out , nil
343
275
}
344
276
345
277
// watchList establishes a watch stream with the server and returns an unstructured list.
@@ -380,24 +312,16 @@ func (c *dynamicResourceClient) Patch(ctx context.Context, name string, pt types
380
312
if err := validateNamespaceWithOptionalName (c .namespace , name ); err != nil {
381
313
return nil , err
382
314
}
383
- result := c .client .client .
315
+ var out unstructured.Unstructured
316
+ if err := c .client .client .
384
317
Patch (pt ).
385
318
AbsPath (append (c .makeURLSegments (name ), subresources ... )... ).
386
319
Body (data ).
387
320
SpecificallyVersionedParams (& opts , dynamicParameterCodec , versionV1 ).
388
- Do (ctx )
389
- if err := result .Error (); err != nil {
390
- return nil , err
391
- }
392
- retBytes , err := result .Raw ()
393
- if err != nil {
321
+ Do (ctx ).Into (& out ); err != nil {
394
322
return nil , err
395
323
}
396
- uncastObj , err := runtime .Decode (unstructured .UnstructuredJSONScheme , retBytes )
397
- if err != nil {
398
- return nil , err
399
- }
400
- return uncastObj .(* unstructured.Unstructured ), nil
324
+ return & out , nil
401
325
}
402
326
403
327
func (c * dynamicResourceClient ) Apply (ctx context.Context , name string , obj * unstructured.Unstructured , opts metav1.ApplyOptions , subresources ... string ) (* unstructured.Unstructured , error ) {
@@ -435,12 +359,13 @@ func (c *dynamicResourceClient) Apply(ctx context.Context, name string, obj *uns
435
359
if err != nil {
436
360
return nil , err
437
361
}
438
- uncastObj , err := runtime . Decode ( unstructured .UnstructuredJSONScheme , retBytes )
439
- if err != nil {
362
+ var out unstructured.Unstructured
363
+ if err := runtime . DecodeInto ( unstructured . UnstructuredJSONScheme , retBytes , & out ); err != nil {
440
364
return nil , err
441
365
}
442
- return uncastObj .( * unstructured. Unstructured ) , nil
366
+ return & out , nil
443
367
}
368
+
444
369
func (c * dynamicResourceClient ) ApplyStatus (ctx context.Context , name string , obj * unstructured.Unstructured , opts metav1.ApplyOptions ) (* unstructured.Unstructured , error ) {
445
370
return c .Apply (ctx , name , obj , opts , "status" )
446
371
}
0 commit comments