Skip to content
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

Add an example of how to use patch. #450

Closed
brendandburns opened this issue May 14, 2020 · 3 comments · Fixed by #508
Closed

Add an example of how to use patch. #450

brendandburns opened this issue May 14, 2020 · 3 comments · Fixed by #508

Comments

@brendandburns
Copy link
Contributor

See #443 (comment)

@danquah
Copy link

danquah commented Jul 1, 2020

Just to make sure I understand this before looking into doing an example.

Lets take the example from #443 (comment)

 const k8sNetworkingApi = kc.makeApiClient(k8s.NetworkingV1beta1Api);
  const patchedIngress = {
    metadata: {
      annotations: {
        'nginx.ingress.kubernetes.io/cors-allow-origin': '*'
      }
    }
  }

  // The following gets rejected with a 
  // "Unsupported Media Type":
  //    the body of the request was in an unknown format - 
  //    accepted media types include: application/json-patch+json, 
  //    application/merge-patch+json, application/apply-patch+yaml
  k8sNetworkingApi.patchNamespacedIngress(ingressName, namespace, patchedIngress);

  // The fix is to do this:
  k8sNetworkingApi.patchNamespacedIngress(ingressName, namespace, patchedIngress, undefined, undefined, undefined, undefined,
    { headers: { 'content-type': 'application/merge-patch+json' } });

The problems boils down to this (again, as I understand it).

  • The generated openapi client code does not explicitly set a Content-Type for the PATCH request
  • The client code does set json: true causing request (the library) to set Content-Type: application/json
  • the api-server subsequently rejects the PATCH as it requires another Content-Type, eg. application/merge-patch+json

So, in other words: the generated client code that does the PATCH is incompatible with the api-server out of the box, and the (for this repo) official way of fixing this is to always provide the optional options argument and manually set the Content-Type header?

@saxicek
Copy link

saxicek commented Jul 19, 2020

@danquah Exactly. That is why I asked for the example - client code does not work out of the box, optional parameter which specifies content-type must be included. In my opinion it is fine to force developers to specify this explicitly - in my case it lead me to study various merge types in Kubernetes (https://www.disasterproject.com/kubernetes-kubectl-patching/). But it should be documented.

@mauriziovitale
Copy link

mauriziovitale commented Jul 26, 2020

@brendanburns Same here, I am not able to patch a container image.

Screenshot 2020-07-26 at 17 24 09

It works just fine when I run it from postman:
curl -X PATCH \ https://domain/api/v1/namespaces/namespace/pods/process-697548b7b4-d2hgn \ -H 'Content-Type: application/json-patch+json' \ -d '[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]'

It looks like we are suffering the same issue of kubernetes-client/python#866

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants