From 0baeeb0bd2492af8ccd7a035f7e23fa5db80bac8 Mon Sep 17 00:00:00 2001 From: Tiago Ilieve Date: Thu, 28 Dec 2023 01:39:04 -0300 Subject: [PATCH] Add 'kubectx' --- README.md | 2 ++ main.go | 9 +++++++++ tables/arch.go | 10 ++++++++++ tables/os.go | 10 ++++++++++ tables/tables_test.go | 4 ++++ tables/tools.go | 1 + tables/url.go | 1 + tools/asset.go | 4 ++++ tools/asset_test.go | 7 +++++++ tools/tools.go | 4 ++++ 10 files changed, 52 insertions(+) diff --git a/README.md b/README.md index 888120a..25e7d58 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ $ staticd - `cloudflared`: [cloudflare/cloudflared][cloudflared], Argo Tunnel client. - `flyctl`: [superfly/flyctl][flyctl], command line tools for fly.io services - `k9s`: [derailed/k9s][k9s], Kubernetes CLI to manage your clusters in style. +- `kubectx`: [ahmetb/kubectx][kubectx], faster way to switch between clusters in kubectl - `upx`: [upx/upx][upx], the Ultimate Packer for eXecutables. - `xh`: [ducaale/xh][xh], friendly and fast tool for sending HTTP requests. - `yj`: [sclevine/yj][yj], convert between YAML, TOML, JSON, and HCL. @@ -25,6 +26,7 @@ $ staticd [cloudflared]: https://github.com/cloudflare/cloudflared [flyctl]: https://github.com/superfly/flyctl [k9s]: https://github.com/derailed/k9s +[kubectx]: https://github.com/ahmetb/kubectx [upx]: https://github.com/upx/upx [xh]: https://github.com/ducaale/xh [yj]: https://github.com/sclevine/yj diff --git a/main.go b/main.go index d913b1a..4f2dcbe 100644 --- a/main.go +++ b/main.go @@ -118,6 +118,14 @@ func main() { }, } + kubectxCmd := &cobra.Command{ + Use: tools.Kubectx, + Short: "Faster way to switch between clusters in kubectl", + Run: func(cmd *cobra.Command, args []string) { + run(tools.Kubectx) + }, + } + upxCmd := &cobra.Command{ Use: tools.UPX, Short: "The Ultimate Packer for eXecutables", @@ -155,6 +163,7 @@ func main() { rootCmd.AddCommand(cloudflaredCmd) rootCmd.AddCommand(flyctlCmd) rootCmd.AddCommand(k9sCmd) + rootCmd.AddCommand(kubectxCmd) rootCmd.AddCommand(upxCmd) rootCmd.AddCommand(xhCmd) rootCmd.AddCommand(yjCmd) diff --git a/tables/arch.go b/tables/arch.go index e11d160..67308b2 100644 --- a/tables/arch.go +++ b/tables/arch.go @@ -47,6 +47,16 @@ var Arch = map[string]map[string]map[string]string{ "arm64": "arm64", }, }, + Kubectx: { + "darwin": { + "amd64": "x86_64", + "arm64": "arm64", + }, + "linux": { + "amd64": "x86_64", + "arm64": "arm64", + }, + }, UPX: { "linux": { "amd64": "amd64", diff --git a/tables/os.go b/tables/os.go index a6690b8..d02f4be 100644 --- a/tables/os.go +++ b/tables/os.go @@ -47,6 +47,16 @@ var OS = map[string]map[string]map[string]string{ "arm64": "Linux", }, }, + Kubectx: { + "darwin": { + "amd64": "darwin", + "arm64": "darwin", + }, + "linux": { + "amd64": "linux", + "arm64": "linux", + }, + }, UPX: { "linux": { "amd64": "linux", diff --git a/tables/tables_test.go b/tables/tables_test.go index a0bade9..34ccee5 100644 --- a/tables/tables_test.go +++ b/tables/tables_test.go @@ -42,6 +42,10 @@ func (s *TablesTestSuite) TestToolsNames() { local: tables.K9s, remote: tools.K9s, }, + { + local: tables.Kubectx, + remote: tools.Kubectx, + }, { local: tables.UPX, remote: tools.UPX, diff --git a/tables/tools.go b/tables/tools.go index a2562b0..3c2f80f 100644 --- a/tables/tools.go +++ b/tables/tools.go @@ -6,6 +6,7 @@ const ( Cloudflared = "cloudflared" Flyctl = "flyctl" K9s = "k9s" + Kubectx = "kubectx" UPX = "upx" Xh = "xh" Yj = "yj" diff --git a/tables/url.go b/tables/url.go index 238209a..14fe61c 100644 --- a/tables/url.go +++ b/tables/url.go @@ -6,6 +6,7 @@ var URL = map[string]string{ Cloudflared: "https://github.com/cloudflare/cloudflared/releases", Flyctl: "https://github.com/superfly/flyctl/releases", K9s: "https://github.com/derailed/k9s/releases", + Kubectx: "https://github.com/ahmetb/kubectx/releases", UPX: "https://github.com/upx/upx/releases", Xh: "https://github.com/ducaale/xh/releases", Yj: "https://github.com/sclevine/yj/releases", diff --git a/tools/asset.go b/tools/asset.go index 5973e0a..4cbd4ae 100644 --- a/tools/asset.go +++ b/tools/asset.go @@ -33,6 +33,10 @@ func (t *Tool) AssetK9s() { t.Asset.Name = fmt.Sprintf("k9s_%v_%v.tar.gz", t.OS, t.Arch) } +func (t *Tool) AssetKubectx() { + t.Asset.Name = fmt.Sprintf("kubectx_%v_%v_%v.tar.gz", t.Version, t.OS, t.Arch) +} + func (t *Tool) AssetUPX() { baseName := fmt.Sprintf("upx-%v-%v_%v", t.TrimVersion(), t.Arch, t.OS) t.Asset.Name = baseName + ".tar.xz" diff --git a/tools/asset_test.go b/tools/asset_test.go index a10ee37..25d8467 100644 --- a/tools/asset_test.go +++ b/tools/asset_test.go @@ -191,6 +191,13 @@ func (s *AssetTestSuite) TestName() { version: "v0.30.4", filename: "k9s_Linux_amd64.tar.gz", }, + { + name: Kubectx, + arch: "arm64", + os: "darwin", + version: "v0.9.5", + filename: "kubectx_v0.9.5_darwin_arm64.tar.gz", + }, { name: UPX, arch: "amd64", diff --git a/tools/tools.go b/tools/tools.go index fab5042..6bbc700 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -19,6 +19,7 @@ const ( Cloudflared = "cloudflared" Flyctl = "flyctl" K9s = "k9s" + Kubectx = "kubectx" UPX = "upx" Xh = "xh" Yj = "yj" @@ -140,6 +141,7 @@ func (t *Tool) GetVersion() error { return nil } +//nolint:cyclop func (t *Tool) SetAsset() error { t.Asset.Destination = path.Join(t.BaseDir(), t.Name) t.Asset.WithinArchive = t.Name @@ -155,6 +157,8 @@ func (t *Tool) SetAsset() error { t.AssetFlyctl() case K9s: t.AssetK9s() + case Kubectx: + t.AssetKubectx() case UPX: t.AssetUPX() case Xh: