From 3b19d4740d832afe3e31da75ce0842630f7cd606 Mon Sep 17 00:00:00 2001 From: Daniel Henkel Date: Thu, 7 Dec 2023 10:19:34 +0100 Subject: [PATCH] feature: merge evict pod command into debug-pdb --- .goreleaser.yaml | 43 -------------- README.md | 66 ++++------------------ cmd/kubectl-debug-pdb/kubectl-debug-pdb.go | 1 + cmd/kubectl-evict/kubectl-evict.go | 33 ----------- pkg/cmd/evict_pod.go | 2 +- 5 files changed, 14 insertions(+), 131 deletions(-) delete mode 100644 cmd/kubectl-evict/kubectl-evict.go diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 3a1395b..1dd400f 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -27,20 +27,6 @@ builds: - linux - windows - darwin - - env: - - CGO_ENABLED=0 - main: ./cmd/kubectl-evict/kubectl-evict.go - id: kubectl-evict - binary: kubectl-evict - goarch: - - amd64 - - arm - - arm64 - goos: - - linux - - windows - - darwin - archives: - id: kubectl-debug-pdb builds: @@ -58,22 +44,6 @@ archives: format_overrides: - goos: windows format: zip - - id: kubectl-evict - builds: - - kubectl-evict - format: tar.gz - # this name template makes the OS and Arch compatible with the results of `uname`. - name_template: >- - {{ .Binary }}_ - {{- title .Os }}_ - {{- if eq .Arch "amd64" }}x86_64 - {{- else if eq .Arch "386" }}i386 - {{- else }}{{ .Arch }}{{ end }} - {{- if .Arm }}v{{ .Arm }}{{ end }} - # use zip for windows archives - format_overrides: - - goos: windows - format: zip brews: - name: kubectl-debug-pdb ids: @@ -87,19 +57,6 @@ brews: branch: main pull_request: enabled: true - - name: kubectl-evict - ids: - - kubectl-evict - folder: Formula - homepage: "https://github.com/dhenkel92/kubectl-debug-pdb" - license: "MIT" - repository: - owner: dhenkel92 - name: homebrew-tap - branch: main - pull_request: - enabled: true - checksum: name_template: 'checksums.txt' snapshot: diff --git a/README.md b/README.md index 4b56ed7..434f5b8 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,6 @@

- - - - -

Kubectl PDB & Eviction plugin

+

Kubectl debug PDB plugin

