Skip to content

Golang CLI tool that can be used to purge k8s jobs that have completed

License

Notifications You must be signed in to change notification settings

azharullah/purge-k8s-jobs-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Purge-k8s-jobs-cli

CII Best Practices Go Report Card

Purge-k8s-jobs-cli is a cobra based CLI wrapper over the purgek8sjobs package.

Why purge-k8s-jobs-cli?

This utility provides a command line tool based interface to the purgek8sjobs, which would be the most appropriate way to consume the package.

The reasons to why anyone might want use this tool are mentioned here

Usage

The docker image with the tool's binary is available here

Kubernetes deployment via helm

A helm chart is available to enable easy deployment to k8s clusters.

helm upgrade --install purge-k8s-jobs helm

As a standalone CLI tool

The binary is available as a release artifact here

To build a binary from source:

make build  # For OSX
make build-linux  # For Linux
make build-linux BINARYNAME=xyz  # For custom binary names

CLI usage

For command help text:

./bin/purge-k8s-jobs-cli-v0.1.0 -h
This utility helps purge all kubernetes jobs that have completed their execution more than `b` hours ago in the namespace `n`. Optionally, this also write the job spec and events to a provided log file path

Usage:
  purge-completed-k8s-jobs --namespace xyz --before-hours 5 --events-log-file=./events.txt --spec-log-file=./spec.txt

Flags:
  -b, --before-hours int16       Query and delete jobs that were complete before x hours (default 1)
  -e, --events-log-file string   Log file to write the job events to
  -h, --help                     help for purge-completed-k8s-jobs
  -n, --namespace string         Namespace in which the operations are to be performed (default "default")
  -s, --spec-log-file string     Log file to write the job spec to

To use kubeconfig file for authentication:

export KUBECONFIG=~/.kube/config
purge-completed-k8s-jobs-v0.1.0 --namespace xyz --before-hours 0 \
    --events-log-file=./events.txt --spec-log-file=./spec.txt

To set custom log levels: (The default log level is debug )

export LOG_LEVEL=warn
purge-completed-k8s-jobs-v0.1.0 --namespace xyz --before-hours 0 \
    --events-log-file=./events.txt --spec-log-file=./spec.txt