godaddy / godaddy/kubernetes-client

JSON Patch not working with PATCH method

Open
#694 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
963
Forks
189
PR merge metrics
No merged PRs in 30d

Description

Suppose I have a custom resource like this:

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

When calling the following method:

```javascript
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\"" }
```

Contributor guide

Open the contributing guide

Research direction

Start from the client.apis...patch entry point shown in the report and reproduce the request against the Example custom resource with the supplied JSON Patch body and content type. Trace how the patch body is serialized and sent; done means the API accepts the request and updates spec.foo from "bar" to "baz".

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, kubernetes, nodejs
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.