Last active
August 10, 2020 22:59
-
-
Save ezhuravlev/1646ab9b553942b211f82b0d8b412041 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -o errexit | |
#: ${1?"Usage: $0 <NODE>"} | |
[[ "$1" = "--help" ]] && echo "Usage: $0 <NODE>" && exit 0 | |
NODE=$1 | |
JQ_TEMPLATE=" | |
[ | |
.items[] as \$items | |
| \$items.spec.containers[] as \$containers | |
| \$items | |
" | |
[[ ! -z "$NODE" ]] && JQ_TEMPLATE+=" | select(.spec.nodeName==\"$NODE\")" | |
JQ_TEMPLATE+=" | |
| del(.spec.containers) as \$containers2 | |
| \$containers * \$containers2 | |
| { | |
node: .spec.nodeName, | |
ns: .metadata.namespace, | |
name: .metadata.name, | |
image: .image, | |
cpu: ((.resources.requests.cpu // \"---\") + \"/\" + (.resources.limits.cpu // \"---\")), | |
mem: ((.resources.requests.memory // \"---\") + \"/\" + (.resources.limits.memory // \"---\")) | |
} | |
] | |
| [.[]| with_entries( .key |= ascii_upcase ) ] | |
| (.[0] |keys_unsorted | @tsv) # print headers | |
, (.[]|.|map(.) |@tsv) # print table | |
" | |
kubectl get po -A -o json | jq -r "$JQ_TEMPLATE" | column -t | awk -v bld=$(tput bold) -v rst=$(tput sgr0) 'NR == 1{$0 = bld$0rst} 1' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment