Skip to content

Commit d886878

Browse files
committed
Add e2e custom object test
1 parent 043429a commit d886878

File tree

1 file changed

+89
-1
lines changed

1 file changed

+89
-1
lines changed

kubernetes_asyncio/e2e_test/test_client.py

+89-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
from unittest import IsolatedAsyncioTestCase
1818

1919
from kubernetes_asyncio.client import api_client
20-
from kubernetes_asyncio.client.api import core_v1_api
20+
from kubernetes_asyncio.client.api import (
21+
apiextensions_v1_api, core_v1_api, custom_objects_api,
22+
)
2123
from kubernetes_asyncio.e2e_test import base
2224
from kubernetes_asyncio.stream import WsApiClient
2325

@@ -187,6 +189,92 @@ async def test_service_apis(self):
187189
name=name, body={}, namespace="default"
188190
)
189191

192+
async def test_custom_objects_api(self):
193+
client = api_client.ApiClient(configuration=self.config)
194+
195+
apiextensions_api_client = apiextensions_v1_api.ApiextensionsV1Api(client)
196+
custom_objects_api_client = custom_objects_api.CustomObjectsApi(client)
197+
198+
name = 'clusterchangemes.apps.example.com'
199+
crd_manifest = {
200+
"apiVersion": "apiextensions.k8s.io/v1",
201+
"kind": "CustomResourceDefinition",
202+
"metadata": {
203+
"name": name,
204+
},
205+
"spec": {
206+
"group": "apps.example.com",
207+
"names": {
208+
"kind": "ClusterChangeMe",
209+
"listKind": "ClusterChangeMeList",
210+
"plural": "clusterchangemes",
211+
"singular": "clusterchangeme",
212+
},
213+
"scope": "Cluster",
214+
"versions": [
215+
{
216+
"name": "v1",
217+
"served": True,
218+
"storage": True,
219+
"schema": {
220+
"openAPIV3Schema": {
221+
"type": "object",
222+
"properties": {
223+
"spec": {
224+
"type": "object",
225+
"properties": {
226+
"size": {"type": "integer"}
227+
},
228+
}
229+
},
230+
}
231+
},
232+
}
233+
],
234+
},
235+
}
236+
custom_object_manifest = {
237+
'apiVersion': 'apps.example.com/v1',
238+
'kind': 'ClusterChangeMe',
239+
'metadata': {
240+
'name': "changeme-name",
241+
},
242+
'spec': {}
243+
}
244+
245+
await apiextensions_api_client.create_custom_resource_definition(
246+
crd_manifest
247+
)
248+
249+
await apiextensions_api_client.read_custom_resource_definition(
250+
crd_manifest["metadata"]["name"]
251+
)
252+
253+
await custom_objects_api_client.create_cluster_custom_object(
254+
crd_manifest["spec"]["group"],
255+
crd_manifest["spec"]["versions"][0]["name"],
256+
crd_manifest["spec"]["names"]["plural"],
257+
custom_object_manifest
258+
)
259+
260+
# json merge patch (implied)
261+
resp = await custom_objects_api_client.patch_cluster_custom_object(
262+
group=crd_manifest["spec"]["group"],
263+
version=crd_manifest["spec"]["versions"][0]["name"],
264+
plural=crd_manifest["spec"]["names"]["plural"],
265+
name=custom_object_manifest["metadata"]["name"],
266+
body={
267+
"spec": {
268+
"size": 0
269+
}
270+
},
271+
)
272+
self.assertEqual(resp["spec"]["size"], 0)
273+
274+
await apiextensions_api_client.delete_custom_resource_definition(
275+
crd_manifest["metadata"]["name"]
276+
)
277+
190278
async def test_replication_controller_apis(self):
191279
client = api_client.ApiClient(configuration=self.config)
192280
api = core_v1_api.CoreV1Api(client)

0 commit comments

Comments
 (0)