Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix DynamicClient.server_side_apply #1850

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

Merged

Conversation

kariya-mitsuru
Copy link
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

DynamicClient.server_side_apply is obviously designed to accept a dict or a ResourceInstance as body like other methods.
(This is why the name and namespace parameters are treated as optional.)
However, if a dict or a ResourceInstance is passed actually, an error occurs because RESTClientObject.rest cannot interpret the Content-Type application/apply-patch+yaml.

So, modify RESTClientObject.rest to treat application/apply-patch+yaml as other json-based Content-Types.

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Yes.

You can no longer specify an argument of type str or bytes for the body parameter of DynamicClient.server_side_apply.
Pass an argument of type dict or ResourceInstance instead.
Accordingly, the name and namespace parameters can now be omitted if the body argument contains appropriate metadata.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

DynamicClient.server_side_apply is designed to accept a dict or a
ResourceInstance as body.  However, if a dict or a ResourceInstance is
passed actually, an error occurs because RESTClientObject.rest cannot
interpret the Content-Type application/apply-patch+yaml.

So, modify RESTClientObject.rest to treat application/apply-patch+yaml
as other json-based Content-Types.
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. labels Jul 5, 2022
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jul 5, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: kariya-mitsuru / name: Mitsuru Kariya (5529ded)

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Jul 5, 2022
@k8s-ci-robot
Copy link
Contributor

Welcome @kariya-mitsuru!

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 requested review from fabianvf and roycaihw July 5, 2022 16:56
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. 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 Jul 5, 2022
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

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 5, 2022
@fabianvf
Copy link
Contributor

fabianvf commented Jul 5, 2022

@abikouo any thoughts?

resp = api.server_side_apply(
name=name, namespace='default', body=body,
Copy link
Member

Choose a reason for hiding this comment

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

body=body

Does this mean users can no longer pass JSON as the body? Is this considered a breaking change?

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be a breaking change, though I'm not sure that we intended for this to accept a string in the first place. Could add a little bit of logic to server_side_apply to attempt to yaml load the content in order to preserve that behavior if it's what we want

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure that we intended for this to accept a string in the first place

I agree. I'm okay with calling it out as a breaking change in the release notes. We could provide instruction/util to help users switch/keep the behavior, but the default behavior doesn't have to accept a string.

@roycaihw
Copy link
Member

roycaihw commented Jul 5, 2022

/lgtm
/approve

/hold
please feel free to unhold #1850 (comment)

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 5, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fabianvf, kariya-mitsuru, roycaihw

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 Jul 5, 2022
@abikouo
Copy link
Contributor

abikouo commented Jul 6, 2022

@abikouo any thoughts?

lgtm, it makes sense!!

@roycaihw
Copy link
Member

roycaihw commented Jul 6, 2022

/unhold

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 6, 2022
@k8s-ci-robot k8s-ci-robot merged commit e8a10b1 into kubernetes-client:master Jul 6, 2022
@kariya-mitsuru kariya-mitsuru deleted the fix-server-side-apply branch July 8, 2022 04:17
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. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants