-
Notifications
You must be signed in to change notification settings - Fork 2
/
cluster.sh
executable file
·200 lines (199 loc) · 6.46 KB
/
cluster.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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/usr/bin/env bash
. utils.sh
clear
echo ""
prnt "Manage etcd cluster(mec)"
declare -A clusterActions
clusterActions+=(['Quit']='quit')
clusterActions+=(['System pods states']='pod-state')
clusterActions+=(['Current cluster state']='cluster-state')
clusterActions+=(['Restart kubernetes runtime']='restart-runtime')
clusterActions+=(['Refresh view']='refresh-view')
clusterActions+=(['Snapshot view']='snapshot-view')
clusterActions+=(['State view']='state-view')
clusterActions+=(['System init']='system-init')
clusterActions+=(['Setup kubernetes cluster']='setup-kube-cluster')
clusterActions+=(['Manage external etcd']='manage-etcd')
clusterActions+=(['Suspend embedded etcd']='suspend-embedded-etcd')
clusterActions+=(['Resume embedded etcd']='resume-embedded-etcd')
clusterActions+=(['Console']='console')
re="^[0-9]+$"
PS3=$'\e[92mSelection(mec): \e[0m'
select option in "${!clusterActions[@]}"; do
if ! [[ "$REPLY" =~ $re ]] || [ "$REPLY" -gt 13 -o "$REPLY" -lt 1 ]; then
err "Invalid selection!"
else
case "${clusterActions[$option]}" in
cluster-state)
. checks/cluster-state.sh
;;
setup-kube-cluster)
./setup-kube-cluster.sh
PS3=$'\e[92mSelection(mec): \e[0m'
;;
suspend-embedded-etcd)
prnt "Suspend embedded etcd"
read_setup
if [ ! -z "$masters" ]; then
PS3=$'\e[92mChoose one(q to quit): \e[0m'
unset masterHostAndIps
declare -a masterHostAndIps
for etcd_node_entry in $masters; do
if ! is_etcd_suspended_at $(echo $etcd_node_entry | cut -d':' -f2); then
masterHostAndIps+=($etcd_node_entry)
fi
done
count=${#masterHostAndIps[@]}
[ "$count" -eq 0 ] && prnt "Etcd(s) already suspended"
select host_and_ip in "${masterHostAndIps[@]}"; do
if [ "$REPLY" == 'q' ]; then
prnt "Exited etcd suspension"
echo ""
PS3=$'\e[92mSelection(mee): \e[0m'
break
fi
if ! [[ "$REPLY" =~ $re ]] || [ "$REPLY" -gt "$count" -o "$REPLY" -lt 1 ]; then
err "Invalid selection"
else
echo "Selected $host_and_ip ($REPLY) for suspension"
echo "Suspending etcd node: $host_and_ip"
node_name=$(echo $host_and_ip | cut -d':' -f1)
node_ip=$(echo $host_and_ip | cut -d':' -f2)
. suspend-embedded-etcd.sh $node_name $node_ip
if [ "$?" -eq 0 ]; then
:
else
:
fi
fi
done
else
err "No etcd node to suspend"
fi
PS3=$'\e[92mSelection(mee): \e[0m'
;;
console)
./console.sh
PS3=$'\e[92mSelection(mec): \e[0m'
;;
resume-embedded-etcd)
prnt "Resuming embedded etcd"
prnt "Resume embedded etcd"
read_setup
if [ ! -z "$masters" ]; then
PS3=$'\e[92mChoose one(q to quit): \e[0m'
unset _masterHostAndIps
declare -a _masterHostAndIps
for _etcd_node_entry in $masters; do
if is_etcd_suspended_at $(echo $_etcd_node_entry | cut -d':' -f2); then
_masterHostAndIps+=($_etcd_node_entry)
fi
done
count=${#_masterHostAndIps[@]}
[ "$count" -eq 0 ] && prnt "Etcd(s) already resumed"
select _host_and_ip in "${_masterHostAndIps[@]}"; do
if [ "$REPLY" == 'q' ]; then
prnt "Exited etcd resume"
echo ""
PS3=$'\e[92mSelection(mee): \e[0m'
break
fi
if ! [[ "$REPLY" =~ $re ]] || [ "$REPLY" -gt "$count" -o "$REPLY" -lt 1 ]; then
err "Invalid selection"
else
echo "Selected $_host_and_ip ($REPLY) for resume"
echo "Resuming etcd on node: $_host_and_ip"
_node_ip=$(echo $_host_and_ip | cut -d':' -f2)
. resume-embedded-etcd.sh $_node_ip
if [ "$?" -eq 0 ]; then
:
else
:
fi
fi
done
else
err "No etcd node to resume"
fi
PS3=$'\e[92mSelection(mee): \e[0m'
;;
manage-etcd)
echo "Manage etcd"
. widgets/manage-etcd.sh
PS3=$'\e[92mSelection(mec): \e[0m'
;;
system-init)
. checks/cluster-state.sh
if [ "$cluster_state" = "external-up" ]; then
warn "System init will fail when cluster is running on external etcd!"
return 1
fi
. widgets/system-init.sh
system_init_response=$?
if [ "$system_init_response" -ne 0 ]; then
err "System init was not complete - turn on debug & check messages."
else
if [ "$user_action" = "q" ]; then
prnt "Exited system initialization"
else
:
fi
fi
echo ""
PS3=$'\e[92mSelection(mec): \e[0m'
;;
pod-state)
. checks/system-pod-state.sh
;;
restart-runtime)
PS3=$'\e[92mRestarting k8s runtime - choose option: \e[0m'
restart_options=("Auto-detect kube nodes" "Enter ips" "Back")
select restart_option in "${restart_options[@]}"; do
case "$REPLY" in
1)
. restart-runtime.sh
break
;;
2)
echo "Type in the kube node IPs - blank line to complete: "
rm -f /tmp/kube_ips.tmp
while read line; do
[ -z "$line" ] && break
echo "$line" >>/tmp/kube_ips.tmp
done
if [ -s /tmp/kube_ips.tmp ]; then
kube_ips=$(cat /tmp/kube_ips.tmp | tr "\n" " " | xargs)
. restart-runtime.sh $kube_ips
rm -f /tmp/kube_ips.tmp
else
err "No node ips provided!"
fi
break
;;
3)
break
;;
esac
done
echo ""
PS3=$'\e[92mSelection(mec) \e[0m'
;;
refresh-view)
script=$(readlink -f "$0")
exec "$script"
;;
snapshot-view)
script=$(readlink -f "snapshots.sh")
exec "$script"
;;
quit)
prnt "quit"
break
;;
state-view)
script=$(readlink -f "states.sh")
exec "$script"
;;
esac
fi
done