get-ix-pods scripting support added
This commit is contained in:
parent
64972fc3b2
commit
e179df0b48
56
get-ix-pods
56
get-ix-pods
|
@ -10,41 +10,63 @@ get-apps() {
|
|||
k3s kubectl get --all-namespaces deployments.apps --sort-by='.metadata.namespace' "${@}"
|
||||
}
|
||||
|
||||
FILTER=('')
|
||||
FILTER1=('')
|
||||
FILTER2=()
|
||||
OUTPUT=()
|
||||
|
||||
ARG="${1:---all}"
|
||||
while [[ -n "$1" ]]; do
|
||||
ARG="${1}"
|
||||
shift
|
||||
|
||||
if [[ -n "$ARG" ]]; then
|
||||
if [[ "$ARG" =~ ^-(a|-active)$ ]]; then
|
||||
FILTER=(-v '\b0/0\b')
|
||||
if [[ "${#OUTPUT[@]}" -eq 0 && "$ARG" =~ ^-(N|name|names-only)$ ]]; then
|
||||
OUTPUT=(awk "'{print \$1;}'" \| sort --unique)
|
||||
elif [[ "${#OUTPUT[@]}" -eq 0 && "$ARG" =~ ^-Nx$ ]]; then
|
||||
OUTPUT=(awk "'{print \$1;}'" \| sed -e "'s|^ix-||'" \| sort --unique)
|
||||
elif [[ "${#OUTPUT[@]}" -eq 0 && "$ARG" =~ ^-(H|(no-?)(head(e(r(s)?)?)?))$ ]]; then
|
||||
OUTPUT=('grep' '.')
|
||||
elif [[ -z "${FILTER1[*]}" && "$ARG" =~ ^- ]]; then
|
||||
if [[ "$ARG" =~ ^(-A|--all)$ ]]; then
|
||||
FILTER1=('.')
|
||||
elif [[ "$ARG" =~ ^-(a|-active)$ ]]; then
|
||||
FILTER1=(-v '\b0/0\b')
|
||||
elif [[ "$ARG" =~ ^-(r|-ready)$ ]]; then
|
||||
FILTER=('\b([1-9]\d*)/\1\b')
|
||||
FILTER1=('\b([1-9]\d*)/\1\b')
|
||||
elif [[ "$ARG" =~ ^-(l|-limbo)$ ]]; then
|
||||
FILTER=('\b([0-9]+)/(?!\1)([1-9][0-9]*)\b')
|
||||
FILTER1=('\b([0-9]+)/(?!\1)([1-9][0-9]*)\b')
|
||||
elif [[ "$ARG" =~ ^-(s|-stop|-stopped)$ ]]; then
|
||||
FILTER=('\b0/0\b')
|
||||
FILTER1=('\b0/0\b')
|
||||
elif [[ "$ARG" =~ ^(-h|-?|/h|/?|--help)$ ]]; then
|
||||
printf '%s\n' \
|
||||
'Usage:' \
|
||||
" $(basename "$0") <args>" \
|
||||
" $(basename "$0") <args> [grep -P filter]" \
|
||||
'' \
|
||||
' Default behavior will list all apps' \
|
||||
'' \
|
||||
'Arguments:' \
|
||||
' -h | --help Display this help/usage message' \
|
||||
'' \
|
||||
'Filters:' \
|
||||
' -A | --all (default) List all apps' \
|
||||
' -a | --active List all active (non-stopped) apps' \
|
||||
' -r | --ready List all active apps in ready state' \
|
||||
' -s | --stopped List all apps in stopped state' \
|
||||
' -l | --limbo List all active apps not in ready state'
|
||||
' -l | --limbo List all active apps not in ready state' \
|
||||
'' \
|
||||
'Output:' \
|
||||
' -N | --names-only App names only' \
|
||||
' -Nx App names only with "ix-" prefix removed' \
|
||||
' -H | --no-headers No headers'
|
||||
exit 0
|
||||
elif [[ ! "$ARG" =~ ^(-A|--all)$ ]]; then
|
||||
else
|
||||
printf '%s\n' \
|
||||
"Invalid argument: $ARG" \
|
||||
>&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
FILTER2=("${FILTER2[@]}" "$ARG")
|
||||
fi
|
||||
done
|
||||
|
||||
APPS="$(get-apps)"
|
||||
HEADER="$(head -n1 <<<"$APPS")"
|
||||
|
@ -58,8 +80,12 @@ APPS="$(
|
|||
| join( "|" )
|
||||
'
|
||||
)" <<<"$APPS" \
|
||||
| grep -P "${FILTER[@]}"
|
||||
| grep -P "${FILTER1[@]}" \
|
||||
| grep -P "${FILTER2[@]:-.}"
|
||||
)"
|
||||
echo "$HEADER"
|
||||
echo "$APPS"
|
||||
if [[ "${#OUTPUT[@]}" -le 1 ]]; then
|
||||
echo "$HEADER"
|
||||
fi
|
||||
echo "$APPS" \
|
||||
| eval "${OUTPUT[*]:-grep .}"
|
||||
|
||||
|
|
Loading…
Reference in New Issue