godaddy / kubernetes-client

Simplified Kubernetes API client for Node.js.
MIT License
961 stars 192 forks source link

JSON Patch not working with PATCH method #694

Open linkdd opened 3 years ago

linkdd commented 3 years ago

Suppose I have a custom resource like this:

---
apiVersion: example.com/v1
kind: Example
metadata:
  # ...
spec:
  foo: "bar"

When calling the following method:

client.apis['example.com'].v1.namespace('default').examples('name').patch({
  body: [ { op: "add", path: "/spec/foo", value: "baz" } ],
  headers: {
    'content-type': 'application/json-patch+json'
  }
})

A 422 error is received with the following error message:

"" is invalid: patch: Invalid value: "[{\"op\":\"add\",\"path\":\"/spec/foo\",\"value\": \"baz\"}]": couldn't get version/kind; json parse error: json: cannot unmarshal array into Go value of type struct { APIVersion string "json:\"apiVersion,omitempty\""; Kind string "json:\"kind,omitempty\"" }