vardius / go-api-boilerplate

Go Server/API boilerplate using best practices DDD CQRS ES gRPC
https://go-api-boilerplate.local
MIT License
917 stars 135 forks source link

Deleting namespaces #66

Closed vardius closed 3 years ago

vardius commented 4 years ago

Deleting namespace will stuck at Terminating state. More info here: https://github.com/kubernetes/kubernetes/issues/60807

This happens only with CRDs. By deleting the CRD object, it gets in state were the objects owned by it were not deleted. Temporary solution is to edit namespaces and empty finalisers.

Perform following:

  1. Delete namespace
    ✗ make helm-delet
  2. Dump namespace to json
    kubectl get namespace go-api-boilerplate -o json > tmp.json
  3. Edit tmp.json and remove"kubernetes" from finalisers
  4. Run proxy
    kubectl proxy
  5. Upload edited json
    curl -k -H "Content-Type: application/json" -X PUT --data-binary @tmp.json http://127.0.0.1:8001/api/v1/namespaces/\go-api-boilerplate/finalize

If you are running newest version of k8s instead of doing all steps you can just run one command as follow:

kubectl get namespace go-api-boilerplate -o json \
            | tr -d "\n" | sed "s/\"finalizers\": \[[^]]\+\]/\"finalizers\": []/" \
            | kubectl replace --raw /api/v1/namespaces/go-api-boilerplate/finalize -f -

This way you will not have to spawn a kubectl proxy process and avoid dependency with curl. https://github.com/kubernetes/kubernetes/issues/60807#issuecomment-635399941

vardius commented 3 years ago

Works with terraform.