forked from kubeflow/arena
-
Notifications
You must be signed in to change notification settings - Fork 9
/
uninstall.sh
executable file
·131 lines (117 loc) · 2.84 KB
/
uninstall.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
#!/bin/bash
set -xe
function help() {
echo -e "
Usage:
arena-uninstall [OPTION1] [OPTION2] ...
Options:
--kubeconfig string Specify the kubeconfig file
--namespace string Specify the namespace to delete arena
--delete-binary Clean the client env,include ~/charts and /usr/local/bin/arena
--delete-crds Delete the CRDs,Warning: this option will delete the training jobs
--chart-dir Specify the chart dir
"
}
function logger() {
timestr=$(date +"%Y-%m-%d/%H:%M:%S")
level=$(echo $1 | tr 'a-z' 'A-Z')
echo ${timestr}" "${level}" "$2
}
function run() {
detect_chart_dir
delete
if [[ $DELETE_CRDS == "true" ]];then
delete_crds $ARTIFACTS_DIR/all_crds
fi
if [[ $CLEAN_CLIENT == "true" ]];then
delete_client
fi
}
function delete() {
set +e
if arena-helm list -n $ARENA_NAMESPACE | grep arena-artifacts &> /dev/null;then
arena-helm delete arena-artifacts -n $ARENA_NAMESPACE
fi
arena-helm template arena-artifacts -n $ARENA_NAMESPACE $ARTIFACTS_DIR > /tmp/arena-artifacts.yaml
arena-kubectl delete -f /tmp/arena-artifacts.yaml
arena-kubectl delete ns $ARENA_NAMESPACE
set -e
}
function delete_client() {
rm -rf /charts
rm -rf /usr/local/bin/arena*
}
function delete_crds() {
for file in $(ls $1);do
local path=$1"/"$file
if [ -d $path ];then
delete_crds $path
else
arena-kubectl delete -f $path || true
fi
done
}
function detect_chart_dir() {
ARTIFACTS_DIR=""
if [[ $CHART_DIR != "" ]];then
export ARTIFACTS_DIR=$CHART_DIR
return
fi
if [ -d arena-artifacts ];then
export ARTIFACTS_DIR=arena-artifacts
return
fi
if [ -d ~/charts/arena-artifacts ];then
export ARTIFACTS_DIR=~/charts/arena-artifacts
return
fi
export ARTIFACTS_DIR=/charts/arena-artifacts
}
function parse_args() {
while [[ $# -gt 0 ]];do
key="$1"
case $key in
--delete-binary)
export CLEAN_CLIENT="true"
;;
--delete-crds)
export DELETE_CRDS="true"
;;
--namespace)
check_option_value "--namespace" $2
export ARENA_NAMESPACE=$2
shift
;;
--chart-dir)
check_option_value "--chart-dir" $2
export CHART_DIR=$2
shift
;;
--help|-h)
help
exit 0
;;
*)
# unknown option
logger error "unkonw option [$key]"
help
exit 3
;;
esac
shift
done
}
function check_option_value() {
option=$1
value=$2
if [[ $value == "" ]] || echo "$value" | grep -- "^--" &> /dev/null;then
logger error "the option $option not set value,please set it"
exit 3
fi
}
function main() {
export ARENA_NAMESPACE="arena-system"
parse_args $@
run
}
main $@