Skip to content
This repository has been archived by the owner on Mar 13, 2022. It is now read-only.

Make duck-typing checking in serialize_body method more restrictive #241

Merged

Conversation

piglei
Copy link
Contributor

@piglei piglei commented May 28, 2021

Thebody parameter in DynamicClient's most methods currently accepts both dict type and ResourceInstance type. This was achieved by calling serialize_body() before mading any requests.

But in current implementation, the duck-typing style checking in serialize_body was kind of meaning-less---ResourceInstance type has overwritten it's __getattr__ method, so basically it's instances can pass every hasattr(...) check.

>>> inst = ResourceInstance(None, {'kind': 'Pod'})
>>> hasattr(inst, 'to_dict')
True
>>> hasattr(inst, 'to_dict_whatever_name')
True

This PR makes the checking in serialize_body() method more restrictive and also add some related unit tests.

Release Note:

Type checking in `Client.serialize_body()` was made more restrictive and robust.

@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 May 28, 2021
@k8s-ci-robot k8s-ci-robot requested review from roycaihw and yliaog May 28, 2021 07:44
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels May 28, 2021
@k8s-ci-robot
Copy link
Contributor

Welcome @piglei!

It looks like this is your first PR to kubernetes-client/python-base 🎉. 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-base 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/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 28, 2021
@roycaihw
Copy link
Member

roycaihw commented Jun 7, 2021

/assign @yliaog

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 16, 2021
@yliaog
Copy link
Contributor

yliaog commented Aug 16, 2021

/lgtm

/assign @fabianvf

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 16, 2021
Copy link
Contributor

@fabianvf fabianvf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm, needs rebase though

@yliaog
Copy link
Contributor

yliaog commented Aug 18, 2021

/approve

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed lgtm Indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 18, 2021
@piglei
Copy link
Contributor Author

piglei commented Aug 22, 2021

/lgtm, needs rebase though

Rebased with upstream/master.

OWNERS Outdated Show resolved Hide resolved
config/__init__.py Outdated Show resolved Hide resolved
@piglei piglei changed the base branch from master to b1 August 23, 2021 02:13
@k8s-ci-robot k8s-ci-robot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Aug 23, 2021
@piglei piglei changed the base branch from b1 to master August 23, 2021 02:13
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 23, 2021
@piglei
Copy link
Contributor Author

piglei commented Aug 23, 2021

PR refreshed.

@k8s-ci-robot k8s-ci-robot removed the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 23, 2021
@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please sign in with your organization's credentials at https://identity.linuxfoundation.org/projects/cncf to be authorized.
  • If you have done the above and are still having issues with the CLA being reported as unsigned, please log a ticket with the Linux Foundation Helpdesk: https://support.linuxfoundation.org/
  • Should you encounter any issues with the Linux Foundation Helpdesk, send a message to the backup e-mail support address at: [email protected]

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Aug 23, 2021
@yliaog
Copy link
Contributor

yliaog commented Aug 23, 2021

please squash the commits

@piglei piglei force-pushed the enhance-body-serialization branch from fd876b7 to 66a45cd Compare August 23, 2021 06:50
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Aug 23, 2021
@piglei
Copy link
Contributor Author

piglei commented Aug 23, 2021

please squash the commits

Done

@yliaog
Copy link
Contributor

yliaog commented Aug 23, 2021

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 23, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fabianvf, piglei, 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

@fabianvf
Copy link
Contributor

@piglei just needs the release note and it should be good to go

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. 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 Sep 16, 2021
@piglei
Copy link
Contributor Author

piglei commented Sep 16, 2021

@piglei just needs the release note and it should be good to go

Thanks for reminding me, the release note was now added.

@k8s-ci-robot k8s-ci-robot merged commit b0afc93 into kubernetes-client:master Sep 16, 2021
@piglei piglei deleted the enhance-body-serialization branch September 16, 2021 02:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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 Indicates that a PR is ready to be merged. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants