Skip to content

Commit

Permalink
Updating the READ.ME
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfoehrKn committed May 30, 2020
1 parent c341984 commit 64148e4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,27 @@ $ 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.

```
# 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)

Expand Down
4 changes: 2 additions & 2 deletions cmd/switcher/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package switcher
import (
"os"

"github.com/spf13/cobra"

"github.com/danielfoehrkn/kubectlSwitch/pkg"

"github.com/spf13/cobra"
)

var (
Expand Down
3 changes: 0 additions & 3 deletions hack/switch/switch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added hack/switch/switcher
Binary file not shown.

0 comments on commit 64148e4

Please sign in to comment.