Skip to content

PatchNamespacedDeploymentWithHttpMessagesAsync provokes a "UnprocessableEntity" exception #510

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

Closed
KevinDitschke opened this issue Oct 30, 2020 · 15 comments
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@KevinDitschke
Copy link

I updated the kubernetes-client from version 2.0.29 to the latest version 3.0.4.
I'm using the method PatchNamespacedDeploymentWithHttpMessagesAsync to exchange the imageversion of a V1Deployment.

I passed a patch with the API object, the name and namespace like this:

var response = await _client.PatchNamespacedDeploymentWithHttpMessagesAsync(patchObject, deployment.Metadata.Name, deployment.Metadata.NamespaceProperty);

It results in this exception:
image

Reverting the version to 2.0.29 causes the method to work perfectly fine again.

What has changed between the versions, that this exception occurs? Are there properties missing on the patch object?

Thank you in advance!

@brendandburns
Copy link
Contributor

brendandburns commented Oct 30, 2020

Please see the discussion here:
#476

We had accidentally switched to JSONPatch in 2.0.29, and in 3.0.4 we switched back to Merge Patch.

Unfortunately we need a better option that allows you to choose, but we're not there yet.

@mprigge
Copy link

mprigge commented Nov 3, 2020

I've read #476 and I'm a little bit confused. The latest 3.0.7 is currently sending patches with a content type of application/merge-patch+json; charset=utf-8. This is resulting in 422 UnprocessableEntity from the API. Manually sending an otherwise identical patch with application/json-patch+json; charset=utf-8 works as expected. I'd been packing a JsonPatchDocument inside of V1Patch as the body. Is there a different means of constructing the patch body we should be using with the latest version which works with this content type?

@tg123
Copy link
Member

tg123 commented Nov 3, 2020

trying to find a solution to handle custom content type.
then will fix this issue

@narthollis
Copy link
Contributor

narthollis commented Nov 4, 2020

I am currently working around this by adding another DelegateHandler to my HttpClient pipeline:

            services
                .AddHttpClient("k8s")
                .ConfigurePrimaryHttpMessageHandler(Configuration.CreateDefaultHttpClientHandler())
                .AddHttpMessageHandler<ForceJsonPatchHandler>()
                .AddHttpMessageHandler(KubernetesClientConfiguration.CreateWatchHandler);
...

    public class ForceJsonPatchHandler : DelegatingHandler
    {
        protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            if (request.Method == HttpMethod.Patch && request.RequestUri.ToString().Contains("/configmaps/"))
            {
                request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json-patch+json");
            }

            return base.SendAsync(request, cancellationToken);
        }
    }

@RobLSDev
Copy link

RobLSDev commented Nov 4, 2020

Are there any code examples available to convert from json patching to merge patching? It seems like all of the existing patch examples in this repository use json, and would be broken by #476

@brendandburns
Copy link
Contributor

Merge patch is described in the RFC here:

https://tools.ietf.org/html/rfc7386

I will fix/update the patch example in the codebase.

@brendandburns
Copy link
Contributor

I sent a PR here:
#517

With a working example.

@RobLSDev
Copy link

RobLSDev commented Nov 6, 2020

So that PR includes a changes to the library itself. Am I correct in understanding that the examples won't work until we are on a version of the library that includes that PR?

@brendandburns
Copy link
Contributor

yes, that's correct.

note that you can always use the ReplaceFoo APIs instead of PatchFoo APIs to accomplish the same thing. (though you need to send a complete API object for the resource when you use Replace)

@mihaimyh
Copy link

Is the the only way to create patches going forward? Do we need to manually create Json strings?

mihaimyh added a commit to mihaimyh/HookTrigger that referenced this issue Nov 11, 2020
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 9, 2021
@mihaimyh
Copy link

/lifecycle stale

@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Mar 30, 2021
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-contributor-experience at kubernetes/community.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-contributor-experience at kubernetes/community.
/close

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

9 participants