-
Notifications
You must be signed in to change notification settings - Fork 420
/
ir_k8s_failover_ci.sh
executable file
·63 lines (53 loc) · 1.84 KB
/
ir_k8s_failover_ci.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
#!/bin/bash
# usage: ./ir_k8s_failover_ci.sh default test-graphscope-store 2 1
function rand(){
min=$1
max=$(($2 - $min + 1))
num=$(($RANDOM+1000000000))
echo $(($num%$max + $min))
}
function get_role_pods_to_kill() {
role=$1
role_total=$2
kill_total=$((role_total/2+1))
entries=($(shuf -i 0-$((role_total-1)) -n ${kill_total}))
for i in "${entries[@]}"
do
kill_pods=${kill_pods}' '${role_prefix}'-'${role}'-'$i
done
echo ${kill_pods}
}
function wait_role_pods_to_run() {
role=$1
role_total=$2
while [ 1 ]
do
cnt=$(kubectl --namespace=${namespace} get pod -l "app.kubernetes.io/component=${role}" --field-selector=status.phase==Running 2> /dev/null | wc -l)
if [[ $? == 0 && $cnt > ${role_total} ]];then
break
fi
echo "keep waiting for all pods are running ..."
done
}
namespace=$1
role_prefix=$2
store_total=$3
frontend_total=$4
wait_role_pods_to_run store ${store_total}
wait_role_pods_to_run frontend ${frontend_total}
# random kill executor
kubectl --namespace=${namespace} delete pod $(get_role_pods_to_kill store ${store_total})
wait_role_pods_to_run store ${store_total}
sleep 5
node_port=$(kubectl --namespace=${namespace} get svc ${role_prefix}-frontend -o go-template='{{range.spec.ports}}{{if .nodePort}}{{.nodePort}}{{"\n"}}{{end}}{{end}}' | head -1)
hostname=$(minikube ip)
python3 ./submit_query.py $hostname:${node_port}
## random kill frontend
#kubectl --namespace=${namespace} delete pod $(get_role_pods_to_kill frontend ${frontend_total})
#wait_role_pods_to_run frontend ${frontend_total}
#
#sleep 5
#
#node_port=$(kubectl --namespace=${namespace} get svc ${role_prefix}-frontend -o go-template='{{range.spec.ports}}{{if .nodePort}}{{.nodePort}}{{"\n"}}{{end}}{{end}}')
#hostname=$(hostname -i)
#python3 ./submit_query.py $hostname:${node_port}