-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Return empty list when there is no matching resource instsnce items … #2155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return empty list when there is no matching resource instsnce items … #2155
Conversation
|
Welcome @dirrao! |
c6a4801
to
de1a14f
Compare
4d4f68a
to
9f81f98
Compare
9f81f98
to
5194426
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dirrao, yliaog The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/release-note-none |
What type of PR is this?
/kind bug
When using dynamic client to list pods in PartialObjectMetadataList format. When there no matching pods with labels, its throwing exception rather than return empty list. This MR will return empty list instead of throwing exception.
Fixes: #2142
Special notes for your reviewer:
Return default empty list when there is nothing to return
Does this PR introduce a user-facing change?
No
It gracefully return empty list when there is matching resources
#fetching the node api
api = client.resources.get(api_version="v1", kind="Pod")
#Creating a custom header
params = {'header_params': {'Accept': 'application/json;as=PartialObjectMetadataList;v=v1;g=meta.k8s.io'}, 'query_params': [('labelSelector', 'role=xyz')], 'namespace': 'default'}
resp = api.get(**params)
Traceback (most recent call last):
File "dynamic_client.py", line 30, in
main()
File "dynamic_client.py", line 16, in main
resp = api.get(**params)
File "/usr/local/miniconda/lib/python3.7/site-packages/kubernetes/dynamic/client.py", line 112, in get
return self.request('get', path, **kwargs)
File "/usr/local/miniconda/lib/python3.7/site-packages/kubernetes/dynamic/client.py", line 62, in inner
return serializer(self, json.loads(resp.data.decode('utf8')))
File "/usr/local/miniconda/lib/python3.7/site-packages/kubernetes/dynamic/resource.py", line 291, in init
for item in instance['items']:
TypeError: 'NoneType' object is not iterable