commit 0e14810de9042ea249608b8e95f17dab9f674800
| author | 斟酌 鵬兄 <tgckpg@gmail.com> |
| date | 2026-09-25T14:22:59Z |
| subject | Added kviz |
commit 0e14810de9042ea249608b8e95f17dab9f674800
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date: 2026-09-25T14:22:59Z
Added kviz
---
bash/dist/rbashrc | 2 +-
bash/dist/rbashrc.asc | 10 +++---
bash/dist/sources.list | 2 +-
bash/sources/19_k8s_funcs | 77 +++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 84 insertions(+), 7 deletions(-)
diff --git a/bash/dist/rbashrc b/bash/dist/rbashrc
index 45a0a66..0be6ab2 100755
--- a/bash/dist/rbashrc
+++ b/bash/dist/rbashrc
@@ -18,7 +18,7 @@ RBASH_CONFIG="$RBASH_HOME/config"
RBASH_ENV="$RBASH_HOME/env"
RBASH_MERGED="$RBASH_CACHE_DIR/merged"
RBASH_BIN="$RBASH_HOME/bin"
-RBASH_SOURCES_SUM="3cbdee204a161551890fa580a5d7f8eddc749afe7aa1579606b4a31f77d8d432"
+RBASH_SOURCES_SUM="f6f558d9b40551d7789cbc11397a691104eaba5bb726cdee6b1394aad622891a"
# ---- rbash: bash/core/00_env.bash ----
diff --git a/bash/dist/rbashrc.asc b/bash/dist/rbashrc.asc
index b6a86da..83c7550 100644
--- a/bash/dist/rbashrc.asc
+++ b/bash/dist/rbashrc.asc
@@ -1,8 +1,8 @@
-----BEGIN PGP SIGNATURE-----
-iJEEABYKADkWIQR8HpSNhBJUxWnt+97Vz1+xz60nwwUCarCfmBsUgAAAAAAEAA5t
-YW51MiwyLjUrMS4xMiwwLDMACgkQ1c9fsc+tJ8M8zgD/T8V3I2yCBC2jlNykolCq
-HXlm/IS+9iTzDo+JwjW65hwA/R4K6JWzC6AjSdD1oXoVgIHMEC0NeoM/04yzYtk/
-t00A
-=/r4G
+iJEEABYKADkWIQR8HpSNhBJUxWnt+97Vz1+xz60nwwUCaraDtBsUgAAAAAAEAA5t
+YW51MiwyLjUrMS4xMiwwLDMACgkQ1c9fsc+tJ8MsVgD/TyLRQbyCkIcQDkF6ViEr
+OABublP9LDCALn7Sbirnaz0A/RHS83lRPFprFWRPZEAtNGX41fp/pd0D3d7hL+aj
+3IIB
+=h0Wm
-----END PGP SIGNATURE-----
diff --git a/bash/dist/sources.list b/bash/dist/sources.list
index 5399dde..69b8059 100644
--- a/bash/dist/sources.list
+++ b/bash/dist/sources.list
@@ -6,7 +6,7 @@ a0d62f10f39fa988d8ff8ce13a1751488e6bad1662c3b97ab8ef3fa09c702666 sources/15_gpg
6699650f7a08fd6c5f98a234f60ff60f39a640aeea89bb4e57ebab13c1d91a66 sources/16_keystore
570a67928ad4eb2ae343ebc3eee39413989087388fe35e0cd675573add6730b0 sources/17_kcontext
f45e3d068475a40b838336f675948d07b544967d03fbf491abd70e131db38fb0 sources/18_kotp
-7ce7ab97af4aa3f6681981d0d2f687b3eb9b7e7beda5e3b74b651210f7c6fac9 sources/19_k8s_funcs
+3b5e18ded2470999571a8d327837343877f141ad14f9ef13731ec7084239ad52 sources/19_k8s_funcs
60c468b70dbcfa2d198362b90278e4a5e86fb1784c85e846402527df7406774d sources/21_win-greps
e007fe16e8ed65c5dca0effcd7227ed52008ca42fe3b6f1b7344a685c17ac02f sources/22_win-setups
b5a488efc0558e2b795a1558e2c91a8aeecc3fd441d437aff3a4749d5eb0bdfc sources/23_win-binaries
diff --git a/bash/sources/19_k8s_funcs b/bash/sources/19_k8s_funcs
index 5012cca..5b32674 100644
--- a/bash/sources/19_k8s_funcs
+++ b/bash/sources/19_k8s_funcs
@@ -345,3 +345,80 @@ function kcreate {
return "$rc"
}
+
+function kviz {
+ local tmp pods_json nodes_json
+ local node instance_type cpu mem tree pod status
+ local -a pods
+
+ tmp=$(mktemp) || return
+ trap 'rm -f "$tmp"' RETURN
+
+ cat > "$tmp"
+
+ pods_json=$(cat "$tmp") || return
+ nodes_json=$(kubectl get nodes -o json) || return
+
+ mapfile -t nodes < <(
+ jq -r '
+ .items[]
+ | .spec.nodeName // empty
+ ' <<< "$pods_json" |
+ sort -u
+ )
+
+ if [ ${#nodes[@]} -eq 0 ]; then
+ echo "No scheduled pods found."
+ return
+ fi
+
+ for node in "${nodes[@]}"; do
+ read -r instance_type cpu mem < <(
+ jq -r --arg node "$node" '
+ .items[]
+ | select(.metadata.name == $node)
+ | [
+ (
+ .metadata.labels["node.kubernetes.io/instance-type"]
+ // .metadata.labels["beta.kubernetes.io/instance-type"]
+ // "-"
+ ),
+ (.status.allocatable.cpu // "-"),
+ (.status.allocatable.memory // "-")
+ ]
+ | @tsv
+ ' <<< "$nodes_json"
+ )
+
+ printf '\033[1;36m%s\033[0m\n' "$node"
+ printf ' %-16s cpu: %-8s mem: %s\n' \
+ "$instance_type" "$cpu" "$mem"
+
+ mapfile -t pods < <(
+ jq -r --arg node "$node" '
+ .items[]
+ | select(.spec.nodeName == $node)
+ | [
+ .metadata.name,
+ .status.phase
+ ]
+ | @tsv
+ ' <<< "$pods_json"
+ )
+
+ for ((i = 0; i < ${#pods[@]}; i++)); do
+ IFS=$'\t' read -r pod status <<< "${pods[$i]}"
+
+ if (( i == ${#pods[@]} - 1 )); then
+ tree="└─"
+ else
+ tree="├─"
+ fi
+
+ printf ' %s %-45s %s\n' \
+ "$tree" "$pod" "$status"
+ done
+
+ echo
+ done
+}