8 Commits

Author SHA1 Message Date
Ahmet Alp Balkan
e82879a185 Update README.md 2017-11-09 14:15:52 -08:00
Ahmet Alp Balkan
8c17834c36 Merge pull request #15 from bnookala/use-rename-context
Use rename-context in place of set-context
2017-11-09 14:15:23 -08:00
Bhargav Nookala
9ed6690978 🔧 use rename-context in place of set-context 2017-11-03 12:49:03 -07:00
Ahmet Alp Balkan
ed2afa7572 Add GIFs to README.md
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
2017-10-24 12:32:22 -07:00
Ahmet Alp Balkan
5d79a0663d Remove message for '-' in kubectx.zsh
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
2017-10-23 23:56:21 -07:00
Ahmet Alp Balkan
e7131add7a Add Stargazers chart
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
2017-10-22 19:22:23 -07:00
Ahmet Alp Balkan
fd91e53d1f 🎉 kubectx is now in homebrew-core 🎊
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
2017-06-29 14:12:46 -07:00
Ahmet Alp Balkan
b06fcaf054 Update Homebrew Formula with v0.3.1
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
2017-05-17 10:09:10 -07:00
6 changed files with 37 additions and 25 deletions

View File

@@ -1,8 +1,8 @@
class Kubectx < Formula
desc "Tool that can switch between kubectl contexts easily and create aliases"
homepage "https://github.com/ahmetb/kubectx"
url "https://github.com/ahmetb/kubectx/archive/v0.3.0.tar.gz"
sha256 "720b6d9a960a7583983ac84c90d2ff89f4494584cf82a3abb5d4e66e72444621"
url "https://github.com/ahmetb/kubectx/archive/v0.3.1.tar.gz"
sha256 "4e995f5bec6f41c8d5b6e77f413a58ead077816348e72de26dde3655ec2b7d0b"
head "https://github.com/ahmetb/kubectx.git", :branch => "short-names"
bottle :unneeded

View File

@@ -1,6 +1,11 @@
This repository provides both `kubectx` and `kubens` tools. Purpose of this
project is to provide an utility and facilitate discussion about how `kubectl`
can manage contexts better.
This repository provides both `kubectx` and `kubens` tools.
**`kubectx`** help you switch between clusters back and forth:
![kubectx demo GIF](img/kubectx-demo.gif)
**`kubens`** help you switch between Kubernetes namespaces smoothly:
![kubens demo GIF](img/kubens-demo.gif)
# kubectx(1)
@@ -9,15 +14,12 @@ kubectx is an utility to manage and switch between kubectl(1) contexts.
```
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
```
Purpose of this project is to provide an utility and facilitate discussion
about how `kubectl` can manage contexts better.
### Usage
```sh
@@ -73,20 +75,34 @@ Active namespace is "default".
**For macOS:**
> Use [Homebrew](https://brew.sh/) package manager:
:tada: kubectx is now in Homebrew! :confetti_ball:
> Use the [Homebrew](https://brew.sh/) package manager:
>
> brew install kubectx
>
> brew tap ahmetb/kubectx https://github.com/ahmetb/kubectx.git
> brew install kubectx
> this will also set up bash/zsh completion scripts automatically.
Running `brew install` with `--with-short-names` will install tools with names
`kctx` and `kns` to prevent prefix collision with `kubectl` name.
> Note: If you installed kubectx before it was accepted to Homebrew core
> repository, reinstall with:
> `brew untap ahmetb/kubectx && brew uninstall --force kubectx && brew update && brew install kubectx`
**Other platforms:**
> Download the `kubectx` script, make it executable and add it to your PATH. You
> can also install bash/zsh [completion scripts](completion/) manually.
- Download the `kubectx` script
- Add it somewhere in your PATH
- Make it executable (`chmod +x`)
- You can also install bash/zsh [completion scripts](completion/) manually.
-----
Disclaimer: This is not an official Google product.
#### Stargazers over time
[![Stargazers over time](https://starcharts.herokuapp.com/ahmetb/kubectx.svg)](https://starcharts.herokuapp.com/ahmetb/kubectx)

View File

@@ -5,7 +5,7 @@ PREV=""
if [ -f "$KUBECTX" ]; then
# show '-' only if there's a saved previous context
local PREV=$(cat "${KUBECTX}")
_arguments "1: :((-\:Back\ to\ ${PREV} \
_arguments "1: :((- \
$(kubectl config get-contexts --output='name')))"
else
_arguments "1: :($(kubectl config get-contexts --output='name'))"

BIN
img/kubectx-demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 KiB

BIN
img/kubens-demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 KiB

14
kubectx
View File

@@ -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
@@ -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