Files
dotfiles/dot_config/quickshell/scripts/executable_k8s-status.sh

23 lines
624 B
Bash
Executable File

#!/usr/bin/env bash
# Outputs pod ready status for a namespace as JSON.
# Usage: k8s-status.sh <namespace>
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)
}
'