-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwave-infra-installation.sh
executable file
·375 lines (304 loc) · 9.21 KB
/
wave-infra-installation.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
#!/bin/bash
#General parameters
SPARK_OPERATOR_NAMESPACE="wave-sparkoperator"
SPARK_APPLICATIONS_NAMESPACE="wave-applications"
LOG_LEVEL="info"
#PVC yaml template URL
PVC_YAML_TEMPLATE="https://raw.githubusercontent.com/alextarasov-spot/wave-sparkhistory-helm-chart/master/wave-pvc-sparkhistory-template.yaml"
#EFS provisioner DEFAULT parameters
EFS_ENABLED=false
PVC_ENABLED=true
WAVE_PVC_NAME="wave-efs"
EFS_PROVISIONER_RELEASE_NAME="wave-nfs"
EFS_PROVISIONER_SERVICE_ACCOUNT_NAME="wave-efs-provisioner"
EFS_PROVISIONER_NAME="wave.sparkhistory/aws-efs"
WAVE_EFS_PROVISIONER_STORAGE_CLASS_NAME="wave-aws-efs"
#EFS provisioner MANDATORY parameters
EFS_FILESYSTEM_ID=""
EFS_AWS_REGION=""
#Spark History Server parameters
SPARK_HISTORY_RELEASE_NAME="wave-history"
#Spark Operator parameters
SPARK_OPERATOR_RELEASE_NAME="wave-spark"
#HELM dry-run mode
DRY_RUN=false
#UNINSTALL mode
UNINSTALL=false
#create necessarry createNamespaces
function createNamespaces() {
info "Going to create namespace $SPARK_OPERATOR_NAMESPACE"
# verify that the SPARK_OPERATOR_NAMESPACE namespace doesn't exists
ns=$(kubectl get namespace $SPARK_OPERATOR_NAMESPACE --no-headers --output=go-template={{.metadata.name}} 2>/dev/null)
if [ -z "${ns}" ]; then
kubectl create namespace $SPARK_OPERATOR_NAMESPACE
else
info "Namespace $SPARK_OPERATOR_NAMESPACE already exists"
fi
printf "\n"
info "Going to create namespace $SPARK_APPLICATIONS_NAMESPACE"
# verify that the SPARK_APPLICATIONS_NAMESPACE namespace doesn't exists
ns=$(kubectl get namespace $SPARK_APPLICATIONS_NAMESPACE --no-headers --output=go-template={{.metadata.name}} 2>/dev/null)
if [ -z "${ns}" ]; then
kubectl create namespace $SPARK_APPLICATIONS_NAMESPACE
else
info "Namespace $SPARK_APPLICATIONS_NAMESPACE already exists"
fi
}
function efsProvisioner() {
if [ "$EFS_ENABLED" = false ]; then
debug "efsEbabled set to false"
return 0
fi
printf "\n"
info "efsEbabled set to ($EFS_ENABLED). Going to install EFS Provisioner into $SPARK_APPLICATIONS_NAMESPACE namespace"
info "EFS Provisioner Release name: ($EFS_PROVISIONER_RELEASE_NAME)"
info "EFS Provisioner name: ($EFS_PROVISIONER_NAME)"
info "EFS Provisioner StorageClass Name: ($WAVE_EFS_PROVISIONER_STORAGE_CLASS_NAME)"
info "EFS File Systen ID: ($EFS_FILESYSTEM_ID)"
info "AWS Region: ($EFS_AWS_REGION)"
printf "\n"
helm repo add stable https://kubernetes-charts.storage.googleapis.com
helm install $EFS_PROVISIONER_RELEASE_NAME $($DRY_RUN && echo "--dry-run --debug") stable/efs-provisioner \
--namespace $SPARK_APPLICATIONS_NAMESPACE \
--set efsProvisioner.provisionerName=$EFS_PROVISIONER_NAME \
--set serviceAccount.name=$EFS_PROVISIONER_SERVICE_ACCOUNT_NAME \
--set efsProvisioner.storageClass.name=$WAVE_EFS_PROVISIONER_STORAGE_CLASS_NAME \
--set efsProvisioner.efsFileSystemId=$EFS_FILESYSTEM_ID \
--set efsProvisioner.awsRegion=$EFS_AWS_REGION
if [ $? -gt 0 ]; then
printf "\n\n\t\t"
error "ERROR: EFS Provisioner not installed. Please check the error message above"
exit 1
fi
#Create PVC
if [ "$PVC_ENABLED" = true ]; then
createPvc
else
info "pvcEnabled set to FALSE. PVC won't be created. Please take a look at template above."
fi
}
function createPvc() {
info "Going to create PVC from template"
debug "Namespace: ${SPARK_APPLICATIONS_NAMESPACE}"
debug "EFS Provisioner StorageClass Name: ${WAVE_EFS_PROVISIONER_STORAGE_CLASS_NAME}"
#Get PVC yaml from WAVE repository
source /dev/stdin <<<"$(
echo 'cat <<EOF >>wave-pvc-sparkhistory.yaml'
curl -s $PVC_YAML_TEMPLATE
)"
finalPvcYaml=$(cat wave-pvc-sparkhistory.yaml)
debug "wave-pvc-sparkhistory.yaml\n $finalPvcYaml"
kubectl apply -f wave-pvc-sparkhistory.yaml
if [ $? -gt 0 ]; then
printf "\n\n\t\t"
error "ERROR: PVC not created. Please check the error message above"
exit 1
fi
#Remove tmp result PVC yaml
rm wave-pvc-sparkhistory.yaml
}
function sparkHistory() {
info "Going to install Spark History Server into $SPARK_APPLICATIONS_NAMESPACE namespace"
printf "\n"
helm repo add stable https://kubernetes-charts.storage.googleapis.com
helm install $SPARK_HISTORY_RELEASE_NAME $($DRY_RUN && echo "--dry-run --debug") stable/spark-history-server \
--namespace $SPARK_APPLICATIONS_NAMESPACE \
--set nfs.enableExampleNFS=false \
--set pvc.enablePVC=$PVC_ENABLED \
--set pvc.existingClaimName=$WAVE_PVC_NAME
if [ $? -gt 0 ]; then
printf "\n\n\t\t"
error "ERROR: Spark Histroy Server not installed. Please check the error message above"
exit 1
fi
}
function sparkOperator() {
info "Going to install Spark Operator into $SPARK_OPERATOR_NAMESPACE namespace"
printf "\n"
helm repo add incubator http://storage.googleapis.com/kubernetes-charts-incubator
helm install $SPARK_OPERATOR_RELEASE_NAME $($DRY_RUN && echo "--dry-run --debug") incubator/sparkoperator \
--namespace $SPARK_OPERATOR_NAMESPACE \
--set sparkJobNamespace=$SPARK_APPLICATIONS_NAMESPACE \
--set enableWebhook=true
if [ $? -gt 0 ]; then
printf "\n\n\t\t"
error "ERROR: Spark Operator not installed. Please check the error message above"
exit 1
fi
}
function validation() {
#Validate EFS mandatory parameters if efsEnambled
if [ "$EFS_ENABLED" = true ]; then
if [ -z "$EFS_FILESYSTEM_ID" ]; then
error "ERROR: efsProvisioner.efsFileSystemId is empty EXIT"
exit 1
fi
if [ -z "$EFS_AWS_REGION" ]; then
error "ERROR: efsProvisioner.awsRegion is empty. EXIT"
exit 1
fi
fi
}
function uninstall() {
if [ "$UNINSTALL" = false ]; then
return 0
fi
warn "WARNING: You are about to uninstall resources creaed by Wave!
This includes Sprak-Operator,Spark-History and wave-applications namespaces"
echo "Do you want to uninstall?"
select yn in "Yes" "No"; do
case $yn in
Yes)
uninstallSparkOperator
uninstallSparkHistory
uninstallEfsProvisioner
break
;;
No) exit ;;
esac
done
info "Uninstalled successfully"
exit 0
}
function uninstallSparkOperator() {
info "Going to uninstall Spark Operator"
helm uninstall $SPARK_OPERATOR_RELEASE_NAME --namespace $SPARK_OPERATOR_NAMESPACE
if [ $? -gt 0 ]; then
printf "\n\n\t\t"
error "ERROR: Couldn't uninstall Spark Operator. Please check the error message above"
exit 1
fi
}
function uninstallSparkHistory() {
info "Going to uninstall Spark History"
helm uninstall $SPARK_HISTORY_RELEASE_NAME --namespace $SPARK_APPLICATIONS_NAMESPACE
if [ $? -gt 0 ]; then
printf "\n\n\t\t"
error "ERROR: Couldn't uninstall Spark History. Please check the error message above"
exit 1
fi
}
function uninstallEfsProvisioner() {
if [ "$EFS_ENABLED" = false ]; then
info "efsEbabled set to false. EFS Provisioner won't be uninstalled"
return 0
fi
info "Going to uninstall EFS Provisioner"
helm uninstall $EFS_PROVISIONER_RELEASE_NAME --namespace $SPARK_APPLICATIONS_NAMESPACE
if [ $? -gt 0 ]; then
printf "\n\n\t\t"
error "ERROR: Couldn't uninstall EFS Provisioner. Please check the error message above"
exit 1
fi
if [ "$PVC_ENABLED" = false ]; then
info "pvcEbabled set to false. PVC $WAVE_PVC_NAME won't be deleted"
return 0
fi
info "Going to delete PVC"
kubectl delete pvc $WAVE_PVC_NAME -n $SPARK_APPLICATIONS_NAMESPACE
if [ $? -gt 0 ]; then
printf "\n\n\t\t"
error "ERROR: Couldn't delete PVC. Please check the error message above"
exit 1
fi
}
log_level_for() {
case "${1}" in
"error")
echo 1
;;
"warn")
echo 2
;;
"info")
echo 3
;;
"debug")
echo 4
;;
*)
echo -1
;;
esac
}
current_log_level() {
log_level_for "${LOG_LEVEL}"
}
error() {
[ $(log_level_for "error") -le $(current_log_level) ] && echo "${1}" >&2
}
warn() {
[ $(log_level_for "warn") -le $(current_log_level) ] && echo "${1}" >&2
}
debug() {
[ $(log_level_for "debug") -le $(current_log_level) ] && echo "${1}" >&2
}
info() {
[ $(log_level_for "info") -le $(current_log_level) ] && echo "${1}" >&2
}
function usage() {
cat <<EOF
Install and configure all prerequisites for Wave product by Spot
Usage:
${0} [flags]
Flags:
--efs-enabled Enable EFS for spark history setup
--efs-file-system-id EFS FileSystemID for spark history Setup
--efs-aws-region EFS Region location
--pvc-enabled creating PVC for spark history deployment
--dry-run
--uninstall Delete all deployments/configs installed by Wave
EOF
exit 1
}
function init() {
while [[ $# -gt 0 ]]; do
case ${1} in
--efs-enabled)
EFS_ENABLED="$2"
shift
;;
--efs-file-system-id)
EFS_FILESYSTEM_ID="$2"
shift
;;
--efs-aws-region)
EFS_AWS_REGION="$2"
shift
;;
--efsProvisionerName)
EFS_PROVISIONER_NAME="$2"
shift
;;
--pvc-enabled)
PVC_ENABLED="$2"
shift
;;
--dry-run)
DRY_RUN="$2"
shift
;;
--uninstall)
UNINSTALL="$2"
shift
;;
*)
usage
;;
esac
shift
done
if [ "$DRY_RUN" = true ]; then
LOG_LEVEL="debug"
fi
}
function main() {
uninstall
validation
createNamespaces
efsProvisioner
sparkHistory
sparkOperator
}
init "$@"
main "$@"