Kubectl patch and curl patch unable to patch a resource

8/2/2018

I tried to add an extended resource to one node in my cluster. I followed this task, from official documentation

I've followed the instructions step by step, but the PATCH doesn't seem to have an effect.

After running:

curl --header "Content-Type: application/json-patch+json" --request PATCH --data '[{"op": "add", "path": "/status/capacity/example.com~1dongle", "value": "4"}]' http://localhost:8001/api/v1/nodes/kubernetes-3/status

I get a response, with added extended resource

"capacity": {
  "cpu": "8",
  "example.com/dongle": "4",
  "memory": "8218052Ki",
  "pods": "110"
},

But if I run kubectl describe node kubernetes-3 the capacity has old values:

Capacity: cpu: 8 memory: 8218052Ki pods: 110

I've checked the apiserver logs and everything looks good:

PATCH /api/v1/nodes/kubernetes-3/status: (39.112896ms) 200 [[curl/7.59.0] 127.0.0.1:49234]

However, if I use the kubectl patch command, the command returns node "kubernetes-3" not patched

The command I ran: kubectl patch node kubernetes-3 --type='json' -p '[{"op": "add", "path": "/status/capacity/example.com~1dongle", "value": "4"}]'

And again, the apiserver logs, which show, that the response was successful (status 200):

PATCH /api/v1/nodes/kubernetes-3: (4.831866ms) 200 [[kubectl/v1.8.0+coreos.0 (linux/amd64) kubernetes/a65654e] 127.0.0.1:50004]

kubectl version output:

Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.0+coreos.0", GitCommit:"a65654ef5b593ac19fbfaf33b1a1873c0320353b", GitTreeState:"clean", BuildDate:"2017-09-29T21:51:03Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.0+coreos.0", GitCommit:"a65654ef5b593ac19fbfaf33b1a1873c0320353b", GitTreeState:"clean", BuildDate:"2017-09-29T21:51:03Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
-- mythic
kubernetes

1 Answer

8/3/2018

I've tried it on the Kubernetes cluster v1.11.1

Curl version is working fine, but it takes some time (5-10 seconds) to show it on the "get" output:

curl --header "Content-Type: application/json-patch+json" \
--request PATCH \
--data '[{"op": "add", "path": "/status/capacity/example.com~1dongle", "value": "2"}]' \
http://localhost:8001/api/v1/nodes/node-name/status

kubectl get node node-name -o yaml
...
 capacity:
    cpu: "2"
    ephemeral-storage: 20263528Ki
    example.com/dongle: "2"
    example2.com/dongle: "4"
    example3.com/dongle: "4"
    example4.com/dongle: "4"
    hugepages-1Gi: "0"
    hugepages-2Mi: "0"
    memory: 7652316Ki
    pods: "110"
...

kubectl version still doesn't work, but I guess it's because it requests the wrong address /api/v1/nodes/node-name, instead of /api/v1/nodes/node-name/status

The command

kubectl -v=9 patch node/node-name --type='json' -p='[{"op": "add", "path": "/status/capacity/example.com-dongle", "value": "6"}]'

gave me the log:

I0803 13:08:38.552155 694 round_trippers.go:386] curl -k -v -XPATCH -H "Accept: application/json" -H "Content-Type: application/json-patch+json" -H "User-Agent: kubectl/v1.11.1 (linux/amd64) kubernetes/b1b2997" 'https://10.156.0.8:6443/api/v1/nodes/node-name'

If we check the similar request on kubeclt proxy connection:

It doesn’t work:

curl -XPATCH  -H "Accept: application/json" -H "Content-Type: application/json-patch+json" -H "User-Agent: kubectl/v1.11.1 (linux/amd64) kubernetes/b1b2997" --data '[{"op": "add", "path": "/status/capacity/example4.com~1dongle", "value": "4"}]' \
'http://127.0.0.1:8001/api/v1/nodes/node-name' 

But with “/status” in the end it works well:

curl -XPATCH  -H "Accept: application/json" -H "Content-Type: application/json-patch+json" -H "User-Agent: kubectl/v1.11.1 (linux/amd64) kubernetes/b1b2997" --data '[{"op": "add", "path": "/status/capacity/example4.com~1dongle", "value": "4"}]' \
'http://127.0.0.1:8001/api/v1/nodes/node-name/status'
-- VAS
Source: StackOverflow