@@ -17,6 +17,7 @@ limitations under the License.
17
17
package dynamic
18
18
19
19
import (
20
+ "fmt"
20
21
"io"
21
22
22
23
"k8s.io/apimachinery/pkg/api/meta"
@@ -102,6 +103,9 @@ func (c *dynamicResourceClient) Create(obj *unstructured.Unstructured, opts meta
102
103
return nil , err
103
104
}
104
105
name = accessor .GetName ()
106
+ if len (name ) == 0 {
107
+ return nil , fmt .Errorf ("name is required" )
108
+ }
105
109
}
106
110
107
111
result := c .client .client .
@@ -130,14 +134,18 @@ func (c *dynamicResourceClient) Update(obj *unstructured.Unstructured, opts meta
130
134
if err != nil {
131
135
return nil , err
132
136
}
137
+ name := accessor .GetName ()
138
+ if len (name ) == 0 {
139
+ return nil , fmt .Errorf ("name is required" )
140
+ }
133
141
outBytes , err := runtime .Encode (unstructured .UnstructuredJSONScheme , obj )
134
142
if err != nil {
135
143
return nil , err
136
144
}
137
145
138
146
result := c .client .client .
139
147
Put ().
140
- AbsPath (append (c .makeURLSegments (accessor . GetName () ), subresources ... )... ).
148
+ AbsPath (append (c .makeURLSegments (name ), subresources ... )... ).
141
149
Body (outBytes ).
142
150
SpecificallyVersionedParams (& opts , dynamicParameterCodec , versionV1 ).
143
151
Do ()
@@ -161,6 +169,10 @@ func (c *dynamicResourceClient) UpdateStatus(obj *unstructured.Unstructured, opt
161
169
if err != nil {
162
170
return nil , err
163
171
}
172
+ name := accessor .GetName ()
173
+ if len (name ) == 0 {
174
+ return nil , fmt .Errorf ("name is required" )
175
+ }
164
176
165
177
outBytes , err := runtime .Encode (unstructured .UnstructuredJSONScheme , obj )
166
178
if err != nil {
@@ -169,7 +181,7 @@ func (c *dynamicResourceClient) UpdateStatus(obj *unstructured.Unstructured, opt
169
181
170
182
result := c .client .client .
171
183
Put ().
172
- AbsPath (append (c .makeURLSegments (accessor . GetName () ), "status" )... ).
184
+ AbsPath (append (c .makeURLSegments (name ), "status" )... ).
173
185
Body (outBytes ).
174
186
SpecificallyVersionedParams (& opts , dynamicParameterCodec , versionV1 ).
175
187
Do ()
@@ -189,6 +201,9 @@ func (c *dynamicResourceClient) UpdateStatus(obj *unstructured.Unstructured, opt
189
201
}
190
202
191
203
func (c * dynamicResourceClient ) Delete (name string , opts * metav1.DeleteOptions , subresources ... string ) error {
204
+ if len (name ) == 0 {
205
+ return fmt .Errorf ("name is required" )
206
+ }
192
207
if opts == nil {
193
208
opts = & metav1.DeleteOptions {}
194
209
}
@@ -224,6 +239,9 @@ func (c *dynamicResourceClient) DeleteCollection(opts *metav1.DeleteOptions, lis
224
239
}
225
240
226
241
func (c * dynamicResourceClient ) Get (name string , opts metav1.GetOptions , subresources ... string ) (* unstructured.Unstructured , error ) {
242
+ if len (name ) == 0 {
243
+ return nil , fmt .Errorf ("name is required" )
244
+ }
227
245
result := c .client .client .Get ().AbsPath (append (c .makeURLSegments (name ), subresources ... )... ).SpecificallyVersionedParams (& opts , dynamicParameterCodec , versionV1 ).Do ()
228
246
if err := result .Error (); err != nil {
229
247
return nil , err
@@ -292,6 +310,9 @@ func (c *dynamicResourceClient) Watch(opts metav1.ListOptions) (watch.Interface,
292
310
}
293
311
294
312
func (c * dynamicResourceClient ) Patch (name string , pt types.PatchType , data []byte , opts metav1.PatchOptions , subresources ... string ) (* unstructured.Unstructured , error ) {
313
+ if len (name ) == 0 {
314
+ return nil , fmt .Errorf ("name is required" )
315
+ }
295
316
result := c .client .client .
296
317
Patch (pt ).
297
318
AbsPath (append (c .makeURLSegments (name ), subresources ... )... ).
0 commit comments