forked from oceanbase/ob-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_P0_cluster02_serverExpan.sh
executable file
·111 lines (100 loc) · 3.71 KB
/
check_P0_cluster02_serverExpan.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
# load all the parameters in setup.sh
source setup.sh
source util.sh
source env.sh
source case_p0_ClusterAndTenant/env_vars.sh
prepare() {
kubectl create namespace $NAMESPACE
create_pass_secret $NAMESPACE $OB_ROOT_SECRET $PASSWORD
echo $PASSWORD
}
# clean up delete everything by deleting the entire namespace
cleanup() {
kubectl delete namespace $NAMESPACE
}
run() {
local template_file=$1
echo $OBCLUSTER_NAME
envsubst < ./config/clusterManage/$template_file | kubectl apply -f -
}
check_resource_running() {
local suffix=$1
counter=0
timeout=100
RESOURCE_RUNNING='false'
while true; do
echo 'check resource'
counter=$((counter+1))
pod_1_zone1=`kubectl get pod -o wide -n $NAMESPACE | grep "$OBCLUSTER_NAME-1-zone1" | awk -v line="$suffix" 'NR==line{print \$2}'`
pod_1_zone2=`kubectl get pod -o wide -n $NAMESPACE | grep "$OBCLUSTER_NAME-1-zone2" | awk -v line="$suffix" 'NR==line{print \$2}'`
pod_1_zone3=`kubectl get pod -o wide -n $NAMESPACE | grep "$OBCLUSTER_NAME-1-zone3" | awk -v line="$suffix" 'NR==line{print \$2}'`
ip=`kubectl get pod -o wide -n $NAMESPACE | grep $OBCLUSTER_NAME-1-zone1 |awk -F' ' '{print $6}'| awk 'NR==1'`
crd_obcluster=`kubectl get obcluster $OBCLUSTER_NAME -n $NAMESPACE -o yaml| grep "status: running" | tail -n 1| sed 's/ //g'`
if [[ $pod_1_zone1 = "1/1" && $pod_1_zone2 = "1/1" && $pod_1_zone3 = "1/1" && -n "$ip" && $crd_obcluster = "status:running" ]];then
echo "pod_1_zone1 is $pod_1_zone1 ready"
echo "pod_1_zone2 is $pod_1_zone2 ready"
echo "pod_1_zone3 is $pod_1_zone3 ready"
echo "svc is $ip ready"
echo "crd_obcluster $crd_obcluster"
RESOURCE_RUNNING='true'
break
fi
if [ $counter -eq $timeout ]; then
echo "resource still not running"
break
fi
sleep 3s
done
}
check_in_obcluster() {
local suffix=$1
counter=0
timeout=100
OBSERVER_ACTIVE='false'
ip=`kubectl get pod -o wide -n $NAMESPACE | grep $OBCLUSTER_NAME-1-zone1 |awk -F' ' '{print $6}'| awk 'NR==1'`
echo $ip
echo $PASSWORD
while true; do
echo 'check ob'
counter=$((counter+1))
server_1_zone1=`mysql -uroot -h $ip -P 2881 -Doceanbase -p$PASSWORD -e 'select * from __all_server;'|grep zone1| awk -v line="$suffix" 'NR==line{print \$11}'`
server_1_zone2=`mysql -uroot -h $ip -P 2881 -Doceanbase -p$PASSWORD -e 'select * from __all_server;'|grep zone2| awk -v line="$suffix" 'NR==line{print \$11}'`
server_1_zone3=`mysql -uroot -h $ip -P 2881 -Doceanbase -p$PASSWORD -e 'select * from __all_server;'|grep zone3| awk -v line="$suffix" 'NR==line{print \$11}'`
if [[ $server_1_zone1 == "ACTIVE" && $server_1_zone2 == "ACTIVE" && $server_1_zone3 == "ACTIVE" ]]
then
echo "server_1_zone1 $server_1_zone1"
echo "server_1_zone2 $server_1_zone2"
echo "server_1_zone3 $server_1_zone3"
OBSERVER_ACTIVE='true'
break
fi
if [ $counter -eq $timeout ]; then
echo "resource still not running"
echo "case failed"
break
fi
sleep 3s
done
}
validate() {
local suffix=$1
echo 'do validate'
check_resource_running $suffix
if [[ $RESOURCE_RUNNING == 'false' ]]; then
echo "case failed"
else
check_in_obcluster $suffix
if [[ $OBSERVER_ACTIVE == 'false' ]]; then
echo "case failed"
cleanup
prepare
else
echo "case passed"
fi
fi
}
run "obcluster_template_1-1-1.yaml"
validate 1
run "obcluster_template_2-2-2.yaml"
validate 2