diff --git a/dot_config/quickshell/scripts/executable_k8s-status.sh b/dot_config/quickshell/scripts/executable_k8s-status.sh new file mode 100755 index 0000000..183a952 --- /dev/null +++ b/dot_config/quickshell/scripts/executable_k8s-status.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# Outputs pod ready status for a namespace as JSON. +# Usage: k8s-status.sh +set -euo pipefail + +NS="${1:-tenant-5}" + +pods_json=$(kubectl get pods -n "$NS" -o json 2>/dev/null) || exit 0 + +echo "$pods_json" | jq -c ' + [.items[] | { + app: (.metadata.labels["app.kubernetes.io/instance"] // .metadata.name), + ready: ((.status.conditions // []) + | map(select(.type == "Ready")) + | if length > 0 then .[0].status == "True" else false end) + }] as $pods | + { + pods: $pods, + readyCount: ($pods | map(select(.ready)) | length), + totalCount: ($pods | length) + } +'