From 9ed6690978df71de8961f2b35bd86a6c01db14ec Mon Sep 17 00:00:00 2001 From: Bhargav Nookala Date: Thu, 2 Nov 2017 16:48:58 -0700 Subject: [PATCH] :wrench: use rename-context in place of set-context --- kubectx | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/kubectx b/kubectx index f6d7574a..6acc42d4 100755 --- a/kubectx +++ b/kubectx @@ -36,9 +36,9 @@ usage() { cat <<"EOF" USAGE: kubectx : list the contexts - kubectx : switch to context + kubectx : switch to context kubectx - : switch to the previous context - kubectx = : create alias for context + kubectx = : rename context to kubectx -h,--help : show this message EOF exit 1 @@ -107,7 +107,7 @@ cluster_of_context() { -o=jsonpath="{.contexts[?(@.name==\"${1}\")].context.cluster}" } -alias_context() { +rename_context() { local old_name="${1}" local new_name="${2}" @@ -119,11 +119,7 @@ alias_context() { exit 1 fi - kubectl config set-context "${new_name}" \ - --cluster="${old_cluster}" \ - --user="${old_user}" \ - - echo "Aliased \"${old_name}\" as \"${new_name}\"." >&2 + kubectl config rename-context "${old_name}" "${new_name}" } main() { @@ -141,7 +137,7 @@ main() { echo "error: unrecognized flag \"${1}\"" >&2 usage elif [[ "${1}" =~ (.+)=(.+) ]]; then - alias_context "${BASH_REMATCH[2]}" "${BASH_REMATCH[1]}" + rename_context "${BASH_REMATCH[2]}" "${BASH_REMATCH[1]}" else set_context "${1}" fi