diff --git a/README.md b/README.md index 3fc88c21..c65e0b3d 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ $ tree .kube/switch ``` Using the `switch` utility allows me to easily find the `kubeconfig` I am looking for. -Because the directory names are part of the search result it can be easily identified - without having to remember context names in the `kubeconfig` file. +Because the directory name are part of the search result, the target `kubeconfig` can be identified without having to remember context names. In addition, the selection can be verified by looking at the live preview. Please take a look at the gif above how that looks like. @@ -107,19 +107,19 @@ Please take a look at the gif above how that looks like. # switch ``` -If you think that could be helpful in managing you `kubeconfig` files, try it out and let me know what you think of it. +If you think that could be helpful in managing you `kubeconfig` files, try it out and let me know what you think. ### How it works -The tool sets the `KUBECONFIG` environment variable in your current shell session to the selected `kubeconfig`. -This way you can target different Kubernetes clusters in each terminal window. - -First, the `switch` script calls the `switcher` binary with the user provided flags. -The `switcher` then recursively searches for `kubeconfig` files in the configured directory and displays a fuzzy search. -The selected `kubeconfig` filepath is captured ny the `switch` script as the output of the `switcher` binary. +The tool sets the `KUBECONFIG` environment variable in the current shell session to the selected `kubeconfig`. +This way different Kubernetes clusters can be targeted in each terminal window. -In turn the `switch` script finally sets the KUBECONFIG` environment variable`in the current shell session. -To be able to do that, the `switch` script has to be sourced. +There are two separate tools involved. THe first one is `switch.sh`, a tiny bash script, and then there is the `switcher` binary. +The only thing the `switch` script does, is calling the `switcher` binary, capturing the path to the user selected `kubeconfig` and then setting +the `KUBECONFIG` environment variable. +In order for the script to set the environment variable in the current shell session, it has to be sourced. + +The `switcher`'s job is to displays a fuzzy search based on a recursive directory search for `kubeconfig` files in the configured directory. ### Difference to [kubectx.](https://github.com/ahmetb/kubectx) diff --git a/cmd/switcher/switch.go b/cmd/switcher/switch.go index 8049ed22..6dd2bf13 100644 --- a/cmd/switcher/switch.go +++ b/cmd/switcher/switch.go @@ -3,9 +3,9 @@ package switcher import ( "os" - "github.com/spf13/cobra" - "github.com/danielfoehrkn/kubectlSwitch/pkg" + + "github.com/spf13/cobra" ) var ( diff --git a/hack/switch/switch.sh b/hack/switch/switch.sh index 6df878b8..9c0580b3 100755 --- a/hack/switch/switch.sh +++ b/hack/switch/switch.sh @@ -83,9 +83,6 @@ switch(){ EXECUTABLE_PATH=$DEFAULT_EXECUTABLE_PATH fi -# FLAGS="${KUBECONFIG_NAME} ${SHOW_PREVIEW} $KUBECONFIG_DIRECTORY_FLAG ${KUBECONFIG_DIRECTORY}" -# echo "FLAGS: $FLAGS" - # execute golang binary handing over all the flags NEW_KUBECONFIG=$($EXECUTABLE_PATH $KUBECONFIG_DIRECTORY_FLAG ${KUBECONFIG_DIRECTORY} $KUBECONFIG_NAME_FLAG ${KUBECONFIG_NAME} $SHOW_PREVIEW_FLAG ${SHOW_PREVIEW}) if [[ "$?" = "0" ]]; then diff --git a/hack/switch/switcher b/hack/switch/switcher new file mode 100755 index 00000000..9ee9ab5b Binary files /dev/null and b/hack/switch/switcher differ