Commit Graph

290 Commits

Author SHA1 Message Date
Ahmet Alp Balkan
039f5ed1ef fix: skip fzf launch when no contexts exist in kubeconfig (#480)
Return an error early in InteractiveSwitchOp if the kubeconfig has no
contexts, instead of launching fzf with an empty list.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 06:54:27 +00:00
Ahmet Alp Balkan
81defc835f refactor: replace testutil.WithEnvVar with t.Setenv (#479)
t.Setenv is the modern standard Go testing utility (since Go 1.17) that automatically restores environment variables when the test completes. This replaces the custom testutil.WithEnvVar function which manually saved and restored env var state.

The testutil.go file is deleted as it only contained WithEnvVar. The testutil package remains for its other utilities like KubeconfigBuilder.
2026-03-08 20:26:40 -07:00
Ahmet Alp Balkan
d3576731a0 feat: add XDG_CACHE_HOME support to Go implementations (#478)
Adds a new CacheDir() function that respects the XDG_CACHE_HOME environment variable,
matching the bash scripts' behavior. kubectx and kubens now prefer XDG_CACHE_HOME when
set, falling back to $HOME/.kube otherwise. This aligns the Go implementations with
the bash scripts' cache directory logic.

Includes comprehensive tests covering all scenarios:
- XDG_CACHE_HOME set (returns the XDG value)
- XDG_CACHE_HOME unset (falls back to $HOME/.kube)
- Neither set (returns empty string)
2026-03-08 20:19:35 -07:00
Ahmet Alp Balkan
aa92c923c2 docs: simplify installation instructions into a single table (#477)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 18:01:03 -07:00
Ahmet Alp Balkan
bb9592d770 chore: update goreleaser config and release workflow (#475)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 17:44:31 -07:00
Ahmet Alp Balkan
0d800e1367 fix: improve error handling and resource management in kubeconfig (#476)
This change addresses eight key improvements to the kubectx/kubens codebase:

Resource Management Fixes:
- Fix use-after-close bugs where Kubeconfig was accessed after Close()
- Fix resource leaks on error paths by ensuring defer kc.Close() is called
- Fix YAML encoder not being closed after Encode(), causing buffered data loss

API Design Improvements:
- Change ContextNames() to return ([]string, error) instead of silently returning
  nil on error, making parse failures distinguishable from empty results
- Change GetCurrentContext() to return (string, error) instead of returning ""
  for both "not set" and parse error cases
- Update all 16 call sites across cmd/kubectx and cmd/kubens packages to handle
  the new error returns while preserving backward-compatible behavior

Error Handling:
- Add explicit error handling for printer.Success() calls in 5+ locations
  by prefixing unchecked calls with _ =

Performance:
- Add slice pre-allocation in namespace list pagination using slices.Grow()
  before append loops, reducing allocations when fetching 500+ item batches

All changes maintain backward compatibility for missing kubeconfig keys while
improving error transparency and resource safety.
2026-03-08 17:44:18 -07:00
Ahmet Alp Balkan
860e09775b refactor: modernize Go codebase for Go 1.25 (#473)
Modernize the codebase to use idiomatic Go 1.25 patterns, removing deprecated APIs and reducing external dependencies.

- Replace deprecated `io/ioutil` with `os.ReadFile`, `os.WriteFile`, `os.MkdirTemp`, `os.CreateTemp`
- Replace `interface{}` with `any` (Go 1.18+)
- Remove `github.com/pkg/errors` dependency entirely, using stdlib `fmt.Errorf` with `%w` and `errors.New`
- Use `errors.As()` instead of direct type assertions on error values
- Use `strings.Cut()` for delimiter parsing instead of `strings.Split` + length check
- Use `slices.Contains()` for linear search in `ContextExists()`
- Use `t.Setenv()` and `t.TempDir()` in tests instead of manual env save/restore and temp dir cleanup
- Delete unused `internal/testutil/tempfile.go` helper
- Update GitHub Actions CI and release workflows from Go 1.22 to 1.25

Net result: -70 lines, 1 fewer external dependency.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 17:07:59 -07:00
Ahmet Alp Balkan
189100f2b6 ci: add workflow to warn PRs modifying frozen bash scripts (#474)
Adds a GitHub Actions workflow that comments on PRs modifying the root kubectx or kubens bash scripts
The comment uses a [!WARNING] alert to inform contributors that bash implementations are frozen and to propose changes to the Go implementation instead
Skips the comment if the PR author is ahmetb

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 16:49:55 -07:00
Joffrey Mischler
c13bf5a18b feat(kubens): add unset option (#440)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Ahmet Alp Balkan <ahmet@linkedin.com>
2026-03-08 16:19:49 -07:00
github-actions[bot]
defbc123a4 Merge pull request #466 from ahmetb/dependabot/go_modules/kubernetes-a1707b12ae
chore(deps): bump the kubernetes group with 2 updates
2026-03-08 23:09:07 +00:00
dependabot[bot]
d770af960d chore(deps): bump the kubernetes group with 2 updates
Bumps the kubernetes group with 2 updates: [k8s.io/apimachinery](https://github.com/kubernetes/apimachinery) and [k8s.io/client-go](https://github.com/kubernetes/client-go).


Updates `k8s.io/apimachinery` from 0.28.5 to 0.35.2
- [Commits](https://github.com/kubernetes/apimachinery/compare/v0.28.5...v0.35.2)

Updates `k8s.io/client-go` from 0.28.5 to 0.35.2
- [Changelog](https://github.com/kubernetes/client-go/blob/master/CHANGELOG.md)
- [Commits](https://github.com/kubernetes/client-go/compare/v0.28.5...v0.35.2)

---
updated-dependencies:
- dependency-name: k8s.io/apimachinery
  dependency-version: 0.35.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: kubernetes
- dependency-name: k8s.io/client-go
  dependency-version: 0.35.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: kubernetes
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-08 23:08:58 +00:00
dependabot[bot]
6f020b98a5 chore(deps): bump samuelmeuli/action-snapcraft from 1 to 3 (#468)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-08 16:08:48 -07:00
dependabot[bot]
58ae4f7464 chore(deps): bump goreleaser/goreleaser-action from 2 to 7 (#467)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-08 16:08:44 -07:00
dependabot[bot]
6f89971cc4 chore(deps): bump actions/setup-go from 2 to 6 (#465)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-08 16:08:37 -07:00
github-actions[bot]
171ce81a99 Merge pull request #471 from ahmetb/dependabot/go_modules/github.com/fatih/color-1.18.0
chore(deps): bump github.com/fatih/color from 1.9.0 to 1.18.0
2026-03-08 23:08:16 +00:00
dependabot[bot]
b1dec7b4ae chore(deps): bump github.com/fatih/color from 1.9.0 to 1.18.0
Bumps [github.com/fatih/color](https://github.com/fatih/color) from 1.9.0 to 1.18.0.
- [Release notes](https://github.com/fatih/color/releases)
- [Commits](https://github.com/fatih/color/compare/v1.9.0...v1.18.0)

---
updated-dependencies:
- dependency-name: github.com/fatih/color
  dependency-version: 1.18.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-08 23:08:05 +00:00
github-actions[bot]
da8283523a Merge pull request #470 from ahmetb/dependabot/go_modules/github.com/mattn/go-isatty-0.0.20
chore(deps): bump github.com/mattn/go-isatty from 0.0.14 to 0.0.20
2026-03-08 23:07:31 +00:00
dependabot[bot]
830c34933a chore(deps): bump github.com/mattn/go-isatty from 0.0.14 to 0.0.20
Bumps [github.com/mattn/go-isatty](https://github.com/mattn/go-isatty) from 0.0.14 to 0.0.20.
- [Commits](https://github.com/mattn/go-isatty/compare/v0.0.14...v0.0.20)

---
updated-dependencies:
- dependency-name: github.com/mattn/go-isatty
  dependency-version: 0.0.20
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-08 23:07:22 +00:00
github-actions[bot]
439f75c76b Merge pull request #469 from ahmetb/dependabot/go_modules/sigs.k8s.io/kustomize/kyaml-0.21.1
chore(deps): bump sigs.k8s.io/kustomize/kyaml from 0.16.0 to 0.21.1
2026-03-08 23:06:42 +00:00
dependabot[bot]
05b0aae499 chore(deps): bump sigs.k8s.io/kustomize/kyaml from 0.16.0 to 0.21.1
Bumps [sigs.k8s.io/kustomize/kyaml](https://github.com/kubernetes-sigs/kustomize) from 0.16.0 to 0.21.1.
- [Release notes](https://github.com/kubernetes-sigs/kustomize/releases)
- [Commits](https://github.com/kubernetes-sigs/kustomize/compare/api/v0.16.0...api/v0.21.1)

---
updated-dependencies:
- dependency-name: sigs.k8s.io/kustomize/kyaml
  dependency-version: 0.21.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-08 23:06:32 +00:00
github-actions[bot]
f0ef521d44 Merge pull request #472 from ahmetb/dependabot/go_modules/github.com/google/go-cmp-0.7.0
chore(deps): bump github.com/google/go-cmp from 0.5.9 to 0.7.0
2026-03-08 23:05:41 +00:00
dependabot[bot]
c22e1bce9c chore(deps): bump actions/cache from 4 to 5 (#463)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-08 16:04:59 -07:00
github-actions[bot]
052dfbf90a Merge pull request #464 from ahmetb/dependabot/github_actions/rajatjindal/krew-release-bot-0.0.51
chore(deps): bump rajatjindal/krew-release-bot from 0.0.38 to 0.0.51
2026-03-08 23:04:51 +00:00
dependabot[bot]
e9050880c7 chore(deps): bump github.com/google/go-cmp from 0.5.9 to 0.7.0
Bumps [github.com/google/go-cmp](https://github.com/google/go-cmp) from 0.5.9 to 0.7.0.
- [Release notes](https://github.com/google/go-cmp/releases)
- [Commits](https://github.com/google/go-cmp/compare/v0.5.9...v0.7.0)

---
updated-dependencies:
- dependency-name: github.com/google/go-cmp
  dependency-version: 0.7.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-08 22:58:13 +00:00
dependabot[bot]
430c1534d2 chore(deps): bump rajatjindal/krew-release-bot from 0.0.38 to 0.0.51
Bumps [rajatjindal/krew-release-bot](https://github.com/rajatjindal/krew-release-bot) from 0.0.38 to 0.0.51.
- [Release notes](https://github.com/rajatjindal/krew-release-bot/releases)
- [Commits](https://github.com/rajatjindal/krew-release-bot/compare/v0.0.38...v0.0.51)

---
updated-dependencies:
- dependency-name: rajatjindal/krew-release-bot
  dependency-version: 0.0.51
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-08 22:57:54 +00:00
Ahmet Alp Balkan
a6cf1728fe chore: add dependabot config and auto-merge workflow (#462)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 15:57:13 -07:00
ultram4rine
80bbe8306a Migrate to kyaml (#412)
Closes #327.
2026-03-08 15:20:45 -07:00
Ahmet Alp Balkan
4c9e8fb81e feat: add -s/--shell flag for scoped sub-shell (#461)
Spawns an isolated sub-shell with a minimal kubeconfig containing only the specified context.

This allows the user to launch a shell where they can only interact with a single cluster without having to worry about a command or an LLM agent interacting with other contexts.

Inside the isolated shell, most context switching/editing operations on kubectx are blocked. Nested shells not allowed.

Fixes #12.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 14:48:03 -07:00
Ahmet Alp Balkan
5a29645996 fix(ci): upgrade actions/cache from v2 to v4 (#460)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 13:46:29 -07:00
Ahmet Alp Balkan
c52b598c2c docs: add description and legacy note to bash --help output (#459)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 13:28:53 -07:00
justin0u0
013b6bc252 fix(kubectx): use the env variable for kubectl (#438) 2025-01-22 09:07:57 -08:00
Antoine
0bcd0d5dd5 fix some ci enhancement (#435)
* fix(release): customize goreleaser config file, by adding json schema and fixing configuration version

* fix(go): rename invalid comment format

* fix(ci): made release workflow work again

replace goreleaser --rm-dist flag by --clean
increment go version for release pipeline
fetch previous tags use by goreleaser
give release workflow content write permissions to publish release
2025-01-07 12:25:01 -08:00
Suleiman Dibirov
561793c356 chore: upgrade Go version to 1.22 (#425) 2024-07-10 14:25:37 -07:00
Suleiman Dibirov
b5daf2cef7 feat(kubens): added force flag to switch namespaces even if it doesn'… (#416)
* feat(kubens): added force flag to switch namespaces even if it doesn't exist

* Merged lines

* fixed README.md and flags.go

* updated flags.go, flags_test.go
2024-07-09 21:38:40 -07:00
pullmerge
4997a261dc Fix some comments (#418) 2024-04-15 09:31:07 -07:00
Marcos Alano
8fb8c9f2f2 Add support to publish Snaps using goreleaser (#353)
Closes #351.
2023-12-25 00:28:51 -08:00
Nabil
11c19c0fb7 Add Scoop command (#396) 2023-08-04 15:04:50 -07:00
Ahmet Alp Balkan
92e5b5f43b Release v0.9.5 v0.9.5 2023-07-13 20:12:27 -07:00
Ahmet Alp Balkan
33c27c03b2 k8s.io & go version bump (#393) 2023-07-13 20:10:47 -07:00
niko2
7560b8f04f Modify oh-my-zsh example (#346) 2023-03-15 16:30:08 -07:00
Ahmet Alp Balkan
d8ff2847ba fix go.sum tidy
Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
2023-02-24 12:03:11 -08:00
Gastón Haro
da454d8a0c Fix README.md "alias" to "rename" (#375) 2023-02-24 09:20:16 -08:00
Nikolas Grottendieck
021c1bc736 Windows installation instructions (winget) (#365) (#381) 2023-02-24 09:14:12 -08:00
Vincent Victoria
29850e1a75 Add prerequisite for completion to work after brew install (#368) 2022-10-24 12:06:54 -07:00
Sandro
7d6b179aed Bump golang.org/x/sys to fix compilation on M1 macs (#360) 2022-08-04 08:41:17 -07:00
Apoorv Verma [AP]
e5e7f53336 Windows installation instructions (Chocolatey) (#350) 2022-03-16 00:08:53 -07:00
Gábor Lipták
e6de7ba0a2 Run Go 1.17 mod tiny (#336) 2022-01-10 21:00:11 -08:00
SADIK KUZU
b6b364685a Fix typo on README.md (#341) 2022-01-09 09:39:34 -08:00
Ahmet Alp Balkan
617e4f0562 add build cache to actions (#339) 2021-12-26 21:50:17 -08:00
Kai
60523045a5 README.md: HTTP => HTTPS (#337) 2021-11-28 08:23:09 -08:00