Skip to content

Commit 1d5650d

Browse files
feat!: Rename project from kube-switcher to kubectl-switch
BREAKING CHANGE: the binary has been renamed from `kube-switcher` to `kubectl-switch`
1 parent 4aece45 commit 1d5650d

File tree

11 files changed

+53
-61
lines changed

11 files changed

+53
-61
lines changed

.devcontainer/devcontainer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "kube-switcher",
2+
"name": "kubectl-switch",
33
"build": {
44
"dockerfile": "Dockerfile"
55
},

.github/workflows/devcontainer-build.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
uses: mirceanton/reusable-workflows/.github/workflows/reusable-docker-build-push.yaml@1f67ebf2d8aa5a366dc1a2179911c7edaea8a5af # v3.4.18
1616
secrets: inherit
1717
with:
18-
image: "ghcr.io/mirceanton/kube-switcher-devcontainer"
18+
image: "ghcr.io/mirceanton/kubectl-switch-devcontainer"
1919
platforms: linux/amd64
2020
tags: test
2121
context: ./.devcontainer

.github/workflows/test.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ jobs:
2424
- name: Checkout
2525
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
2626

27-
- name: Build `kube-switcher`
28-
run: go build -o kube-switcher
27+
- name: Build `kubectl-switch`
28+
run: go build -o kubectl-switch
2929

3030
- name: Install `minikube`
3131
run: |
@@ -39,7 +39,7 @@ jobs:
3939
wait
4040
4141
- name: Switch context to test-cluster-1
42-
run: ./kube-switcher context test-cluster-1
42+
run: ./kubectl-switch context test-cluster-1
4343

4444
- name: Validate the cluster has switched to test-cluster-1 by listing nodes
4545
run: |
@@ -50,21 +50,21 @@ jobs:
5050
kubectl get pods --namespace=default 2>&1 | grep "No resources found" || { echo "Error: Pods found in default namespace!" >&2; exit 1; }
5151
5252
- name: Switch to the kube-system namespace
53-
run: ./kube-switcher namespace kube-system
53+
run: ./kubectl-switch namespace kube-system
5454

5555
- name: Validate that kube-system namespace is selected and kube-apiserver is running
5656
run: |
5757
kubectl get pods --namespace=kube-system | grep "kube-apiserver" || { echo "Error: kube-apiserver not found in kube-system!" >&2; exit 1; }
5858
5959
- name: Switch back to the default namespace
60-
run: ./kube-switcher namespace default
60+
run: ./kubectl-switch namespace default
6161

6262
- name: Check that no pods are found again in the default namespace
6363
run: |
6464
kubectl get pods --namespace=default 2>&1 | grep "No resources found" || { echo "Error: Pods found in default namespace!" >&2; exit 1; }
6565
6666
- name: Switch context to test-cluster-2
67-
run: ./kube-switcher context test-cluster-2
67+
run: ./kubectl-switch context test-cluster-2
6868

6969
- name: Validate the cluster has switched to test-cluster-2 by listing nodes
7070
run: |

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
kube-switcher
1+
kubectl-switch
22
dist/

.goreleaser.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
33
version: 2
4-
project_name: kube-switcher
4+
project_name: kubectl-switch
55

66
before:
77
hooks:
@@ -52,7 +52,7 @@ nfpms:
5252
formats: [deb, apk, rpm]
5353

5454
brews:
55-
- name: kube-switcher
55+
- name: kubectl-switch
5656
description: A simple tool to switch between Kubernetes contexts.
5757
license: MIT
5858
homepage: https://github.com/mirceanton/{{.ProjectName}}

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
FROM alpine:3.20.3@sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d
22
USER 8675:8675
3-
COPY kube-switcher /
4-
ENTRYPOINT ["/kube-switcher"]
3+
COPY kubectl-switch /
4+
ENTRYPOINT ["/kubectl-switch"]

README.md

+36-38
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,50 @@
1-
# kube-switcher
1+
# kubectl-switch
22

33
A simple tool to manage and switch between multiple Kubernetes configuration files. This tool allows you to dump all your kubeconfig files in a single directory and easily switch between them as well as configure the current namespace.
44

