Why do namespaces get recreated after being deleted?

Hi!

I have a lot of stale garden namespaces in my cluster (I create one namespace per build so it’s easy to clean up all the dependencies left behind after a build). I wrote a script to find the old namespaces that are not used by any builds anymore and run garden delete env --env=<namespace>.<my-env-name> on them. I noticed that the the k8s namespaces created by garden would immediately get recreated after the command succeeds. Is there a way to get rid of them permanently?

Thanks!
Anna

Hey Anna! Hmh, I had not come across this. I’m gonna see if I can reproduce, I suppose it’s possible there’s a bug in there somewhere. To be sure I understand, you’re finding that the garden delete env command is actually re-creating the namespace after first deleting it?

yea, I tried with kubectl delete namespace too and I don’t see the same behavior there. FWIW I’m using EKS, the k8s server version is 1.20.7, my garden version is 0.12.28-edge-58cb5715

Dang, you’ve indeed found a bug. The namespace gets deleted and then re-created right at the tail end of the process. I suspect some status call is implicitly creating the namespace, I’ll try and track that down, thanks for the report!

The workaround would be to simply follow the garden delete env command with a corresponding kubectl delete ns command, but I’ll make sure this is fixed ahead of next release, it’ll be straightforward no doubt.

1 Like