Skip to content

Commit

Permalink
Merge pull request #15 from bnookala/use-rename-context
Browse files Browse the repository at this point in the history
Use rename-context in place of set-context
  • Loading branch information
ahmetb authored Nov 9, 2017
2 parents ed2afa7 + 9ed6690 commit 8c17834
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions kubectx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ usage() {
cat <<"EOF"
USAGE:
kubectx : list the contexts
kubectx <NAME> : switch to context
kubectx <NAME> : switch to context <NAME>
kubectx - : switch to the previous context
kubectx <NEW_NAME>=<NAME> : create alias for context
kubectx <NEW_NAME>=<NAME> : rename context <NAME> to <NEW_NAME>
kubectx -h,--help : show this message
EOF
exit 1
Expand Down Expand Up @@ -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}"

Expand All @@ -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() {
Expand All @@ -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
Expand Down

0 comments on commit 8c17834

Please sign in to comment.