kubectx
kubectx copied to clipboard
Option to delete user and cluster used by context when deleteing it
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.
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.
This seems to be possible now:
https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/
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?
- A separate flag (e.g.,
-D
or-dd
)? - A companion flag to
-d
(e.g.,-d -p
, "p" is for purge)? - 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
.
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 please see #409 which adds this as a new -D
flag (indeed, only for the Go implementation 😉).