Skip to content

Commit 8b2466c

Browse files
Fix Custom Resource pagination hang (#547)
1 parent ce3e0ac commit 8b2466c

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

kr8s/_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ async def _async_get_single(
528528
if (
529529
"metadata" in resourcelist
530530
and "continue" in resourcelist["metadata"]
531+
and resourcelist["metadata"]["continue"]
531532
):
532533
continue_paging = True
533534
params["continue"] = resourcelist["metadata"]["continue"]

kr8s/conftest.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,50 @@ async def example_deployment_spec(ns):
108108
}
109109

110110

111+
@pytest.fixture
112+
async def example_crd_spec():
113+
spec = {
114+
"apiVersion": "apiextensions.k8s.io/v1",
115+
"kind": "CustomResourceDefinition",
116+
"metadata": {"name": "shirts.stable.example.com"},
117+
"spec": {
118+
"group": "stable.example.com",
119+
"scope": "Namespaced",
120+
"names": {"plural": "shirts", "singular": "shirt", "kind": "Shirt"},
121+
"versions": [
122+
{
123+
"name": "v1",
124+
"served": True,
125+
"storage": True,
126+
"schema": {
127+
"openAPIV3Schema": {
128+
"type": "object",
129+
"properties": {
130+
"spec": {
131+
"type": "object",
132+
"properties": {
133+
"color": {"type": "string"},
134+
"size": {"type": "string"},
135+
},
136+
}
137+
},
138+
}
139+
},
140+
"selectableFields": [
141+
{"jsonPath": ".spec.color"},
142+
{"jsonPath": ".spec.size"},
143+
],
144+
"additionalPrinterColumns": [
145+
{"jsonPath": ".spec.color", "name": "Color", "type": "string"},
146+
{"jsonPath": ".spec.size", "name": "Size", "type": "string"},
147+
],
148+
}
149+
],
150+
},
151+
}
152+
yield spec
153+
154+
111155
def check_socket(host, port):
112156
with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock:
113157
return sock.connect_ex((host, port)) == 0
@@ -163,8 +207,9 @@ def serviceaccount(k8s_cluster, k8s_token):
163207
host, port = _hostport.split(":")
164208

165209
# Create a temporary directory and populate it with the serviceaccount files
166-
with tempfile.TemporaryDirectory() as tempdir, set_env(
167-
KUBERNETES_SERVICE_HOST=host, KUBERNETES_SERVICE_PORT=port
210+
with (
211+
tempfile.TemporaryDirectory() as tempdir,
212+
set_env(KUBERNETES_SERVICE_HOST=host, KUBERNETES_SERVICE_PORT=port),
168213
):
169214
tempdir = Path(tempdir)
170215
# Create ca.crt in tempdir from the certificate-authority-data in kubeconfig

kr8s/tests/test_api.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
from kr8s.asyncio.objects import Pod, Table
1414

1515

16+
@pytest.fixture
17+
async def example_crd(example_crd_spec):
18+
example = await kr8s.asyncio.objects.CustomResourceDefinition(example_crd_spec)
19+
if not await example.exists():
20+
await example.create()
21+
assert example in [
22+
crd async for crd in kr8s.asyncio.get("customresourcedefinitions")
23+
]
24+
yield example
25+
await example.delete()
26+
27+
1628
async def test_factory_bypass() -> None:
1729
with pytest.raises(ValueError, match="kr8s.api()"):
1830
_ = kr8s.Api()
@@ -160,6 +172,11 @@ async def test_get_pods(namespace) -> None:
160172
assert isinstance(pods[0], Pod)
161173

162174

175+
async def test_get_custom_resouces(example_crd) -> None:
176+
async for shirt in kr8s.asyncio.get(example_crd.name):
177+
assert shirt
178+
179+
163180
async def test_get_pods_as_table() -> None:
164181
api = await kr8s.asyncio.api()
165182
async for pods in api.get("pods", namespace="kube-system", as_object=Table):

0 commit comments

Comments
 (0)