API server always complain "Invalid JSON document" when I try to patch update deployment

1,538 views
Skip to first unread message

lin.for...@gmail.com

unread,
Aug 2, 2016, 9:57:22 PM8/2/16
to kubernetes-dev
Hi,

Can someone help on this problem?

I was trying to patch update deployment from my ReactJS UI using Restful API, and blocked by this issue:
E0803 01:43:35.580224       1 errors.go:63] apiserver received an error that is not an unversioned.Status: Invalid JSON document

The Json request is < {"spec":{"template":{"spec":{"containers":[{"name":"testxxx","image":"apache2"}]}}}} >, the API I was calling is < http://<kubernetesAPIServer>/apis/extensions/v1beta1/namespaces/default/deployments/testxxxx >.

However I can successfully update the deployment with curl
# curl -XPATCH -H'Content-Type: application/strategic-merge-patch+json' http://<kubernetesAPIServer>/apis/extensions/v1beta1/namespaces/default/deployments/testxxxx -d @patch.json
{
  "kind": "Deployment",
  "apiVersion": "extensions/v1beta1",
  "metadata": {
    "name": "testxxxx",
    "namespace": "default",
...
}

Brendan Burns

unread,
Aug 3, 2016, 1:10:58 AM8/3/16
to kubernetes-dev
If it works from curl it seems like this is an issue with the React/Javascript API, rather than the API server.  Can you introspect the request in the chrome debugger and look for differences between the curl request and what the browser is sending?

--brendan

lin.for...@gmail.com

unread,
Aug 3, 2016, 2:06:11 AM8/3/16
to kubernetes-dev
Thanks.

Is there any way to print the API request in kube-api log? Just like what "kubectl ... --v=8" is showing. I try to specify "--v=4" options for kube-apiserver, but the debug info is not clear enough to show me what is wrong about the Json request body.

Daniel Smith

unread,
Aug 3, 2016, 2:16:09 AM8/3/16
to lin.for...@gmail.com, kubernetes-dev
Like Brendan says, I suggest looking at the network tab in the chrome debugger, it will show you exactly what was sent/received.

Personally, I'd bet that the verb is not being set to PATCH. I don't know if it is even possible to do that from JS.

Please note that the Kubernetes API is not XSS hardened and using it directly from a web app is a security risk.

--
You received this message because you are subscribed to the Google Groups "kubernetes-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-de...@googlegroups.com.
To post to this group, send email to kuberne...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kubernetes-dev/c2858d88-4e9a-4c52-8b00-9e3b97065763%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

lin.for...@gmail.com

unread,
Aug 3, 2016, 4:06:52 AM8/3/16
to kubernetes-dev, lin.for...@gmail.com
Finally I got tcpflow to print request body, and it's indeed the JS issue.

Thanks.
Reply all
Reply to author
Forward
0 new messages