|
17 | 17 | from unittest import IsolatedAsyncioTestCase
|
18 | 18 |
|
19 | 19 | 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 | +) |
21 | 25 | from kubernetes_asyncio.e2e_test import base
|
22 | 26 | from kubernetes_asyncio.stream import WsApiClient
|
23 | 27 |
|
@@ -187,6 +191,92 @@ async def test_service_apis(self):
|
187 | 191 | name=name, body={}, namespace="default"
|
188 | 192 | )
|
189 | 193 |
|
| 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 | + |
190 | 280 | async def test_replication_controller_apis(self):
|
191 | 281 | client = api_client.ApiClient(configuration=self.config)
|
192 | 282 | api = core_v1_api.CoreV1Api(client)
|
|
0 commit comments