5-
Available both as a standalone CLI or a `kubectl` plugin.
6-
75
## Features
86

97
- Manage multiple kubeconfig files in a single directory.
108
- Easily switch between different Kubernetes contexts.
119
- Easily switch between different namespaces.
1210
- Persistent context/namespace switching across different shells.
1311
- Interactive prompts support fuzzy search.
14-
- Non-destructive operations on your original kubeconfig files. `kube-switcher` will never edit those. It will only work with copies of them.
12+
- Non-destructive operations on your original kubeconfig files. `kubectl-switch` will never edit those. It will only work with copies of them.
1513

16-
## Why `kube-switcher`?
14+
## Why `kubectl-switch`?
1715

18-
`kube-switcher` is an alternative to tools like `kubectx`, `kubens` and `kubie`. It has been created because I feel all of those fall short in certain regards:
16+
`kubectl-switch` is an alternative to tools like `kubectx`, `kubens` and `kubie`. It has been created because I feel all of those fall short in certain regards:
1917

20-
- `kubectx` assumes all your contexts are defined in a single config file. Yes, there is some hackery you can do to your `KUBECONFIG` environment variable to make it work with multiple files, but it is a sub-par workflow in my opinion and I never really liked it
18+
- `kubectx` and `kubens` assume all your contexts are defined in a single config file. Yes, there is some hackery you can do to your `KUBECONFIG` environment variable to make it work with multiple files, but it is (in my opinion) a sub-par workflow and I never really liked it
2119
- `kubie` spawns a new shell when you use it to change contexts, making it practically impossible to integrate into scripts or taskfile automation. Also I consider it to be too complicated of a solution for what is fundamentally a really simple problem
2220

23-
What I wanted was something much simpler conceptually: I just want to dump all my `kubeconfig` files in a single directory and then, have my tool parse them and "physically" move over the config file to `.kube/config` (or whatever is configured in my `KUBECONFIG` env var) such that it is also persistent between different shells.
21+
What I wanted was something very simple conceptually: I just want to dump all my `kubeconfig` files in a single directory and then have my tool parse them and "physically" move over the config file to `.kube/config` (or whatever is configured in my `KUBECONFIG` env var) such that it is also persistent between different shells. Here is where `kubectl-switch` comes in!
2422

2523
## Installation
2624

27-
> [!TIP]
28-
> When installing `kube-switcher`, you can use it as a `kubectl` plugin by just renaming the binary to `kubectl-switch`.
29-
> This way, you can run it via `kubectl switch ...`
30-
3125
### Download Precompiled Binaries
3226

