From 07d6f3eecf4ed55326eb6b025d4bfda9c1174e75 Mon Sep 17 00:00:00 2001 From: Doron KG <70585638+doronkg@users.noreply.github.com> Date: Sun, 3 Mar 2024 22:44:02 +0200 Subject: [PATCH] feat: krew plugin workflow (#214) * Added krew plugin workflow * Removed $ from kubectl command * Removed usage examples --- .github/workflows/release.yml | 8 ++++--- .krew.yaml | 43 +++++++++++++++++++++++++++++++++++ README.md | 5 ++++ cmd/kor/root.go | 13 ++++++++++- 4 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 .krew.yaml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 84403ea2..90091eab 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -33,13 +33,13 @@ jobs: with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - + - name: Extract metadata for the Docker image id: meta uses: docker/metadata-action@v5 with: images: ${{ secrets.DOCKERHUB_USERNAME }}/kor - + - name: Build and push the Docker image uses: docker/build-push-action@v5 with: @@ -47,4 +47,6 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - + + - name: Update new version in krew-index + uses: rajatjindal/krew-release-bot@v0.0.46 diff --git a/.krew.yaml b/.krew.yaml new file mode 100644 index 00000000..ae01867a --- /dev/null +++ b/.krew.yaml @@ -0,0 +1,43 @@ +apiVersion: krew.googlecontainertools.github.com/v1alpha2 +kind: Plugin +metadata: + name: kor +spec: + version: {{ .TagName }} + homepage: https://github.com/yonahd/kor + shortDescription: Kor is a tool to discover unused K8s resources. + description: | + This plugin shows unused Kubernetes resources (namespaced or cluster-scoped). + It provides additional capabilities such as exporting Prometheus metrics, + deleting unused resources, and more! + platforms: + - selector: + matchLabels: + os: linux + arch: amd64 + {{ addURIAndSha "https://github.com/yonahd/kor/releases/download/{{ .TagName }}/kor_Linux_x86_64.tar.gz" .TagName }} + bin: kor + - selector: + matchLabels: + os: linux + arch: arm64 + {{ addURIAndSha "https://github.com/yonahd/kor/releases/download/{{ .TagName }}/kor_Linux_arm64.tar.gz" .TagName }} + bin: kor + - selector: + matchLabels: + os: darwin + arch: amd64 + {{ addURIAndSha "https://github.com/yonahd/kor/releases/download/{{ .TagName }}/kor_Darwin_x86_64.tar.gz" .TagName }} + bin: kor + - selector: + matchLabels: + os: darwin + arch: arm64 + {{ addURIAndSha "https://github.com/yonahd/kor/releases/download/{{ .TagName }}/kor_Darwin_arm64.tar.gz" .TagName }} + bin: kor + - selector: + matchLabels: + os: windows + arch: amd64 + {{ addURIAndSha "https://github.com/yonahd/kor/releases/download/{{ .TagName }}/kor_Windows_x86_64.zip" .TagName }} + bin: kor.exe diff --git a/README.md b/README.md index fe6b1e0c..f34f14c2 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,11 @@ docker run --rm -i yonahdissen/kor docker run --rm -i -v "/path/to/.kube/config:/root/.kube/config" yonahdissen/kor all ``` +### Kubectl plugin (krew) +```sh +kubectl krew install kor +``` + ### Helm Run as a cronjob in your Cluster (with an option for sending slack updates) ```sh diff --git a/cmd/kor/root.go b/cmd/kor/root.go index ee703bed..f82f4f5a 100644 --- a/cmd/kor/root.go +++ b/cmd/kor/root.go @@ -3,6 +3,8 @@ package kor import ( "fmt" "os" + "path/filepath" + "strings" "github.com/spf13/cobra" @@ -11,8 +13,17 @@ import ( "github.com/yonahd/kor/pkg/utils" ) +func execName() string { + n := "kor" + if strings.HasPrefix(filepath.Base(os.Args[0]), "kubectl-") { + return "kubectl-" + n + } + + return n +} + var rootCmd = &cobra.Command{ - Use: "kor", + Use: execName(), Short: "kor - a CLI to to discover unused Kubernetes resources", Long: `kor is a CLI to to discover unused Kubernetes resources kor can currently discover unused configmaps and secrets`,