Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete context with cluster and user #409

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

zcahana
Copy link

@zcahana zcahana commented Nov 24, 2023

Adds an option to delete contexts including their referenced cluster and user entries from the clusters/users lists.

The cluster and user entries are only deleted if they are no longer referenced in any other context (i.e., "orphaned").

The new option is exposed via a new CLI flag, -D, alongside the original flag (-d) which retains its existing functionality of deleting the context only.


Closes #202.

Implementation notes

  • The toggle for the new behavior is captured by a boolean, termed "Cascade", which is propagated down from the CLI parsing logic, through the DeleteOp commands, and down to the deleteContext function.
  • The bulk of the new logic is within the the internal/kubeconfig package, with new function for inspecting/manipulating users, clusters and their corresponding references within a context.
  • The implementation for clusters and users is virtually similar except for the field names. In principal there's room for code sharing between these two, but given the scope of the project I figured we're better off with simple and straight-forward coding despite some code duplications.
  • The new command is only available in the Go-based tool.

Testing notes

  • Added unit tests for all new functions in the internal/kubeconfig package.
  • Added E2E tests via bats. Note that these should pass with the Go-based tool, but fail with the Bash tool. I'm not sure whether there's existing automation that runs these tests and with which of the kubectx implementations. If this is a problem, I'll come back to this to see what can be done.

@zcahana
Copy link
Author

zcahana commented Jan 4, 2024

@ahmetb hi, did you happen to have a chance to look at this? I'm wondering if this is something that may be of interest for this project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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