-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
417 lines (367 loc) · 8.86 KB
/
install.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
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
#!/bin/bash
# Copyright 2021 The KubeEdge Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Influential env vars:
#
# SEDNA_ACTION | optional | 'create'/'clean', default is 'create'
# SEDNA_VERSION | optional | The Sedna version to be installed.
# if not specified, it will get latest release version.
# SEDNA_ROOT | optional | The Sedna offline directory
set -o errexit
set -o nounset
set -o pipefail
TMP_DIR='.'
SEDNA_ROOT='.'
SEDNA_VERSION=v1.0
REGISTRY=${REG:-docker.io}
_download_yamls() {
yaml_dir=$1
mkdir -p ${SEDNA_ROOT}/$yaml_dir
cd ${SEDNA_ROOT}/$yaml_dir
for yaml in ${yaml_files[@]}; do
# the yaml file already exists, no need to download
[ -e "$yaml" ] && continue
echo downloading $yaml into ${SEDNA_ROOT}/$yaml_dir
local try_times=30 i=1 timeout=2
while ! timeout ${timeout}s curl -sSO https://raw.githubusercontent.com/kubeedge/sedna/main/$yaml_dir/$yaml; do
((++i>try_times)) && {
echo timeout to download $yaml
exit 2
}
echo -en "retrying to download $yaml after $[i*timeout] seconds...\r"
done
done
}
download_yamls() {
yaml_files=(
sedna.io_datasets.yaml
sedna.io_federatedlearningjobs.yaml
sedna.io_incrementallearningjobs.yaml
sedna.io_jointinferenceservices.yaml
sedna.io_lifelonglearningjobs.yaml
sedna.io_models.yaml
)
_download_yamls build/crds
yaml_files=(
gm.yaml
)
_download_yamls build/gm/rbac
}
prepare_install(){
# need to create the namespace first
kubectl create ns sedna
}
prepare() {
mkdir -p ${SEDNA_ROOT}
# we only need build directory
# here don't use git clone because of large vendor directory
download_yamls
}
cleanup(){
kubectl delete ns sedna
}
create_crds() {
cd ${SEDNA_ROOT}
kubectl create -f build/crds
}
delete_crds() {
cd ${SEDNA_ROOT}
kubectl delete -f build/crds --timeout=90s
}
get_service_address() {
local service=$1
local port=$(kubectl -n sedna get svc $service -ojsonpath='{.spec.ports[0].port}')
# <service-name>.<namespace>:<port>
echo $service.sedna:$port
}
create_kb(){
cd ${SEDNA_ROOT}
kubectl $action -f - <<EOF
apiVersion: v1
kind: Service
metadata:
name: kb
namespace: sedna
spec:
selector:
sedna: kb
type: ClusterIP
ports:
- protocol: TCP
port: 9020
targetPort: 9020
name: "tcp-0" # required by edgemesh, to clean
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: kb
labels:
sedna: kb
namespace: sedna
spec:
replicas: 1
selector:
matchLabels:
sedna: kb
template:
metadata:
labels:
sedna: kb
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: node-role.kubernetes.io/edge
operator: DoesNotExist
serviceAccountName: sedna
containers:
- name: kb
imagePullPolicy: IfNotPresent
image: $REGISTRY/dayuhub/sedna-kb:$SEDNA_VERSION
env:
- name: KB_URL
value: "sqlite:///db/kb.sqlite3"
volumeMounts:
- name: kb-url
mountPath: /db
resources:
requests:
memory: 256Mi
cpu: 100m
limits:
memory: 512Mi
volumes:
- name: kb-url
hostPath:
path: /opt/kb-data
type: DirectoryOrCreate
EOF
}
prepare_gm_config_map() {
KB_ADDRESS=$(get_service_address kb)
cm_name=${1:-gm-config}
config_file=${TMP_DIR}/${2:-gm.yaml}
if [ -n "${SEDNA_GM_CONFIG:-}" ] && [ -f "${SEDNA_GM_CONFIG}" ] ; then
cp "$SEDNA_GM_CONFIG" $config_file
else
cat > $config_file << EOF
kubeConfig: ""
master: ""
namespace: ""
websocket:
address: 0.0.0.0
port: 9000
localController:
server: http://localhost:${SEDNA_LC_BIND_PORT:-9100}
knowledgeBaseServer:
server: http://$KB_ADDRESS
EOF
fi
kubectl $action -n sedna configmap $cm_name --from-file=$config_file
}
create_gm() {
cd ${SEDNA_ROOT}
kubectl create -f build/gm/rbac/
cm_name=gm-config
config_file_name=gm.yaml
prepare_gm_config_map $cm_name $config_file_name
kubectl $action -f - <<EOF
apiVersion: v1
kind: Service
metadata:
name: gm
namespace: sedna
spec:
selector:
sedna: gm
type: ClusterIP
ports:
- protocol: TCP
port: 9000
targetPort: 9000
name: "tcp-0" # required by edgemesh, to clean
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: gm
labels:
sedna: gm
namespace: sedna
spec:
replicas: 1
selector:
matchLabels:
sedna: gm
template:
metadata:
labels:
sedna: gm
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: node-role.kubernetes.io/edge
operator: DoesNotExist
serviceAccountName: sedna
containers:
- name: gm
image: $REGISTRY/dayuhub/sedna-gm:$SEDNA_VERSION
command: ["sedna-gm", "--config", "/config/$config_file_name", "-v2"]
volumeMounts:
- name: gm-config
mountPath: /config
resources:
requests:
memory: 32Mi
cpu: 100m
limits:
memory: 256Mi
volumes:
- name: gm-config
configMap:
name: $cm_name
EOF
}
delete_gm() {
cd ${SEDNA_ROOT}
kubectl delete -f build/gm/rbac/
# no need to clean gm deployment alone
}
create_lc() {
GM_ADDRESS=$(get_service_address gm)
kubectl $action -f- <<EOF
apiVersion: apps/v1
kind: DaemonSet
metadata:
labels:
sedna: lc
name: lc
namespace: sedna
spec:
selector:
matchLabels:
sedna: lc
template:
metadata:
labels:
sedna: lc
spec:
containers:
- name: lc
image: $REGISTRY/dayuhub/sedna-lc:$SEDNA_VERSION
env:
- name: GM_ADDRESS
value: $GM_ADDRESS
- name: BIND_PORT
value: "${SEDNA_LC_BIND_PORT:-9100}"
- name: NODENAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: ROOTFS_MOUNT_DIR
# the value of ROOTFS_MOUNT_DIR is same with the mount path of volume
value: /rootfs
resources:
requests:
memory: 32Mi
cpu: 100m
limits:
memory: 128Mi
volumeMounts:
- name: localcontroller
mountPath: /rootfs
volumes:
- name: localcontroller
hostPath:
path: /
restartPolicy: Always
EOF
}
delete_lc() {
# ns would be deleted in delete_gm
# so no need to clean lc alone
return
}
wait_ok() {
echo "Waiting control components to be ready..."
kubectl -n sedna wait --for=condition=available --timeout=600s deployment/gm
kubectl -n sedna wait pod --for=condition=Ready --selector=sedna
kubectl -n sedna get pod
}
delete_pods() {
# in case some nodes are not ready, here delete with a 60s timeout, otherwise force delete these
kubectl -n sedna delete pod --all --timeout=60s || kubectl -n sedna delete pod --all --force --grace-period=0
}
check_kubectl () {
kubectl get pod >/dev/null
}
check_action() {
action=${SEDNA_ACTION:-create}
support_action_list="create delete"
if ! echo "$support_action_list" | grep -w -q "$action"; then
echo "\`$action\` not in support action list: create/delete!" >&2
echo "You need to specify it by setting $(red_text SEDNA_ACTION) environment variable when running this script!" >&2
exit 2
fi
}
do_check() {
check_kubectl
check_action
}
show_debug_infos() {
cat - <<EOF
Sedna is $(green_text running):
See GM status: kubectl -n sedna get deploy
See LC status: kubectl -n sedna get ds lc
See Pod status: kubectl -n sedna get pod
EOF
}
NO_COLOR='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
green_text() {
echo -ne "$GREEN$@$NO_COLOR"
}
red_text() {
echo -ne "$RED$@$NO_COLOR"
}
do_check
case "$action" in
create)
echo "Installing Sedna $SEDNA_VERSION..."
prepare_install
create_crds
create_kb
create_gm
create_lc
wait_ok
show_debug_infos
;;
delete)
# no errexit when fail to clean
set +o errexit
delete_pods
delete_gm
delete_lc
delete_crds
cleanup
echo "$(green_text Sedna is uninstalled successfully)"
;;
esac