kubectx icon indicating copy to clipboard operation
kubectx copied to clipboard

Option to delete user and cluster used by context when deleteing it

Open cardil opened this issue 4 years ago • 5 comments

For my use case, using -d is super annoying, as ~/.kube/config file are left with defunkt entries from previously created clusters.

I'd like to request an option to delete user and cluster used by context when deleting it.

cardil avatar Apr 09 '20 12:04 cardil

Sadly kubectl doesn’t provide clean cmds to delete user and cluster entries. I have an issue open about this for a long while.

Since we don’t directly manipulate the kubeconfig file, it doesn’t seem currently doable. But we can get to it.

ahmetb avatar Apr 09 '20 15:04 ahmetb

This seems to be possible now:

https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/

acim avatar Sep 16 '20 13:09 acim

Is there still interest in this from the project authors? (@ahmetb) If so, I'm happy to work on adding it.

Also: how would you like to see this being supported?

  1. A separate flag (e.g., -D or -dd)?
  2. A companion flag to -d (e.g., -d -p, "p" is for purge)?
  3. Change behavior of -d

And also: need to consider that the deleted context's cluster/user might still be referenced in other contexts that are still there. In such case, it would be safer to avoid deleting the cluster/user, but possibly provide a way to force the deletion (e.g., -ddd in line with option (1) above, or -d -p -f in line with option (2)).

I personally am more fond of -D and no force deletion of non-orphaned clusters/users, but I'm also good with -dd and -ddd.

zcahana avatar Nov 23 '23 16:11 zcahana

Yeah, I think we can add -D which actually deletes associated orphaned entries. Changing the default behavior of -d is gonna make some folks upset for sure (given there are a lot of course material and content out there explaining people to set up clusters manually, and manually editing the kubeconfig file to make it work).

I recommend adding this feature only to the Go implementation for the sake of simplicity.

ahmetb avatar Jan 06 '24 00:01 ahmetb

@ahmetb please see #409 which adds this as a new -D flag (indeed, only for the Go implementation 😉).

zcahana avatar Jan 07 '24 09:01 zcahana