-
Notifications
You must be signed in to change notification settings - Fork 71
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
Custom object json-patch #68
Comments
As you checked, patching custom objects supports |
When I tried to patch with json patch on a custom object using kubectl it worked, so assuming that the api server handles it. We should leave out the strategic patch since that does not make sense for a custom object, my wrong, at least until strategic patching functionality can be specified in a CRD. So I think that both json and merge patch should be specified in the swagger file. |
Fixed in the latest release - v10.0.0 |
Hi, seems to have got some issues now.
Generated
Then in
When patching, Content-Type contains 'json' and now since content type is The last setting of content type would need to be So best solution would be if the generated code would select the correct content type directly, based on method, body is list and allowed content types. Would that be possible? Alternatively, the What do you think @tomplus ? |
Thanks, definitely it needs to be fixed. |
Hi, I'm running into this issue now. Any quick way of working around the "media type not supported" error while your fix is not yet merged? |
Could you tell more about your use case? Do you try to use different merge strategy? |
I'm just trying to patch a custom object:
But it's throwing me an error on the Content Type:
All I want to do is to patch the resource whith the changes coming in, that used to work fine when I used the default library. The manifest I'm sending is rather simple:
|
Thanks. As a workaround you can try to send list with JSON Patch instructions to modify your CRD. This nice library https://github.com/stefankoegl/python-json-patch creates such patches from differences between dicts. |
Thanks @tomplus ! That did work. I had to make sure to remove the patches I didn't want as the new manifest would not have the UID and the other information from the existing resource:
It's now working fine! |
I have also been frustrated by this recently, specifically because the behavior differs from the official Python kubernetes client. There is a discussion here of why custom object patching in kubernetes-client works the way it does: So basically, it seems, kubernetes-client forces the caller to use application/merge-patch+json, where kubernetes_asyncio forces the use of application/json-patch+json. Both are probably wrong, or at least sub-optimal. I don't know if kubernetes_asyncio has a goal of 100% matching the kubernetes-client API, but it is a convenient quality when you are trying to convert from kubernetes-client to kubernetes_asyncio as I am. |
Totally agree, patching in this library should work in the same way as in the kubernetes-client. I wasn't aware of the differences but as you noticed both behavior are problematic. I've started working on fixing both libraries (by extending openapi-generator) and your post gives me additional motivation to end it up. Thanks. |
This issue continues to frustrate me as well. I am able to workaround it for now but just wanted to add my +1 |
There is a PR to track kubernetes-client/python#959 - it's already prepared and waits for review. |
First off, a huge thank you to @tomplus for his ongoing work to resolve this issue. In the meantime, I've found a somewhat ugly workaround that can be used in the interim. It turns out these headers can be set using @HaraldGustafsson @gcarrarom @hapatrick I know its been a while since your comments but heads up WRT to the above workaround |
@linkous8 Thanks for your workaround here -- when I used this, I needed to use |
Starting from v22.6.0 it's possible to call patch methods with forcing a content type. In a next big release (v30.x) there is a new version of logic to detect a content-type for a patch. There is also an example how to use different type of patch. Changes are already merged to master branch so feel free to test it in the meantime. Thanks. |
I noticed that most patch calls support all 3 patch types (json-patch, merge-patch, strategic-merge-patch), but the patch calls for custom objects (including for status and scale sub-resources) only support merge-patch.
For example compare
consumes
for the custom object from the swagger.json file:and
consumes
from Pod:This then prevents using json-patch instead of merge-patch. Kubectl handles it.
The code in
rest.py
then have some strange things since it actually use the first one only and then if a json-patch contenttype but not list switch to merge-patch. So would be good to have json-patch+json first also for custom objects.The text was updated successfully, but these errors were encountered: