digitalocean / doctl

The official command line interface for the DigitalOcean API.
https://docs.digitalocean.com/reference/doctl/
Apache License 2.0
3.26k stars 397 forks source link

Unable to remove the label from the Kubernetes cluster node pool. #1312

Open ChandanSagar opened 1 year ago

ChandanSagar commented 1 year ago

Unable to remove the label for the Kubernetes cluster node pool.

For adding a persistent node label to the Kubernetes worker nodes, we need to label the node pool using doctl. Once the label has been added how to remove it?

The documentation says the omitted labels will be removed. But how to remove the last label?

For example, if we use the below command to add 3 labels to the node pool.

doctl kubernetes cluster node-pool update <cluster name> <pool name/id> --label key1=value1,key2=value2,key3=value3

We can remove the label key2=value2,key3=value3 using the below command doctl kubernetes cluster node-pool update <cluster name> <pool name/id> --label key1=value1

But how to remove key1=value1 label? The below command doesn't work. doctl kubernetes cluster node-pool update <cluster name> <pool name/id> --label

The label can be removed using the API call but using doctl it seems there isn't a way.

curl -X PUT \                                                                
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <token>" \
  -d '{"name": "<node pool name> ","count": 3, "tags":["null"], "labels": {}}' \     
  "https://api.digitalocean.com/v2/kubernetes/clusters/<cluster ID>/node_pools/<node pool id>"
timoreimann commented 1 year ago

There is a related CLI flag --taint where we solved this in one particular way. We could copy the pattern for labels.

timoreimann commented 1 year ago

Some extra context: the issue is that we use a map[string]string with an omitempty JSON tag in godo, meaning that an empty label map is not encoded.

A fix that does not involve a breaking change would require something like an extra field and/or a customer json.Marshaler implementation to handle the clear label case (possibly accompanied by a helper method). Details are to be determined.