1

I am trying to update status subresource for a Custom Resource and I see a discrepency with curl and kubectl patch commands. when I use curl call it works perfectly fine but when I use kubectl patch command it says patched but with no change. Here are the command that I used

Using Curl:

When I connect to kubectl proxy and run the below curl call, it's successful and updates status subresource on my CR.

curl -XPATCH  -H "Accept: application/json" -H "Content-Type: application/json-patch+json"  --data '[{"op": "replace", "path": "/status/state", "value": "newState"}]' 'http://127.0.0.1:8001/apis/acme.com/v1alpha1/namespaces/acme/myresource/default/status'

Kubectl patch command:

Using kubectl patch says the CR is patch but with no change and the status sub-resource is updated.

$ kubectl -n acme patch myresource default --type='json' -p='[{"op": "replace", "path": "/status/state", "value":"newState"}]'
myresource.acme.com/default patched (no change)

However when I do the kubectl patch on the other sub-resources like spec it works fine. Am i missing something here?

user3435964
  • 663
  • 1
  • 11
  • 23
  • The status subresource is often maintained by the controller and may not be directly modifiable via the API. – larsks Aug 15 '22 at 17:27
  • 1
    thanks for the response, but I can modify using the curl call and not by the kubectl patch. IIUC, they both are same while one works but the other one doesn't – user3435964 Aug 15 '22 at 19:00
  • It looks as if [kubectl is not able to patch the status subresource](https://github.com/kubernetes/kubectl/issues/564). – larsks Aug 15 '22 at 21:33
  • try this https://github.com/ulucinar/kubectl-edit-status – kelviN Dec 09 '22 at 07:31

1 Answers1

1

As of kubectl v1.24, it is possible to patch subresources with an additional flag e.g. --subresource=status. This flag is considered "Alpha" but does not require enabling the feature.

As an example, with a yaml merge:

kubectl patch MyCrd myresource --type=merge --subresource status --patch 'status: {healthState: InSync}'

The Sysdig "What's New?" for v1.24 includes some more words about this flag:

Some kubectl commands like get, patch, edit, and replace will now contain a new flag --subresource=[subresource-name], which will allow fetching and updating status and scale subresources for all API resources.

You now can stop using complex curl commands to directly update subresources.

The --subresource flag is scheduled for promotion to "Beta" in Kubernetes v1.27 through KEP-2590: graduate kubectl subresource support to beta. The lifecycle of this feature can be tracked in #2590 Add subresource support to kubectl.

danopia
  • 111
  • 3