get-ix-pods scripting support added

This commit is contained in:
Lockszmith 2023-11-17 12:55:18 -05:00
parent 64972fc3b2
commit e179df0b48
1 changed files with 61 additions and 35 deletions

View File

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