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

FeatureRequest: Prevent accidental deletion of context when swapping the new and old context in kubectx #136

Closed
RonaldFindling opened this issue Mar 19, 2019 · 4 comments

Comments

@RonaldFindling
Copy link

commented Mar 19, 2019

To prevent accidental deletion of a context when swapping the old and new context parameters on a rename operation check at first if the oldContext exists.

Use Case:

# correct usage
kubectx newContext=oldContext
# wrong usage which deletes oldContext
kubectx oldContext=newContext

Currently in case of wrong usage:

user:~$ kubectx oldContext=newContext
Context "oldContext" exists, deleting...
error: cannot rename the context "nexContext", it's not in /Users/user/.kube/config

Preferred in case of wrong usage: (no context gets deleted)

user:~$ kubectx oldContext=newContext
error: The context "nexContext", is not in /Users/user/.kube/config
@ahmetb

This comment has been minimized.

Copy link
Owner

commented Mar 19, 2019

Currently we do:

  1. does the $newContext exist? if so, "delete" it first (so that rename doesn't fail)
  2. kubectl config rename-context [...]

Sounds like we should instead do:

  1. does the $oldContext exist, if not, QUIT with error.
  2. does the $newContext exist? if so "delete" it first (so that rename doesn't fail)
  3. kubectl config rename-context [...]

Correct?

@RonaldFindling

This comment has been minimized.

Copy link
Author

commented Mar 20, 2019

Exactly.

@jacobtomlinson

This comment has been minimized.

Copy link

commented Apr 3, 2019

Just fell into this trap 🙃

ahmetb added a commit that referenced this issue Apr 3, 2019
kubectx rename check if old_name is a valid ctx
Without this safeguard, when user runs `kubectx NEW_NAME=OLD_NAME` where
NEW_NAME is an existing context but OLD_NAME isn't, we end up deleting NEW_NAME
and not doing any renames (because OLD_NAME is not found).

Fixes #136.

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
@ahmetb

This comment has been minimized.

Copy link
Owner

commented Apr 3, 2019

I prepared a fix in #139. Feel free to test it, but seems trivial.

@ahmetb ahmetb closed this in #139 Apr 4, 2019

ahmetb added a commit that referenced this issue Apr 4, 2019
kubectx rename check if old_name is a valid ctx (#139)
Without this safeguard, when user runs `kubectx NEW_NAME=OLD_NAME` where
NEW_NAME is an existing context but OLD_NAME isn't, we end up deleting NEW_NAME
and not doing any renames (because OLD_NAME is not found).

Fixes #136.

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.