@@ -135,6 +135,121 @@ def test_cluster_custom_resources(self):
135
135
changeme_api = client .resources .get (
136
136
api_version = 'apps.example.com/v1' , kind = 'ClusterChangeMe' )
137
137
138
+ def test_async_namespaced_custom_resources (self ):
139
+ client = DynamicClient (api_client .ApiClient (configuration = self .config ))
140
+
141
+ with self .assertRaises (ResourceNotFoundError ):
142
+ changeme_api = client .resources .get (
143
+ api_version = 'apps.example.com/v1' , kind = 'ChangeMe' )
144
+
145
+ crd_api = client .resources .get (
146
+ api_version = 'apiextensions.k8s.io/v1beta1' ,
147
+ kind = 'CustomResourceDefinition' )
148
+
149
+ name = 'changemes.apps.example.com'
150
+
151
+ crd_manifest = {
152
+ 'apiVersion' : 'apiextensions.k8s.io/v1beta1' ,
153
+ 'kind' : 'CustomResourceDefinition' ,
154
+ 'metadata' : {
155
+ 'name' : name ,
156
+ },
157
+ 'spec' : {
158
+ 'group' : 'apps.example.com' ,
159
+ 'names' : {
160
+ 'kind' : 'ChangeMe' ,
161
+ 'listKind' : 'ChangeMeList' ,
162
+ 'plural' : 'changemes' ,
163
+ 'singular' : 'changeme' ,
164
+ },
165
+ 'scope' : 'Namespaced' ,
166
+ 'version' : 'v1' ,
167
+ 'subresources' : {
168
+ 'status' : {}
169
+ }
170
+ }
171
+ }
172
+ async_resp = crd_api .create (crd_manifest , async_req = True )
173
+
174
+ self .assertEqual (name , async_resp .metadata .name )
175
+ self .assertTrue (async_resp .status )
176
+
177
+ async_resp = crd_api .get (
178
+ name = name ,
179
+ async_req = True
180
+ )
181
+ self .assertEqual (name , async_resp .metadata .name )
182
+ self .assertTrue (async_resp .status )
183
+
184
+ try :
185
+ changeme_api = client .resources .get (
186
+ api_version = 'apps.example.com/v1' , kind = 'ChangeMe' )
187
+ except ResourceNotFoundError :
188
+ # Need to wait a sec for the discovery layer to get updated
189
+ time .sleep (2 )
190
+ changeme_api = client .resources .get (
191
+ api_version = 'apps.example.com/v1' , kind = 'ChangeMe' )
192
+
193
+ async_resp = changeme_api .get (async_req = True )
194
+ self .assertEqual (async_resp .items , [])
195
+
196
+ changeme_name = 'custom-resource' + short_uuid ()
197
+ changeme_manifest = {
198
+ 'apiVersion' : 'apps.example.com/v1' ,
199
+ 'kind' : 'ChangeMe' ,
200
+ 'metadata' : {
201
+ 'name' : changeme_name ,
202
+ },
203
+ 'spec' : {}
204
+ }
205
+
206
+ async_resp = changeme_api .create (body = changeme_manifest , namespace = 'default' , async_req = True )
207
+ self .assertEqual (async_resp .metadata .name , changeme_name )
208
+
209
+ async_resp = changeme_api .get (name = changeme_name , namespace = 'default' , async_req = True )
210
+ self .assertEqual (async_resp .metadata .name , changeme_name )
211
+
212
+ changeme_manifest ['spec' ]['size' ] = 3
213
+ async_resp = changeme_api .patch (
214
+ body = changeme_manifest ,
215
+ namespace = 'default' ,
216
+ content_type = 'application/merge-patch+json' ,
217
+ async_req = True
218
+ )
219
+ self .assertEqual (async_resp .spec .size , 3 )
220
+
221
+ async_resp = changeme_api .get (name = changeme_name , namespace = 'default' , async_req = True )
222
+ self .assertEqual (async_resp .spec .size , 3 )
223
+
224
+ async_resp = changeme_api .get (namespace = 'default' , async_req = True )
225
+ self .assertEqual (len (async_resp .items ), 1 )
226
+
227
+ async_resp = changeme_api .get (async_req = True )
228
+ self .assertEqual (len (async_resp .items ), 1 )
229
+
230
+ async_resp = changeme_api .delete (
231
+ name = changeme_name ,
232
+ namespace = 'default' ,
233
+ async_req = True
234
+ )
235
+
236
+ async_resp = changeme_api .get (namespace = 'default' , async_req = True )
237
+ self .assertEqual (len (async_resp .items ), 0 )
238
+
239
+ async_resp = changeme_api .get (async_req = True )
240
+ self .assertEqual (len (async_resp .items ), 0 )
241
+
242
+ async_resp = crd_api .delete (
243
+ name = name ,
244
+ async_req = True
245
+ )
246
+
247
+ time .sleep (2 )
248
+ client .resources .invalidate_cache ()
249
+ with self .assertRaises (ResourceNotFoundError ):
250
+ changeme_api = client .resources .get (
251
+ api_version = 'apps.example.com/v1' , kind = 'ChangeMe' )
252
+
138
253
def test_namespaced_custom_resources (self ):
139
254
client = DynamicClient (api_client .ApiClient (configuration = self .config ))
140
255
0 commit comments