-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheck_deployments_1.sh
executable file
·128 lines (72 loc) · 3.43 KB
/
eck_deployments_1.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env bash
# count of array
count=`jq '.items | length' "${1}"`
if [ ${count} = 0 ]; then
exit
fi
echo "========================================================================================="
echo "Summary"
echo "========================================================================================="
echo ""
jq -r '
[.items
| sort_by(.metdata.name)[]
| {
"NAME": (.metadata.name // "-"),
"READY": ((.status.readyReplicas|tostring) + "/" + (.status.replicas|tostring) // "-"),
"UP-TO-DATE": (.status.updatedReplicas|tostring // "-"),
"AVAILABLE": (.status.availableReplicas // "-"),
"CONTAINERS": ([.spec.template.spec.containers[].name]|join(",") // "-"),
"APIVERSION": (.metadata.ownerReferences[] | select(.controller==true) |.apiVersion // "-"),
"OWNER": (.metadata.ownerReferences[] | select(.controller==true) |.kind + "/" + .name // "-"),
"IMAGES": ([.spec.template.spec.containers[].image]|join(",") // "-"),
"CREATION TIME": (.metadata.creationTimestamp // "-")
}]| (.[0] |keys_unsorted | @tsv),(.[]|.|map(.) |@tsv)' "${1}" 2>/dev/null | column -ts $'\t'
echo ""
echo "========================================================================================="
echo "Conditions"
echo "========================================================================================="
echo ""
jq -r '
[.items
| sort_by(.metdata.name)[]
| {
"NAME": (.metadata.name // "-"),
"AVAIL REPLICAS": (.status.availableReplicas // "-"),
"AVAIL TIME": (.status.conditions[] | select(.type=="Available") | .lastUpdateTime // "-"),
"MESSAGE": (.status.conditions[] | select(.type=="Available") | .message // "-")
}]| (.[0] |keys_unsorted | @tsv),(.[]|.|map(.) |@tsv)' "${1}" 2>/dev/null | column -ts $'\t'
echo ""
echo "========================================================================================="
echo "SPEC"
echo "========================================================================================="
echo ""
# FIX - need to find a way to use update strategy to get update details
jq -r '
[.items
| sort_by(.metdata.name)[]
| {
"NAME": (.metadata.name // "-"),
"REPLICAS": (.spec.replicas|tostring // "-"),
"UPDATE STRATEGY": (.spec.strategy.type // "-"),
"ROLLINGUPDATE": ([(.spec.strategy.rollingUpdate|to_entries[] | "\(.key)=\(.value)")] | join(",") // "-"),
"SELECTOR": ([(.spec.selector.matchLabels)| (to_entries[] | "\(.key)=\(.value)")] | join(",") // "-")
}]| (.[0] |keys_unsorted | @tsv),(.[]|.|map(.) |@tsv)' "${1}" 2>/dev/null | column -ts $'\t'
echo ""
echo "========================================================================================="
echo "Labels & Annotations"
echo "========================================================================================="
echo ""
for ((i=0; i<$count; i++))
do
item=`jq -r '.items['${i}'].metadata.name' "${1}"`
echo "==== ${item} ----------------------------------------------------------------------------"
echo ""
echo "== Annotations:"
#jq -r '.items['${i}'].metadata.annotations | to_entries | .[] | "* \(.key)",(.value | if try fromjson catch false then fromjson else . end)," "' "${1}" 2>/dev/null
jq -r '.items['${i}'].metadata.annotations | (to_entries[] | "\(.key)=\(.value)")' "${1}" 2>/dev/null
echo ""
echo "== Labels:"
jq -r '.items['${i}'].metadata.labels | (to_entries[] | "\(.key)=\(.value)") | select(length >0)' "${1}" 2>/dev/null
echo ""
done