kubernetes: Kubectl patch does not support patching status of resource

Is this a BUG REPORT or FEATURE REQUEST?:

Uncomment only one, leave it on its own line:

/kind feature

What happened: kubectl patch does not support patching status of resource. For instance:

kubectl -v=9 patch nodes/goodnode.abc --type='json' -p='[{"op": "add", "path": "/status/capacity/example~1foo", "value": "101"}]'

will lead to

I0816 03:03:04.224440   30621 request.go:897] Request Body: [{"op":"add","path":"/status/capacity/example~1foo","value":"101"}]

I0816 03:03:04.224485   30621 round_trippers.go:386] curl -k -v -XPATCH  -H "Content-Type: application/json-patch+json" -H "Accept: application/json" -H "User-Agent: kubectl/v1.13.0 (linux/amd64) kubernetes/1ab4d89" 'https://10.11.12.13:6443/api/v1/nodes/goodnode.abc'

I0816 03:03:04.226477   30621 round_trippers.go:405] PATCH https://10.11.12.13/api/v1/nodes/goodnode.abc 200 OK in 1 milliseconds

node/goodnode.abc patched (no change)

What you expected to happen: node/goodnode.abc patched

How to reproduce it (as minimally and precisely as possible):

kubectl -v=9 patch nodes/goodnode.abc --type='json' -p='[{"op": "add", "path": "/status/capacity/example~1foo", "value": "101"}]'

will get node/goodnode.abc patched (no change)

Anything else we need to know?:

Environment:

  • Kubernetes version (use kubectl version): v1.13.0 (i thought it should be 1.12.0 though)
  • Cloud provider or hardware configuration: local
  • OS (e.g. from /etc/os-release): centos 7.2
  • Kernel (e.g. uname -a):
  • Install tools: build from source
  • Others:

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 22
  • Comments: 29 (9 by maintainers)

Commits related to this issue

Most upvoted comments

This code works well.

patch := fmt.Sprintf(`[{"op": "add", "path": "/status/capacity/localpv.hello.com", "value": "%d"}]`, 102400)
data := []byte(patch)
node, err := kubeCli.CoreV1().Nodes().Patch(context.Background(), nodeName, types.JSONPatchType, data, metav1.PatchOptions{}, "status")

Then kubectl describe node/your-node-name , you will see Capacity resource localpv.hello.com=100k

Removing resource is also simple

data := []byte(`[{"op": "remove", "path": "/status/capacity/localpv.hello.com"}, {"op": "remove", "path": "/status/allocatable/localpv.hello.com"}]`)
\node, err = kubeCli.CoreV1().Nodes().Patch(context.Background(), nodeName, types.JSONPatchType, data, metav1.PatchOptions{}, "status")

Don’t know if this is relevant for the issue, but when I tried to do something similar directly via curl

curl -X PATCH http://localhost:8001/api/v1/nodes/kind-control-plane -H "Content-Type: application/merge-patch+json" -d '{
    "status": {
        "conditions": [
            {
                "type": "MyCondition",
                "status": "True",
                    "reason": "MyReason",
                    "message": "my message"
            }
        ]
    }
}'

I got the same behaviour (patch “applied” but nothing changed).

When I switched to patching against the /status subresource, it suddenly worked

curl -X PATCH http://localhost:8001/api/v1/nodes/kind-control-plane/status -H "Content-Type: application/merge-patch+json" -d '{
    "status": {
        "conditions": [
            {
                "type": "MyCondition",
                "status": "True",
                    "reason": "MyReason",
                    "message": "my message"
            }
        ]
    }
}'

@jaibheem: You can’t reopen an issue/PR unless you authored it or you are a collaborator.

In response to this:

/reopen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

/reopen