-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introducing janitor: A kubectl plugin to find objects in a problematic state in your Kubernetes cluster.
- Loading branch information
Showing
26 changed files
with
2,578 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: ci | ||
on: | ||
push: | ||
pull_request: | ||
jobs: | ||
goreleaser: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@master | ||
- name: Setup Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.15 | ||
- name: GoReleaser | ||
uses: goreleaser/goreleaser-action@v2 | ||
with: | ||
version: latest | ||
args: release --snapshot --rm-dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: release | ||
on: | ||
push: | ||
tags: | ||
- 'v*.*.*' | ||
jobs: | ||
goreleaser: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@master | ||
- name: Setup Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.15 | ||
- name: GoReleaser | ||
uses: goreleaser/goreleaser-action@v2 | ||
with: | ||
version: latest | ||
args: release --rm-dist | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.vscode/ | ||
dist/ | ||
/kubectl-janitor | ||
/cmd/kubectl-janitor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
before: | ||
hooks: | ||
- go mod download | ||
builds: | ||
- id: kubectl-janitor | ||
main: ./cmd/ | ||
binary: kubectl-janitor | ||
env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- darwin | ||
- linux | ||
- windows | ||
goarch: | ||
- amd64 | ||
|
||
checksum: | ||
name_template: 'checksums.txt' | ||
|
||
archives: | ||
- builds: | ||
- kubectl-janitor | ||
name_template: "{{ .ProjectName }}_{{ .Tag }}_{{ .Os }}_{{ .Arch }}" | ||
wrap_in_directory: false | ||
files: | ||
- LICENSE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
apiVersion: krew.googlecontainertools.github.com/v1alpha2 | ||
kind: Plugin | ||
metadata: | ||
name: janitor | ||
spec: | ||
version: {{ .TagName }} | ||
homepage: https://github.com/dastergon/kubectl-janitor | ||
shortDescription: Find objects in a problematic state | ||
description: | | ||
This plugin assists in finding | ||
Kubernetes objects in a problematic state. | ||
platforms: | ||
- selector: | ||
matchLabels: | ||
os: darwin | ||
arch: amd64 | ||
{{addURIAndSha "https://github.com/dastergon/kubectl-janitor/releases/download/{{ .TagName }}/kubectl-janitor_{{ .TagName }}_darwin_amd64.tar.gz" .TagName }} | ||
bin: kubectl-janitor | ||
- selector: | ||
matchLabels: | ||
os: linux | ||
arch: amd64 | ||
{{addURIAndSha "https://github.com/dastergon/kubectl-janitor/releases/download/{{ .TagName }}/kubectl-janitor_{{ .TagName }}_linux_amd64.tar.gz" .TagName }} | ||
bin: kubectl-janitor | ||
- selector: | ||
matchLabels: | ||
os: windows | ||
arch: amd64 | ||
{{addURIAndSha "https://github.com/dastergon/kubectl-janitor/releases/download/{{ .TagName }}/kubectl-janitor_{{ .TagName }}_windows_amd64.tar.gz" .TagName }} | ||
bin: kubectl-janitor.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# kubectl janitor | ||
|
||
[![Build Status](https://github.com/dastergon/kubectl-janitor/workflows/ci/badge.svg | ||
)](https://github.com/dastergon/kubectl-janitor/workflows/ci/) | ||
[![Go Report Card](https://goreportcard.com/badge/dastergon/kubectl-janitor)](https://goreportcard.com/report/dastergon/kubectl-janitor) | ||
[![LICENSE](https://img.shields.io/github/license/dastergon/kubectl-janitor.svg)](https://github.com/dastergon/kubectl-janitor/blob/master/LICENSE) | ||
[![Releases](https://img.shields.io/github/release-pre/dastergon/kubectl-janitor.svg)](https://github.com/dastergon/kubectl-janitor/releases) | ||
|
||
`kubectl janitor` is a kubectl plugin that assists in finding objects in a problematic state in your Kubernetes cluster. | ||
|
||
## Introduction | ||
Troubleshooting Kubernetes clusters sometimes requires a [combination](https://learnk8s.io/troubleshooting-deployments) of `kubectl` commands and other command-line tools such as [jq](https://github.com/stedolan/jq) to do correlations around the issues that the various objects might have. Moreover, sometimes the supported options of the `--field-selector` flag might be [limited](https://github.com/kubernetes/kubernetes/issues/49387). | ||
|
||
During troubleshooting scenarios, people need to identify the issues quickly without worrying about remembering all the different command combinations. The primary goal of this plugin is to collect some commonly executed kubectl command patterns to identify objects in a problematic state in the cluster and reduce the cognitive load for people troubleshooting. | ||
|
||
## Installing | ||
|
||
### Krew | ||
|
||
You can install `kubectl janitor` using the [Krew](https://github.com/kubernetes-sigs/krew), the package manager for kubectl plugins. | ||
|
||
Once you have Krew [installed](https://krew.sigs.k8s.io/docs/user-guide/setup/install/) run the following command: | ||
|
||
kubectl krew install janitor | ||
|
||
### Releases | ||
|
||
Check the [release](https://github.com/dastergon/kubectl-janitor/releases) page for the full list of pre-built assets. | ||
|
||
#### Install | ||
|
||
1. Download one of the releases that are compatible with your os/arch. | ||
2. Unzip to get `kubectl-janitor` | ||
3. Add it to your `PATH` or move it to a path already in in `PATH` (i.e., `/usr/local/bin`) | ||
|
||
### Source | ||
|
||
go get -u github.com/dastergon/kubectl-janitor/cmd/kubectl-janitor | ||
|
||
This command will download and compile `kubectl-janitor`. | ||
|
||
## Usage | ||
|
||
To get the full list of commands with examples: | ||
|
||
kubectl janitor | ||
|
||
### Features | ||
|
||
#### List Pods that are in a pending state (waiting to be scheduled) | ||
|
||
kubectl janitor pods unscheduled | ||
|
||
#### List Pods in an unhealthy state | ||
|
||
kubectl janitor pods unhealthy | ||
|
||
#### List Pods that are currently running but not ready for some reason | ||
|
||
kubectl janitor pods unready | ||
|
||
#### List the current statuses of the Pods and their respective count | ||
|
||
kubectl janitor pods status | ||
|
||
#### List Jobs that have failed to run and have restartPolicy: Never | ||
|
||
kubectl janitor jobs failed | ||
|
||
#### List PesistentVolumes that are available for claim | ||
|
||
kubectl janitor pvs unclaimed | ||
|
||
#### List PersistentVolumeClaims in a pending state (unbound) | ||
|
||
kubectl janitor pvcs pending | ||
|
||
You can use the `-A` or `--all-namespaces` flag to search for objects in all namespaces. | ||
|
||
You can use the `--no-headers` flag to avoid showing the column names. | ||
|
||
## Cleanup | ||
If you have installed the plugin via the `krew` command. You can remove the plugin by using the same tool: | ||
|
||
kubectl krew uninstall kubectl-janitor | ||
|
||
Or, you can "uninstall" this plugin from kubectl by simply removing it from your PATH: | ||
|
||
rm /usr/local/bin/kubectl-janitor | ||
|
||
## Author | ||
|
||
Pavlos Ratis [@dastergon](https://twitter.com/dastergon). | ||
|
||
## License | ||
|
||
[Apache 2.0.](./LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/dastergon/kubectl-janitor/pkg/cmd" | ||
"github.com/spf13/pflag" | ||
|
||
_ "k8s.io/client-go/plugin/pkg/client/auth" | ||
) | ||
|
||
// version is populated by goreleaser | ||
var version string | ||
|
||
// Execute consolidates all sub-commands to the root command and sets the flags. | ||
func Execute() error { | ||
root := cmd.NewJanitorCommand() | ||
root.Version = version | ||
return root.Execute() | ||
} | ||
|
||
func main() { | ||
flags := pflag.NewFlagSet("kubectl-janitor", pflag.ExitOnError) | ||
pflag.CommandLine = flags | ||
|
||
if err := Execute(); err != nil { | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMainUnknownCommand(t *testing.T) { | ||
defer func(args []string) { | ||
os.Args = args | ||
}(os.Args) | ||
|
||
os.Args = []string{"janitor", "etoomanycookies"} | ||
|
||
err := Execute() | ||
|
||
assert.Error(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module github.com/dastergon/kubectl-janitor | ||
|
||
go 1.15 | ||
|
||
require ( | ||
github.com/spf13/cobra v1.1.1 | ||
github.com/spf13/pflag v1.0.5 | ||
github.com/stretchr/testify v1.4.0 | ||
k8s.io/api v0.19.4 | ||
k8s.io/apimachinery v0.19.4 | ||
k8s.io/cli-runtime v0.19.4 | ||
k8s.io/client-go v0.19.4 | ||
k8s.io/kubectl v0.19.4 | ||
) |
Oops, something went wrong.