Skip to content

Commit 5098e73

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

File tree

1 file changed

+91
-1
lines changed

1 file changed

+91
-1
lines changed

kubernetes_asyncio/e2e_test/test_client.py

+91-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
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,
22+
core_v1_api,
23+
custom_objects_api
24+
)
2125
from kubernetes_asyncio.e2e_test import base
2226
from kubernetes_asyncio.stream import WsApiClient
2327

@@ -187,6 +191,92 @@ async def test_service_apis(self):
187191
name=name, body={}, namespace="default"
188192
)
189193

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

0 commit comments

Comments
 (0)