Skip to content

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

Conversation

dirrao
Copy link
Contributor

@dirrao dirrao commented Nov 28, 2023

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

@k8s-ci-robot k8s-ci-robot added the do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. label Nov 28, 2023
Copy link

linux-foundation-easycla bot commented Nov 28, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: dirrao / name: Gopal Dirisala (5194426)

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Nov 28, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @dirrao!

It looks like this is your first PR to kubernetes-client/python 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-client/python has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Nov 28, 2023
@dirrao dirrao force-pushed the 2142-dynamic-client-empty-results-bug branch from c6a4801 to de1a14f Compare November 28, 2023 07:55
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Nov 28, 2023
@dirrao dirrao force-pushed the 2142-dynamic-client-empty-results-bug branch from 4d4f68a to 9f81f98 Compare November 28, 2023 08:31
@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 28, 2023
@dirrao dirrao force-pushed the 2142-dynamic-client-empty-results-bug branch from 9f81f98 to 5194426 Compare November 28, 2023 08:33
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 28, 2023
@yliaog
Copy link
Contributor

yliaog commented Nov 28, 2023

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 28, 2023
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 28, 2023
@dirrao
Copy link
Contributor Author

dirrao commented Nov 29, 2023

/release-note-none

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Nov 29, 2023
@k8s-ci-robot k8s-ci-robot merged commit 1992802 into kubernetes-client:master Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamic Client list pods as PartialObjectMetadataList is throwing exception when there is no matching labels filters
3 participants