64 lines
1.4 KiB
Bash
Executable File
64 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
source .utils
|
|
|
|
NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}' &>/dev/null)"
|
|
set -e
|
|
NAMESPACE=${NAMESPACE:-default}
|
|
LABEL=""
|
|
ALL_NAMESPACES=false
|
|
|
|
print_usage() {
|
|
blue "kube-all - A better 'kubectl get all' - actually get all Kubernetes resources, including custom resources"
|
|
echo " "
|
|
underline "Usage:"
|
|
echo "kube-all [options]"
|
|
echo " "
|
|
underline "Options:"
|
|
echo "-h, --help show this help text"
|
|
echo "-n, --namespace the namespace the to search in"
|
|
echo "-l, --selector the label selector to match on"
|
|
echo "-A, --all-namespaces match resources in all namespaces (default: false)"
|
|
}
|
|
|
|
while test $# -gt 0; do
|
|
case "$1" in
|
|
-n|--namespace)
|
|
shift
|
|
NAMESPACE=$1
|
|
shift
|
|
;;
|
|
-l|--selector)
|
|
shift
|
|
LABEL=$1
|
|
shift
|
|
;;
|
|
-A|--all-namespaces)
|
|
ALL_NAMESPACES=true
|
|
shift
|
|
;;
|
|
-h|--help)
|
|
print_usage
|
|
exit 0
|
|
;;
|
|
*)
|
|
break
|
|
;;
|
|
esac
|
|
done
|
|
|
|
NAMESPACED="--namespaced"
|
|
|
|
if [[ "${LABEL}" != "" ]]; then
|
|
LABEL="-l ${LABEL}"
|
|
NAMESPACED=""
|
|
fi
|
|
|
|
NAMES="$(kubectl api-resources ${NAMESPACED} --verbs list -o name | tr '\n' ,)"
|
|
|
|
if [[ "$ALL_NAMESPACES" == "true" ]]; then
|
|
kubectl get "${NAMES::${#NAMES}-1}" --show-kind --ignore-not-found ${LABEL} -A 2>/dev/null
|
|
else
|
|
kubectl get "${NAMES::${#NAMES}-1}" --show-kind --ignore-not-found ${LABEL} -n ${NAMESPACE} 2>/dev/null
|
|
fi
|