From b188f4da886ea585f6a555a0d22a025e908142ab Mon Sep 17 00:00:00 2001 From: Jon Mosco Date: Thu, 15 Mar 2018 11:53:31 -0400 Subject: [PATCH] Incorporate utils.bash into each executable to help simplify packaging for Linux and other platforms. This adds to PR #32 remove unused functions --- README.md | 10 +++++----- kubectx | 17 ++++++++--------- kubens | 17 ++++++++--------- utils.bash | 11 ----------- 4 files changed, 21 insertions(+), 34 deletions(-) delete mode 100644 utils.bash diff --git a/README.md b/README.md index 98114d4..55d4e98 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Context "dublin" set. Aliased "gke_ahmetb_europe-west1-b_dublin" as "dublin". ``` -`kubectx` supports Tab completion on bash/zsh/fish shells to help with +`kubectx` supports Tab completion on bash/zsh/fish shells to help with long context names. You don't have to remember full context names anymore. ----- @@ -78,7 +78,7 @@ Active namespace is "default". :confetti_ball: Use the [Homebrew](https://brew.sh/) package manager: brew install kubectx - + This command will set up bash/zsh/fish completion scripts automatically. @@ -93,7 +93,7 @@ This command will set up bash/zsh/fish completion scripts automatically. Since `kubectx`/`kubens` are written in Bash, you should be able to instal them to any POSIX environment that has Bash installed. -- Download the `kubectx`, `kubens` and `utils.bash` scripts. +- Download the `kubectx`, and `kubens` scripts. - Either: - save them all to somewhere in your `PATH`, - or save them to a directory, then create symlinks to `kubectx`/`kubens` from @@ -105,11 +105,11 @@ them to any POSIX environment that has Bash installed. #### Users -| What are others saying about kubectx? | +| What are others saying about kubectx? | | ---- | | _“Thank you for kubectx & kubens - I use them all the time & have them in my k8s toolset to maintain happiness :) ”_ – [@pbouwer](https://twitter.com/pbouwer/status/925896377929949184) | | _“I can't imagine working without kubectx and especially kubens anymore. It's pure gold.”_ – [@timoreimann](https://twitter.com/timoreimann/status/925801946757419008) | -| _“I'm liking kubectx from @ahmetb, makes it super-easy to switch #Kubernetes contexts [...]”_ — [@lizrice](https://twitter.com/lizrice/status/928556415517589505) | +| _“I'm liking kubectx from @ahmetb, makes it super-easy to switch #Kubernetes contexts [...]”_ — [@lizrice](https://twitter.com/lizrice/status/928556415517589505) | | _“Also using it on a daily basis. This and my zsh config that shows me the current k8s context 😉”_ – [@puja108](https://twitter.com/puja108/status/928742521139810305) | | _“Lately I've found myself using the kubens command more than kubectx. Both very useful though :-)”_ – [@stuartleeks](https://twitter.com/stuartleeks/status/928562850464907264) | | _“yeah kubens rocks!”_ – [@embano1](https://twitter.com/embano1/status/928698440732815360) | diff --git a/kubectx b/kubectx index 6acc42d..7113926 100755 --- a/kubectx +++ b/kubectx @@ -21,15 +21,6 @@ set -eou pipefail IFS=$'\n\t' -SCRIPT_DIR="$(dirname "$( readlink -f "${0}" 2>/dev/null || \ - python -c "import os,sys; print(os.path.realpath(sys.argv[1]))" "${0}" )")" - -if [[ -f "${SCRIPT_DIR}/utils.bash" ]]; then - source "${SCRIPT_DIR}/utils.bash" -else - source "${SCRIPT_DIR}/../include/utils.bash" -fi - KUBECTX="${HOME}/.kube/kubectx" usage() { @@ -44,6 +35,14 @@ EOF exit 1 } +current_context() { + kubectl config view -o=jsonpath='{.current-context}' +} + +get_contexts() { + kubectl config get-contexts -o=name | sort -n +} + list_contexts() { set -u pipefail local cur="$(current_context)" diff --git a/kubens b/kubens index 59b074c..7b908b3 100755 --- a/kubens +++ b/kubens @@ -21,15 +21,6 @@ set -eou pipefail IFS=$'\n\t' -SCRIPT_DIR="$(dirname "$( readlink -f "${0}" 2>/dev/null || \ - python -c "import os,sys; print(os.path.realpath(sys.argv[1]))" "${0}" )")" - -if [[ -f "${SCRIPT_DIR}/utils.bash" ]]; then - source "${SCRIPT_DIR}/utils.bash" -else - source "${SCRIPT_DIR}/../include/utils.bash" -fi - KUBENS_DIR="${HOME}/.kube/kubens" usage() { @@ -53,6 +44,14 @@ current_namespace() { fi } +current_context() { + kubectl config view -o=jsonpath='{.current-context}' +} + +get_namespaces() { + kubectl get namespaces -o=jsonpath='{range .items[*].metadata.name}{@}{"\n"}{end}' +} + namespace_file() { local ctx="${1}" echo "${KUBENS_DIR}/${ctx}" diff --git a/utils.bash b/utils.bash deleted file mode 100644 index 8cfc50c..0000000 --- a/utils.bash +++ /dev/null @@ -1,11 +0,0 @@ -current_context() { - kubectl config view -o=jsonpath='{.current-context}' -} - -get_contexts() { - kubectl config get-contexts -o=name | sort -n -} - -get_namespaces() { - kubectl get namespaces -o=jsonpath='{range .items[*].metadata.name}{@}{"\n"}{end}' -}