k8s-widget: add k8s-status.sh
This commit is contained in:
22
dot_config/quickshell/scripts/executable_k8s-status.sh
Executable file
22
dot_config/quickshell/scripts/executable_k8s-status.sh
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/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)
|
||||
}
|
||||
'
|
||||
Reference in New Issue
Block a user