loft-sh / vcluster

vCluster - Create fully functional virtual Kubernetes clusters - Each vcluster runs inside a namespace of the underlying k8s cluster. It's cheaper than creating separate full-blown clusters and it offers better multi-tenancy and isolation than regular namespaces.
https://www.vcluster.com
Apache License 2.0
6.32k stars 403 forks source link

vcluster delete --all Command #363

Open danielhelfand opened 2 years ago

danielhelfand commented 2 years ago

When using the vcluster CLI, it would be nice to support an option to delete all virtual clusters on the host cluster. Something like vcluster delete --all would be helpful in really quickly cleaning up clusters without having to remember specific cluster names/specify all clusters.

Something to consider would be the best way to fetch all the namespaces where virtual clusters are deployed to in order to pass on to helm. Also, the --delete-namespace option would need a way to have all the relevant namespaces passed to it.

The other things to consider would be failure scenarios. Should the command continue if an error is encountered deleting a particular virtual cluster?

Not sure if there would be additional considerations for nested virtual clusters.

Looking forward to thoughts on this!

FabianKramm commented 2 years ago

@danielhelfand thanks for creating this issue! Not sure if we should implement this command as it might have devastating consequences if ran on accident. Besides that as you already mentioned there are a couple of pitfalls like namespace deletion, which can be even more devastating if a vcluster was installed into kube-system for example and vcluster is trying to delete the complete namespace.

I think it might be better to have vcluster list printing the vclusters in a way you could easily pass those to helm delete or kubectl delete namespace, which makes it still easy to use but circumvents the potential pitfalls for now.

danielhelfand commented 2 years ago

Not sure if we should implement this command as it might have devastating consequences if ran on accident.

Sure, I think being more cautious makes sense. There could be a prompt message like Are you sure you want to proceed as something to make users think but understandable if that's uncomfortable.

Maybe a more interesting way to go would be some kind of interactive deletion experience such as below:

vcluster delete -n host-namespace-1

> vcluster
  vcluster2
  vcluster3

vcluster delete -A

  NAME        NAMESPACE
> vcluster    host-namespace-1
  vcluster2   host-namespace-1 
  vcluster3   host-namespace-2

Users could delete vclusters based on a drop down menu experience through the CLI.

FabianKramm commented 2 years ago

@danielhelfand yes having a confirm might make sense, another thought would be to label namespaces with a vcluster label during creation to later identify them that they are safe to delete, which would prevent accidental deletion of important namespaces like kube-system.

sarojregmi200 commented 11 months ago

@FabianKramm since no one is assigned to this Issue, can I work on this issue? I want to give it a try.

It seems to be a old issue but the labels indicate that it is something that we can work on now. I would love to see and know if it is something that the community can work upon. Thanks.