get-ix-pods feature complete

This commit is contained in:
Lockszmith 2023-11-17 12:09:57 -05:00
parent 3e8d024eda
commit 64972fc3b2
2 changed files with 65 additions and 14 deletions

View File

@ -1,14 +0,0 @@
#! /usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
USER_HOME=$HOME
[[ -n "${SUDO_USER}" ]] && USER_HOME="$(eval "echo ~${SUDO_USER}")"
. ${SHRC_D:-$SCRIPT_DIR}/01_util.functions
set -e
k3s kubectl pods --namespace ix -s Ready \
| sed 1d | grep -v svclb- \
| sed -E 's/[[:space:]]([0-9]*|About)[a-z0-9 ]{5,12}ago[[:space:]]//' \
| awk '{ print $4 }' \
| sed 's/^ix-//' | sort -u

65
get-ix-pods Executable file
View File

@ -0,0 +1,65 @@
#! /usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
USER_HOME=$HOME
[[ -n "${SUDO_USER}" ]] && USER_HOME="$(eval "echo ~${SUDO_USER}")"
. ${SHRC_D:-$SCRIPT_DIR}/01_util.functions
set -e
get-apps() {
k3s kubectl get --all-namespaces deployments.apps --sort-by='.metadata.namespace' "${@}"
}
FILTER=('')
ARG="${1:---all}"
if [[ -n "$ARG" ]]; then
if [[ "$ARG" =~ ^-(a|-active)$ ]]; then
FILTER=(-v '\b0/0\b')
elif [[ "$ARG" =~ ^-(r|-ready)$ ]]; then
FILTER=('\b([1-9]\d*)/\1\b')
elif [[ "$ARG" =~ ^-(l|-limbo)$ ]]; then
FILTER=('\b([0-9]+)/(?!\1)([1-9][0-9]*)\b')
elif [[ "$ARG" =~ ^-(s|-stop|-stopped)$ ]]; then
FILTER=('\b0/0\b')
elif [[ "$ARG" =~ ^(-h|-?|/h|/?|--help)$ ]]; then
printf '%s\n' \
'Usage:' \
" $(basename "$0") <args>" \
'' \
' Default behavior will list all apps' \
'' \
'Arguments:' \
' -h | --help Display this help/usage message' \
' -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'
exit 0
elif [[ ! "$ARG" =~ ^(-A|--all)$ ]]; then
printf '%s\n' \
"Invalid argument: $ARG" \
>&2
exit 1
fi
fi
APPS="$(get-apps)"
HEADER="$(head -n1 <<<"$APPS")"
APPS="$(tail +1 <<<"$APPS")"
APPS="$(
grep -E --color=no "$(
get-apps --output=json | jq -r '
[.items[]
| select( .metadata.labels."app.kubernetes.io/managed-by" == "Helm" )
| .metadata.namespace]
| join( "|" )
'
)" <<<"$APPS" \
| grep -P "${FILTER[@]}"
)"
echo "$HEADER"
echo "$APPS"