Skip to content

dev: How to modify the status subresource with `kubectl edit` (CRD)

Sheng Yang edited this page Aug 11, 2020 · 1 revision

The following content is for the debugging purpose only.

Longhorn uses status subresource in the various CRs to separate the responsibility of spec and status. But an unintended result is, it's not possible to modify the status subresource directly using kubectl edit, which results in difficulty when debugging.

To modify the status subresource manually, here we use a Longhorn volume as an example. The same applies to all status subresources:

  1. Run kubectl -n longhorn-system -v=7 edit volumes.longhorn.io pvc-1fa0fff5-5b05-4ac5-9c8c-76ce481fb8ca

  2. Perform the edit.

  3. At the end of the output, you will see something like this:

    I0811 11:01:48.825636   43355 request.go:942] Request Body: {"status":{"state":"attaching"}}
    I0811 11:01:48.825708   43355 round_trippers.go:416] PATCH https://rancher-master/k8s/clusters/c-sff4g/apis/longhorn.io/v1beta1/namespaces/longhorn-system/volumes/pvc-1fa0fff5-5b05-4ac5-9c8c-76ce481fb8ca
    I0811 11:01:48.825716   43355 round_trippers.go:423] Request Headers:
    I0811 11:01:48.825721   43355 round_trippers.go:426]     Accept: application/json
    I0811 11:01:48.825724   43355 round_trippers.go:426]     Content-Type: application/merge-patch+json
    I0811 11:01:48.825729   43355 round_trippers.go:426]     User-Agent: kubectl/v1.14.1 (linux/amd64) kubernetes/b739410
    I0811 11:01:48.825732   43355 round_trippers.go:426]     Authorization: Bearer kubeconfig-xxxx
    
  4. Use the following curl command to update the status:

    curl -XPATCH -H "[Accept]" -H "[Content-Type]" -H "[Authorization]" --data '[Request Body]' [URL]/status

    For example, the command of above example is:

    curl -XPATCH -H "Accept: application/json" -H "Content-Type: application/merge-patch+json" -H "Authorization: Bearer kubeconfig-xxxx" --data '{"status":{"state":"attaching"}}' https://rancher-master/k8s/clusters/c-sff4g/apis/longhorn.io/v1beta1/namespaces/longhorn-system/volumes/pvc-1fa0fff5-5b05-4ac5-9c8c-76ce481fb8ca/status You might also need -k to skip the SSL validation.

Kubernetes issue: https://github.com/kubernetes/kubectl/issues/564

Clone this wiki locally