mirror of
https://github.com/ahmetb/kubectx.git
synced 2025-07-31 14:54:36 +00:00
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>
This commit is contained in:
parent
b3732b309e
commit
b9614bd2e0
5
kubectx
5
kubectx
@ -148,6 +148,11 @@ rename_context() {
|
||||
old_name="$(current_context)"
|
||||
fi
|
||||
|
||||
if ! context_exists "${old_name}"; then
|
||||
echo "error: Context \"${old_name}\" not found, can't rename it." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if context_exists "${new_name}"; then
|
||||
echo "Context \"${new_name}\" exists, deleting..." >&2
|
||||
$KUBECTL config delete-context "${new_name}" 1>/dev/null 2>&1
|
||||
|
Loading…
Reference in New Issue
Block a user