Skip to content

Commit

Permalink
Bug fix: Fix issue with CRD listing. It seems k8s always send the `co…
Browse files Browse the repository at this point in the history
…ntinue` attribute (but with an empty string value) for this kind of resources. (#26)

Fixes #25
  • Loading branch information
gtsystem authored Jan 19, 2022
1 parent 89cb87e commit f11a73d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lightkube/core/generic_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def handle_response(self, method, resp, br):
return
data = resp.json()
if method == 'list':
if 'metadata' in data and 'continue' in data['metadata']:
if 'metadata' in data and data['metadata'].get('continue'):
cont = True
br.params['continue'] = data['metadata']['continue']
else:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='lightkube',
version="0.10.0",
version="0.10.1",
description='Lightweight kubernetes client library',
long_description=Path("README.md").read_text(),
long_description_content_type="text/markdown",
Expand Down
9 changes: 9 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ def test_list_namespaced(client: lightkube.Client):
assert [pod.metadata.name for pod in pods] == ['xx', 'yy']


@respx.mock
def test_list_crd(client: lightkube.Client):
"""CRD list seems to return always the 'continue' metadata attribute"""
resp = {'items': [{'metadata': {'name': 'xx'}}, {'metadata': {'name': 'yy'}}], 'metadata': {'continue': ''}}
respx.get("https://localhost:9443/api/v1/namespaces/default/pods").respond(json=resp)
pods = client.list(Pod)
assert [pod.metadata.name for pod in pods] == ['xx', 'yy']


@respx.mock
def test_list_global(client: lightkube.Client):
resp = {'items': [{'metadata': {'name': 'xx'}}, {'metadata': {'name': 'yy'}}]}
Expand Down

0 comments on commit f11a73d

Please sign in to comment.