33-
Precompiled binaries are available for various platforms. You can download the latest release from the [GitHub Releases page](https://github.com/mirceanton/kube-switcher/releases/latest).
27+
Precompiled binaries are available for various platforms. You can download the latest release from the [GitHub Releases page](https://github.com/mirceanton/kubectl-switch/releases/latest).
3428

3529
1. Download the appropriate binary for your system and extract the archive.
3630
2. Make the extracted binary executable:
3731

3832
```bash
39-
chmod +x kube-switcher
33+
chmod +x kubectl-switch
4034
```
4135

4236
3. Move the binary to a directory in your PATH:
4337

4438
```bash
45-
mv kube-switcher /usr/local/bin/kube-switcher
39+
mv kubectl-switch /usr/local/bin/kubectl-switch
4640
```
4741

4842
### Running via Docker
4943

50-
`kube-switcher` is also available as a Docker container:
44+
`kubectl-switch` is also available as a Docker container:
5145

5246
```bash
53-
docker pull ghcr.io/mirceanton/kube-switcher
47+
docker pull ghcr.io/mirceanton/kubectl-switch
5448
```
5549

5650
### Install via homebrew
@@ -61,19 +55,19 @@ docker pull ghcr.io/mirceanton/kube-switcher
6155
brew tap mirceanton/taps
6256
```
6357

64-
2. Install `kube-switcher`
58+
2. Install `kubectl-switch`
6559

6660
```bash
67-
brew install kube-switcher
61+
brew install kubectl-switch
6862
```
6963

7064
### Build from Source
7165

7266
1. Clone the repository:
7367

7468
```bash
75-
git clone https://github.com/mirceanton/kube-switcher
76-
cd kube-switcher
69+
git clone https://github.com/mirceanton/kubectl-switch
70+
cd kubectl-switch
7771
```
7872

7973
2. Build the tool:
@@ -87,50 +81,52 @@ docker pull ghcr.io/mirceanton/kube-switcher
8781
Otherwise, simply run the `go build` command:
8882

8983
```bash
90-
go build -o talswitcher
84+
go build -o kubectl-switch
9185
```
9286

9387
## Usage
9488

95-
1. Place all of your `kubeconfig` files in a single directory. I personally prefer `~/.kube/configs/`
89+
1. Place all of your `kubeconfig` files in a single directory. I personally prefer `~/.kube/configs/` but you can do whatever you fancy.
9690

9791
2. Set the environment variable `KUBECONFIG_DIR`
9892

9993
```sh
100-
export KUBECONFIG_DIR="~/.kube/configs/"
94+
export KUBECONFIG_DIR="~/.kube/configs/" # <- put here whatever folder you decided on at step 1
10195
```
10296

103-
3. Run `kube-swticher context`/`kube-switcher ctx` or `kubectl switch context`/`kubectl switch ctx` to interactively select your context from a list
97+
3. Run `kubectl switch ctx` or `kubectl switch context` to interactively select your context from a list
10498

10599
```sh
106-
vscode ➜ /workspaces/kube-switcher $ kubectl switch context
100+
vscode ➜ /workspaces/kubectl-switch $ kubectl switch context
107101
? Choose a context: [Use arrows to move, type to filter]
108-
cluster1
102+
cluster1kubectl-switch
109103
cluster2
110-
> cluster3
104+
> cluster3kubectl-switch
111105
112-
INFO[0102] Switched to context 'cluster3'
106+
INFO[0102] Switched tkubectl-switchuster3'
113107
114-
vscode ➜ /workspaces/kube-switcher $ kubectl get nodes
108+
vscode ➜ /workspaces/kubectl-switch $ kubectl get nodes
115109
NAME STATUS ROLES AGE VERSION
116110
cluster3 Ready control-plane 21h v1.30.0
117111
```
118112
119113
Alternatively, pass in a context name to the command to non-interactively switch to it:
120114
121115
```sh
122-
vscode ➜ /workspaces/kube-switcher $ kubectl switch ctx cluster3
116+
vscode ➜ /workspaces/kubectl-switch $ kubectl switch ctx cluster3
123117
INFO[0000] Switched to context 'cluster3'
124118
125-
vscode ➜ /workspaces/kube-switcher $ kubectl get nodes
119+
vscode ➜ /workspaces/kubectl-switch $ kubectl get nodes
126120
NAME STATUS ROLES AGE VERSION
127121
cluster3 Ready control-plane 21h v1.30.0
128122
```
129123
130-
4. Run the `kube-switcher namespace`/`kube-switcher ns` or `kubectl switch namespace`/`kubectl switch ns` to interactively select your current namespace from a list
124+
This will literally detect the file in which that context is defined and copy-paste it to the path defined in your `KUBECONFIG`.
125+
126+
4. Run the `kubectl switch ns` or `kubectl switch namespace` to interactively select your current namespace from a list
131127
132128
```sh
133-
vscode ➜ /workspaces/kube-switcher $ kubectl switch namespace
129+
vscode ➜ /workspaces/kubectl-switch $ kubectl switch namespace
134130
? Choose a namespace: [Use arrows to move, type to filter]
135131
> default
136132
kube-node-lease
@@ -139,7 +135,7 @@ docker pull ghcr.io/mirceanton/kube-switcher
139135
140136
INFO[0012] Switched to namespace 'kube-system'
141137
142-
vscode ➜ /workspaces/kube-switcher $ kubectl get pods
138+
vscode ➜ /workspaces/kubectl-switch $ kubectl get pods
143139
NAME READY STATUS RESTARTS AGE
144140
coredns-7db6d8ff4d-nqmlf 1/1 Running 1 (69m ago) 21h
145141
etcd-cluster1 1/1 Running 1 (69m ago) 21h
@@ -153,14 +149,16 @@ docker pull ghcr.io/mirceanton/kube-switcher
153149
Alternatively, pass in a namespace name to the command to non-interactively switch to it:
154150
155151
```sh
156-
vscode ➜ /workspaces/kube-switcher $ kubectl get pods
152+
vscode ➜ /workspaces/kubectl-switch $ kubectl get pods
157153
No resources found in default namespace.
158-
vscode ➜ /workspaces/kube-switcher $ kubectl switch ns kube-public
154+
vscode ➜ /workspaces/kubectl-switch $ kubectl switch ns kube-public
159155
INFO[0000] Switched to namespace 'kube-public'
160-
vscode ➜ /workspaces/kube-switcher $ kubectl get pods
156+
vscode ➜ /workspaces/kubectl-switch $ kubectl get pods
161157
No resources found in kube-public namespace.
162158
```
163159
160+
This will modify your currently active kubeconfig file (not the original one from `KUBECONFIGS_DIR`, but rather the copy from `KUBECONFIG`) to set the current namespace.
161+
164162
## License
165163
166164
This project is licensed under the MIT License. See the `LICENSE` file for details.

cmd/root.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ var (
1212
)
1313

1414
var rootCmd = &cobra.Command{
15-
Use: "kube-switcher",
15+
Use: "kubectl-switch",
1616
Short: "A tool to switch Kubernetes contexts",
17-
Long: `kube-switcher is a CLI tool to switch Kubernetes contexts from multiple kubeconfig files.`,
17+
Long: `kubectl-switch is a CLI tool to switch Kubernetes contexts from multiple kubeconfig files.`,
1818
Version: version,
1919
}
2020

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/mirceanton/kube-switcher
1+
module github.com/mirceanton/kubectl-switch
22

33
go 1.22.5
44

go.sum

-6
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,10 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
183183
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
184184
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
185185
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
186-
k8s.io/api v0.31.0 h1:b9LiSjR2ym/SzTOlfMHm1tr7/21aD7fSkqgD/CVJBCo=
187-
k8s.io/api v0.31.0/go.mod h1:0YiFF+JfFxMM6+1hQei8FY8M7s1Mth+z/q7eF1aJkTE=
188186
k8s.io/api v0.31.1 h1:Xe1hX/fPW3PXYYv8BlozYqw63ytA92snr96zMW9gWTU=
189187
k8s.io/api v0.31.1/go.mod h1:sbN1g6eY6XVLeqNsZGLnI5FwVseTrZX7Fv3O26rhAaI=
190-
k8s.io/apimachinery v0.31.0 h1:m9jOiSr3FoSSL5WO9bjm1n6B9KROYYgNZOb4tyZ1lBc=
191-
k8s.io/apimachinery v0.31.0/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
192188
k8s.io/apimachinery v0.31.1 h1:mhcUBbj7KUjaVhyXILglcVjuS4nYXiwC+KKFBgIVy7U=
193189
k8s.io/apimachinery v0.31.1/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
194-
k8s.io/client-go v0.31.0 h1:QqEJzNjbN2Yv1H79SsS+SWnXkBgVu4Pj3CJQgbx0gI8=
195-
k8s.io/client-go v0.31.0/go.mod h1:Y9wvC76g4fLjmU0BA+rV+h2cncoadjvjjkkIGoTLcGU=
196190
k8s.io/client-go v0.31.1 h1:f0ugtWSbWpxHR7sjVpQwuvw9a3ZKLXX0u0itkFXufb0=
197191
k8s.io/client-go v0.31.1/go.mod h1:sKI8871MJN2OyeqRlmA4W4KM9KBdBUpDLu/43eGemCg=
198192
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=

main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main
22

33
import (
4-
"github.com/mirceanton/kube-switcher/cmd"
4+
"github.com/mirceanton/kubectl-switch/cmd"
55
)
66

77
func main() {

0 commit comments

Comments
 (0)