Skip to content
Browse files

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 <>
  • Loading branch information...
ahmetb committed Apr 4, 2019
1 parent b3732b3 commit b9614bd2e0b1bb7b11da9627bb146b1b4d1a7524
Showing with 5 additions and 0 deletions.
  1. +5 −0 kubectx
@@ -148,6 +148,11 @@ rename_context() {

if ! context_exists "${old_name}"; then
echo "error: Context \"${old_name}\" not found, can't rename it." >&2
exit 1

if context_exists "${new_name}"; then
echo "Context \"${new_name}\" exists, deleting..." >&2
$KUBECTL config delete-context "${new_name}" 1>/dev/null 2>&1

0 comments on commit b9614bd

Please sign in to comment.
You can’t perform that action at this time.