A kubectl plugin to work with pod disruption budgets. @@ -49,15 +45,12 @@ To get a local copy up and running follow these simple example steps. You can install the tool via Homebrew and the tap repository can be found [here.](https://github.com/dhenkel92/homebrew-tap) ``` -brew update -brew install dhenkel92/homebrew-tap/kubectl-debug-pdb -brew install dhenkel92/homebrew-tap/kubectl-evict +brew update && brew install dhenkel92/homebrew-tap/kubectl-debug-pdb ``` In order to get a newer version, just upgrade via Homebrew ``` -brew upgrade kubectl-debug-pdb -brew upgrade kubectl-evict +brew update && brew upgrade dhenkel92/homebrew-tap/kubectl-debug-pdb ``` ### Other distributions @@ -66,19 +59,18 @@ See the [Releases page](https://github.com/dhenkel92/kubectl-debug-pdb/releases) ## Usage -### Kubectl pdb - ``` Utility to work with pod disruption budgets Usage: - pdb [command] + debug-pdb [command] Available Commands: completion Generate the autocompletion script for the specified shell cover Shows which PDBs are a workload. create Create a new PDB for a given workload. help Help about any command + pod Utility to evict a pod from a node pods List pods covered by a given PDB Flags: @@ -92,7 +84,7 @@ Flags: --cluster string The name of the kubeconfig cluster to use --context string The name of the kubeconfig context to use --disable-compression If true, opt-out of response compression for all requests to the server - -h, --help help for pdb + -h, --help help for debug-pdb --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure --kubeconfig string Path to the kubeconfig file to use for CLI requests. -n, --namespace string If present, the namespace scope for this CLI request @@ -102,66 +94,32 @@ Flags: --token string Bearer token for authentication to the API server --user string The name of the kubeconfig user to use -Use "pdb [command] --help" for more information about a command. +Use "debug-pdb [command] --help" for more information about a command. ``` List all pods for a given PDB: ``` -kubectl pdb pods +kubectl debug-pdb pods ``` List all PDBs for all pods of a namespace: ``` -kubectl pdb cover -n [pod_name] +kubectl debug-pdb cover -n [pod_name] ``` Create new PDB: ``` -kubectl pdb create / --dry-run -o yaml -``` - -### Kubectl evict - -``` -Utility to evict a pod from a node - -Usage: - evict pod [flags] - -Flags: - --dry-run If true, only print the object that would be sent, without sending it. (default true) - -h, --help help for pod - -o, --output string Output format. One of: json|yaml (default "json") - -Global Flags: - --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. - --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --as-uid string UID to impersonate for the operation. - --cache-dir string Default cache directory (default "/Users/daniel.henkel/.kube/cache") - --certificate-authority string Path to a cert file for the certificate authority - --client-certificate string Path to a client certificate file for TLS - --client-key string Path to a client key file for TLS - --cluster string The name of the kubeconfig cluster to use - --context string The name of the kubeconfig context to use - --disable-compression If true, opt-out of response compression for all requests to the server - --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure - --kubeconfig string Path to the kubeconfig file to use for CLI requests. - -n, --namespace string If present, the namespace scope for this CLI request - --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") - -s, --server string The address and port of the Kubernetes API server - --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used - --token string Bearer token for authentication to the API server - --user string The name of the kubeconfig user to use +kubectl debug-pdb create / --dry-run -o yaml ``` Evict a pod in dry-run mode (Default: true): ``` -kubectl evict pod [-n ] +kubectl debug-pdb pod [-n ] ``` Trigger real pod eviction: ``` -kubectl evict pod [-n ] --dry-run=false +kubectl debug-pdb pod [-n ] --dry-run=false ``` ## Contributing diff --git a/cmd/kubectl-debug-pdb/kubectl-debug-pdb.go b/cmd/kubectl-debug-pdb/kubectl-debug-pdb.go index 0c73338..902bfff 100644 --- a/cmd/kubectl-debug-pdb/kubectl-debug-pdb.go +++ b/cmd/kubectl-debug-pdb/kubectl-debug-pdb.go @@ -28,6 +28,7 @@ func main() { rootCmd.AddCommand(cmd.NewCmdPdb(streams, conf)) rootCmd.AddCommand(cmd.NewCmdCreatePDB(streams, conf)) rootCmd.AddCommand(cmd.NewCmdPods(streams, conf)) + rootCmd.AddCommand(cmd.NewCmdEvictPod(streams, conf)) if err := rootCmd.Execute(); err != nil { os.Exit(1) diff --git a/cmd/kubectl-evict/kubectl-evict.go b/cmd/kubectl-evict/kubectl-evict.go deleted file mode 100644 index abcbb11..0000000 --- a/cmd/kubectl-evict/kubectl-evict.go +++ /dev/null @@ -1,33 +0,0 @@ -package main - -import ( - "os" - - "github.com/dhenkel92/kubectl-debug-pdb/pkg/cmd" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "k8s.io/cli-runtime/pkg/genericclioptions" - - // https://krew.sigs.k8s.io/docs/developer-guide/develop/best-practices/ - _ "k8s.io/client-go/plugin/pkg/client/auth" -) - -func main() { - flags := pflag.NewFlagSet("kubectl-evict", pflag.ExitOnError) - pflag.CommandLine = flags - - conf := genericclioptions.NewConfigFlags(true) - conf.AddFlags(flags) - - streams := genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr} - - rootCmd := &cobra.Command{ - Use: "evict", - Short: "Utility to evict a pod from a node", - } - rootCmd.AddCommand(cmd.NewCmdEvictPod(streams, conf)) - - if err := rootCmd.Execute(); err != nil { - os.Exit(1) - } -} diff --git a/pkg/cmd/evict_pod.go b/pkg/cmd/evict_pod.go index ba11b2c..82316e9 100644 --- a/pkg/cmd/evict_pod.go +++ b/pkg/cmd/evict_pod.go @@ -37,7 +37,7 @@ func NewCmdEvictPod(streams genericclioptions.IOStreams, configFlags *genericcli o := NewEvictPodOptions(streams, configFlags) cmd := &cobra.Command{ - Use: "pod ", + Use: "evict ", Short: "Utility to evict a pod from a node", RunE: func(cmd *cobra.Command, args []string) error { if err := o.Complete(cmd, args); err != nil {