forked from OpenEye-Dev/theiaDR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
control-commands
executable file
·165 lines (136 loc) · 3.66 KB
/
control-commands
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#! /bin/bash
display_usage() {
echo -e "Usage: \n bla bla bla... \n"
}
### Commands ------------------------------
export AVAILABLE_COMMANDS=(start_all start_processes stop_all stop_processes restart_processes resize get exit)
# In order to insert a new command, add it to the previus array
# and create a new function called cmd_NAME
# Controlled exit
cmd_exit(){
exit 0
}
# create_cluster
cmd_create_cluster(){
echo "Creating a new cluster"
gcloud container clusters create cl1 --num-nodes=7
}
# start_processes
cmd_start_processes(){
echo "Starting kubernetes processes"
cd kubernetes
# mongo, grade and api server
# sleep are added in order to give time to the db to start
# DB
sleep 2
# kubectl apply -f googlecloud_ssd.yaml
sleep 10
#kubectl apply -f mongo-statefulset.yaml
kubectl apply -f db.yml
sleep 60
# kubectl apply -f grade.yml
kubectl apply -f grade/grade_eye.yml
sleep 3
kubectl apply -f grade/grade_flower.yml
sleep 3
kubectl apply -f grade/grade_dr.yml
sleep 12
kubectl apply -f web.yml
}
# start_all
cmd_start_all(){
cmd_create_cluster
cmd_start_processes
}
# stop_processes
cmd_stop_processes(){
echo "Cleaning kubernetes processes"
# Clean deploy, svc, rc and pods
kubectl delete statefulsets --all
# kubectl delete pvc -l role=mongo
kubectl delete deploy --all
kubectl delete svc --all
kubectl delete rc --all
kubectl delete po --all
}
# stop_all
cmd_stop_all(){
echo "Stopping the cluster"
cmd_stop_processes
sleep 10
# Tear down the cluster
gcloud container clusters delete cl1
}
# restart
cmd_restart_processes(){
echo "Restarting the cluster"
cmd_stop_processes
sleep 35
cmd_start_processes
}
# resize
cmd_resize(){
clear
# DISPLAY DEPLOYMENTS
# Available deployments are listed in an array in project-config
while : ;
do
echo "Current status:"
kubectl get deploy
echo -e "\nResizing deployment of..."
for ((i=1;i <= ${#DEPLOYMENTS_PROD[@]}; i++));
do
echo $i. ${DEPLOYMENTS_PROD[i-1]}
done
read choice
if [[ $choice =~ ^[0-9]+$ && ${choice} -gt 0 && ${choice} -lt ${#DEPLOYMENTS_PROD[@]}+1 ]]
then
CHOSEN_DEPLOY=${DEPLOYMENTS_PROD[$choice-1]/.\//}
break
else
clear
echo -e "Unrecognized command. Type a number among the one shown below.\n"
fi
done
echo "Scaling $CHOSEN_DEPLOY to..."
read scale_choice
if [[ $scale_choice =~ ^[0-9]+$ && ${scale_choice} -gt -1 ]]
then
kubectl scale deploy $CHOSEN_DEPLOY --replicas=$scale_choice
else
echo -e "'${scale_choice}' is not a valid number."
fi
}
cmd_external-ip(){
kubectl get svc | awk -F" " '$3~/^[0-9]/ {print $1,$3}'
}
cmd_cluster-credentials(){
gcloud container clusters get-credentials cl1
}
# get
cmd_get(){
GET_OPTIONS_LIST=(external-ip cluster-credentials exit)
clear
echo "Available cluster info"
# if option in GET_OPTIONS_LIST, switch
# Display commands and let user choose
while : ;
do
echo "Choose a command using its number:"
for ((i=1;i <= ${#GET_OPTIONS_LIST[@]}; i++));
do
echo $i. ${GET_OPTIONS_LIST[i-1]}
done
read choice
if [[ $choice =~ ^[0-9]+$ && ${choice} -gt 0 && ${choice} -lt ${#GET_OPTIONS_LIST[@]}+1 ]]
then
CHOSEN_OPTION=${GET_OPTIONS_LIST[$choice-1]/.\//}
break
else
clear
echo -e "Unrecognized command. Type a number among the one shown below.\n"
fi
done
cmd_$CHOSEN_OPTION
}
# -----------------------------------------