-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-resources-limits.sh
More file actions
executable file
·63 lines (53 loc) · 2.34 KB
/
get-resources-limits.sh
File metadata and controls
executable file
·63 lines (53 loc) · 2.34 KB
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
#!/bin/bash
function output() {
local res_limit=$1
local version=$2
echo "In version \`$version\`" >> $resourcelimit_output
echo >> $resourcelimit_output
echo '```yaml' >> $resourcelimit_output
echo "$res_limit" >> $resourcelimit_output
echo '```' >> $resourcelimit_output
echo >> $resourcelimit_output
}
function switch_env_to () {
local env_ctx=$1
oc config use-context $env_ctx &>/dev/null
}
# Support resource type: Deployment, DaemonSet and StatefulSet
function get_res_limit() {
local res_type=$1
switch_env_to $env_ctx_1
env_1_res_names=$(oc -n $namespace --no-headers=true get $res_type | awk '{print $1}')
switch_env_to $env_ctx_2
env_2_res_names=$(oc -n $namespace --no-headers=true get $res_type | awk '{print $1}')
res_names=$(echo "$env_1_res_names $env_2_res_names" | sort -n | uniq)
echo "## Compare $res_type resources limit in version $env_version_1 and $env_version_2" >> $resourcelimit_output
echo >> $resourcelimit_output
for res_name in $(echo "$res_names");
do
switch_env_to $env_ctx_1
env_1_res_limit=$(oc -n $namespace get $res_type $res_name -ojson | jq '.spec.template.spec' | jq '.initContainers[]?, .containers[]? | {container: .name, resources: .resources}' | yq r -P - 2>/dev/null)
switch_env_to $env_ctx_2
env_2_res_limit=$(oc -n $namespace get $res_type $res_name -ojson | jq '.spec.template.spec' | jq '.initContainers[]?, .containers[]? | {container: .name, resources: .resources}' | yq r -P - 2>/dev/null)
[[ "$env_1_res_limit" == "$env_2_res_limit" ]] && continue
echo "### $res_type \`$res_name\` resource limits" >> $resourcelimit_output
echo >> $resourcelimit_output
output "$env_1_res_limit" "$env_version_1"
output "$env_2_res_limit" "$env_version_2"
done
}
#--------------------------------- Main ---------------------------------#
resourcelimit_output=resourcelimit_output.md
namespace=ibm-common-services
ctx_1="default/api-stemma-cp-fyre-ibm-com:6443/kube:admin"
ctx_2="default/api-xl-odlm-test-cp-fyre-ibm-com:6443/kube:admin"
env_ctx_1=$ctx_1
env_ctx_2=$ctx_2
env_version_1=1.1
env_version_2=1.2
[[ -f ./$resourcelimit_output ]] && >$resourcelimit_output
echo "# Compare Resource Limit in Different Common Services Version" >>$resourcelimit_output
echo >>$resourcelimit_output
get_res_limit "Deployment"
get_res_limit "DaemonSet"
get_res_limit "StatefulSet"