diff --git a/kr8s/_api.py b/kr8s/_api.py index 3ced1dd..c4fbee6 100644 --- a/kr8s/_api.py +++ b/kr8s/_api.py @@ -528,6 +528,7 @@ async def _async_get_single( if ( "metadata" in resourcelist and "continue" in resourcelist["metadata"] + and resourcelist["metadata"]["continue"] ): continue_paging = True params["continue"] = resourcelist["metadata"]["continue"] diff --git a/kr8s/conftest.py b/kr8s/conftest.py index bdfc761..97e202c 100644 --- a/kr8s/conftest.py +++ b/kr8s/conftest.py @@ -108,6 +108,50 @@ async def example_deployment_spec(ns): } +@pytest.fixture +async def example_crd_spec(): + spec = { + "apiVersion": "apiextensions.k8s.io/v1", + "kind": "CustomResourceDefinition", + "metadata": {"name": "shirts.stable.example.com"}, + "spec": { + "group": "stable.example.com", + "scope": "Namespaced", + "names": {"plural": "shirts", "singular": "shirt", "kind": "Shirt"}, + "versions": [ + { + "name": "v1", + "served": True, + "storage": True, + "schema": { + "openAPIV3Schema": { + "type": "object", + "properties": { + "spec": { + "type": "object", + "properties": { + "color": {"type": "string"}, + "size": {"type": "string"}, + }, + } + }, + } + }, + "selectableFields": [ + {"jsonPath": ".spec.color"}, + {"jsonPath": ".spec.size"}, + ], + "additionalPrinterColumns": [ + {"jsonPath": ".spec.color", "name": "Color", "type": "string"}, + {"jsonPath": ".spec.size", "name": "Size", "type": "string"}, + ], + } + ], + }, + } + yield spec + + def check_socket(host, port): with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock: return sock.connect_ex((host, port)) == 0 @@ -163,8 +207,9 @@ def serviceaccount(k8s_cluster, k8s_token): host, port = _hostport.split(":") # Create a temporary directory and populate it with the serviceaccount files - with tempfile.TemporaryDirectory() as tempdir, set_env( - KUBERNETES_SERVICE_HOST=host, KUBERNETES_SERVICE_PORT=port + with ( + tempfile.TemporaryDirectory() as tempdir, + set_env(KUBERNETES_SERVICE_HOST=host, KUBERNETES_SERVICE_PORT=port), ): tempdir = Path(tempdir) # Create ca.crt in tempdir from the certificate-authority-data in kubeconfig diff --git a/kr8s/tests/test_api.py b/kr8s/tests/test_api.py index d4010e8..af9081d 100644 --- a/kr8s/tests/test_api.py +++ b/kr8s/tests/test_api.py @@ -13,6 +13,18 @@ from kr8s.asyncio.objects import Pod, Table +@pytest.fixture +async def example_crd(example_crd_spec): + example = await kr8s.asyncio.objects.CustomResourceDefinition(example_crd_spec) + if not await example.exists(): + await example.create() + assert example in [ + crd async for crd in kr8s.asyncio.get("customresourcedefinitions") + ] + yield example + await example.delete() + + async def test_factory_bypass() -> None: with pytest.raises(ValueError, match="kr8s.api()"): _ = kr8s.Api() @@ -160,6 +172,11 @@ async def test_get_pods(namespace) -> None: assert isinstance(pods[0], Pod) +async def test_get_custom_resouces(example_crd) -> None: + async for shirt in kr8s.asyncio.get(example_crd.name): + assert shirt + + async def test_get_pods_as_table() -> None: api = await kr8s.asyncio.api() async for pods in api.get("pods", namespace="kube-system", as_object=Table):