-
Notifications
You must be signed in to change notification settings - Fork 1
/
kobectl
executable file
·334 lines (270 loc) · 9.18 KB
/
kobectl
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#!/bin/sh
COMMAND=$1
case $COMMAND in
##############################################################################
"apply")
USAGE="usage: kobectl apply [configuration_file]"
CONF_FILE=$2
if [ -z $CONF_FILE ]
then
echo $USAGE
exit
fi
kubectl apply -f $CONF_FILE
;;
##############################################################################
"get")
USAGE="usage: kobectl get [resource_type]"
TYPE=$2
FLAGS="-o custom-columns=NAME:.metadata.name"
if [ -z $TYPE ]
then
echo $USAGE
exit
fi
case $TYPE in
"benchmark" | "benchmarks")
kubectl get benchmarks.kobe.semagrow.org $FLAGS
;;
"experiment" | "experiments")
kubectl get experiments.kobe.semagrow.org $FLAGS
;;
"federatortemplate" | "federatortemplates")
kubectl get federatortemplates.kobe.semagrow.org $FLAGS
;;
"datasettemplate" | "datasettemplates")
kubectl get datasettemplates.kobe.semagrow.org $FLAGS
;;
*)
echo $USAGE
;;
esac
;;
##############################################################################
"delete")
USAGE="usage: kobectl delete [resource_type] [resource]"
TYPE=$2
RESOURCE=$3
if [ -z $TYPE ] || [ -z $RESOURCE ]
then
echo $USAGE
exit
fi
case $TYPE in
"benchmark" | "benchmarks")
kubectl delete benchmarks.kobe.semagrow.org $RESOURCE
;;
"experiment" | "experiments")
kubectl delete experiments.kobe.semagrow.org $RESOURCE
;;
"federatortemplate" | "federatortemplates")
kubectl delete federatortemplates.kobe.semagrow.org $RESOURCE
;;
"datasettemplate" | "datasettemplates")
kubectl delete datasettemplates.kobe.semagrow.org $RESOURCE
;;
*)
echo $USAGE
exit
;;
esac
;;
##############################################################################
"show")
USAGE="usage: kobectl show [resource_type] [resource]"
TYPE=$2
RESOURCE=$3
FLAGS="-o custom-columns=NAME:.metadata.name"
if [ -z $TYPE ] || [ -z $RESOURCE ]
then
echo $USAGE
exit
fi
case $TYPE in
"benchmark" | "benchmarks")
DATASETS=`kubectl get benchmarks.kobe.semagrow.org $RESOURCE \
-o jsonpath="{.spec.datasets[*].name}"`
OUTPUT="NAME STATUS\n"
for DATASET in $DATASETS
do
STATUS=`kubectl get pod $DATASET-pod -n $RESOURCE \
-o custom-columns=:.status.phase --no-headers \
2> /dev/null`
if [ -z $STATUS ]
then
continue
fi
OUTPUT="$OUTPUT$DATASET $STATUS\n"
done
echo -n $OUTPUT | column -t
;;
"experiment" | "experiments")
NAMESPACE=`kubectl get experiments.kobe.semagrow.org $RESOURCE \
-o jsonpath="{.spec.benchmark}"`
FEDERATOR=`kubectl get experiments.kobe.semagrow.org $RESOURCE \
-o jsonpath="{.spec.federatorName}"`
FEDSTATUS=`kubectl get pod $FEDERATOR -n $NAMESPACE \
-o custom-columns=:.status.phase --no-headers \
2< /dev/null`
JOBS=`kubectl get pods --no-headers \
-o custom-columns=:.metadata.name,:.status.phase \
| grep $RESOURCE-evaluationjob`
OUTPUT="NAME STATUS\n$FEDERATOR $FEDSTATUS\n$JOBS\n"
echo -n $OUTPUT | column -t
;;
"federatortemplate" | "federatortemplates")
kubectl get federatortemplate.kobe.semagrow.org $RESOURCE $FLAGS
;;
"datasettemplate" | "datasettemplates")
kubectl get datasettemplate.kobe.semagrow.org $RESOURCE $FLAGS
;;
*)
echo $USAGE
;;
esac
;;
##############################################################################
"install")
USAGE="usage: kobectl install [component] [kobe-directory]"
COMPONENT=$2
KOBEDIR=$3
if [ -z $COMPONENT ] || [ -z $KOBEDIR ]
then
echo $USAGE
exit
fi
cd $KOBEDIR
case $COMPONENT in
"operator")
OPERATOR="true"
;;
"operator-v1")
OPERATOR="true"
;;
"operator-v1beta1")
OPERATOR_BETA="true"
;;
"istio")
ISTIO="true"
;;
"efk")
EFK="true"
;;
"full")
OPERATOR="true"
ISTIO="true"
EFK="true"
;;
*)
echo $USAGE
exit
;;
esac
if [ ! -z $OPERATOR ]
then
kubectl apply -f operator/deploy/crds
kubectl apply -f operator/deploy/service_account.yaml
kubectl apply -f operator/deploy/clusterrole.yaml
kubectl apply -f operator/deploy/clusterrole_binding.yaml
kubectl apply -f operator/deploy/role.yaml
kubectl apply -f operator/deploy/operator.yaml
fi
if [ ! -z $OPERATOR_BETA ]
then
kubectl apply -f operator/deploy/crds-v1beta1
kubectl apply -f operator/deploy/service_account.yaml
kubectl apply -f operator/deploy/clusterrole.yaml
kubectl apply -f operator/deploy/clusterrole_binding.yaml
kubectl apply -f operator/deploy/role.yaml
kubectl apply -f operator/deploy/operator.yaml
fi
if [ ! -z $ISTIO ]
then
curl -L https://istio.io/downloadIstio | sh -
./istio-*/bin/istioctl manifest apply --set profile=default
fi
if [ ! -z $EFK ]
then
helm repo add elastic https://helm.elastic.co
helm repo add kiwigrid https://kiwigrid.github.io
helm install elasticsearch elastic/elasticsearch --set persistence.enabled=false --set replicas=1 --version 7.6.2
helm install kibana elastic/kibana --set service.type=NodePort --version 7.6.2
helm install fluentd kiwigrid/fluentd-elasticsearch -f operator/deploy/efk-config/fluentd-values.yaml --version 8.0.1
kubectl apply -f operator/deploy/efk-config/kobe-kibana-configuration.yaml
fi
;;
##############################################################################
"purge")
USAGE="usage: kobectl purge [kobe-directory]"
KOBEDIR=$2
if [ -z $KOBEDIR ]
then
echo $USAGE
exit
fi
cd $KOBEDIR
echo "This operation will uninstall KOBE from your system."
echo -n "Proceed (y/n)? "
read answer
if [ "$answer" != "${answer#[Yy]}" ]
then
kubectl delete experiments.kobe.semagrow.org --all
kubectl delete benchmarks.kobe.semagrow.org --all
kubectl delete federatortemplates.kobe.semagrow.org --all
kubectl delete datasettemplates.kobe.semagrow.org --all
kubectl delete -f operator/deploy/operator.yaml
kubectl delete -f operator/deploy/role.yaml
kubectl delete -f operator/deploy/clusterrole_binding.yaml
kubectl delete -f operator/deploy/clusterrole.yaml
kubectl delete -f operator/deploy/service_account.yaml
kubectl delete -f operator/deploy/crds
./istio-*/bin/istioctl manifest generate --set profile=default \
| kubectl delete -f -
kubectl delete namespace istio-system
helm delete elasticsearch
helm delete kibana
helm delete fluentd
helm repo remove elastic
helm repo remove kiwigrid
kubectl delete jobs.batch kobe-kibana-configuration
kubectl delete configmaps kobe-kibana-config
echo "Kobe removed."
echo "To also remove fluentd pos and buffer files issue in each node:"
echo "rm -rf /var/log/fluentd-buffers"
echo "rm /var/log/containers.log.pos"
fi
;;
##############################################################################
*)
echo "kobectl controls the KOBE open benchmarking engine."
echo ""
echo "Commands:"
echo " apply apply a resource using a .yaml configuration file"
echo " get display all resources of specific type"
echo " show show the state of a benchmark or an experiment"
echo " delete delete a resource of specific type"
echo " install install KOBE components"
echo " purge uninstall KOBE"
echo " help print this message"
echo ""
echo "Usage:"
echo " kobectl apply [configuration_file]"
echo " kobectl get [resource_type]"
echo " kobectl show [resource_type] [resource]"
echo " kobectl delete [resource_type] [resource]"
echo " kobectl install [component] [kobe-directory]"
echo " kobectl purge [kobe-directory]"
echo ""
echo "[resource_type] can be any of:"
echo " benchmark(s),"
echo " experiment(s),"
echo " federatortemplate(s),"
echo " datasettemplate(s)."
echo ""
echo "[component] can be any of:"
echo " operator, operator-v1, operator-v1beta1, istio, efk, full"
echo ""
echo "for more advanced control options for KOBE, use kubectl."
;;
##############################################################################
esac