Created
May 10, 2022 07:57
-
-
Save reneluria/4b9999a70505e201f1219b5bb592889e to your computer and use it in GitHub Desktop.
kubectl plugin to list failed pods
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
#!/bin/bash | |
usage() { | |
echo "Usage: $0 [-A|-n <namespace>]" | |
echo " -A : act on all namespaces" | |
echo " -n <namespace>: pods for namespace <namespace>" | |
} | |
all=0 | |
namespace= | |
while getopts "hAn:" OPTION; do | |
case "$OPTION" in | |
h) | |
usage | |
exit 0 | |
;; | |
A) | |
all=1 | |
;; | |
n) | |
namespace="$OPTARG" | |
;; | |
*) | |
echo "Error: bad arguments" >&2 | |
exit 1 | |
;; | |
esac | |
done | |
shift $((OPTIND - 1)) | |
args="-o wide" | |
if [[ $all -eq 1 ]]; then | |
args="$args -A" | |
elif [[ -n $namespace ]]; then | |
args="$args -n $namespace" | |
fi | |
# shellcheck disable=SC2086 # we want splitting for $args | |
kubectl get pod --field-selector 'status.phase==Failed' $args |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment