-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathuninstall-operator.sh
executable file
·132 lines (107 loc) · 3.44 KB
/
uninstall-operator.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
#!/usr/bin/env bash
# Copyright 2023.
#
# 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.
#
set -eu -o pipefail
PROJECT_ROOT="$(git rev-parse --show-toplevel)"
declare -r PROJECT_ROOT
# config
declare DELETE_RESOURCES=false
declare OPERATORS_NS="openshift-operators"
declare OPERATOR_VERSION="v0.5.0"
source "$PROJECT_ROOT/hack/utils.bash"
parse_args() {
### while there are args parse them
while [[ -n "${1+xxx}" ]]; do
case $1 in
--delete)
DELETE_RESOURCES=true
shift
;; # exit the loop
--ns | -n)
shift
OPERATORS_NS=$1
shift
;;
--version | -v)
shift
OPERATOR_VERSION=$1
[[ "${1:0:1}" != "v" ]] && OPERATOR_VERSION="v$1"
shift
;;
*) return 1 ;; # show usage on everything else
esac
done
return 0
}
print_usage() {
local scr
scr="$(basename "$0")"
read -r -d '' help <<-EOF_HELP || true
Usage:
$scr
$scr --delete
$scr --version
$scr --ns | -n
─────────────────────────────────────────────────────────────────
Options:
--delete deletes the resources listed
--version | -v version of the operator to delete
default: $OPERATOR_VERSION
--ns | -n NAMESPACE namespace where the operator is deployed
default: $OPERATORS_NS
EOF_HELP
echo -e "$help"
return 0
}
main() {
local operator="kepler-operator"
parse_args "$@" || {
print_usage
fail "failed to parse args"
return 1
}
header "Resources of Kepler Operator - $OPERATOR_VERSION"
kubectl get csv "${operator}.$OPERATOR_VERSION" -n "$OPERATORS_NS" || {
info "failed to find $OPERATOR_VERSION of $operator."
line 50
kubectl get csv | grep -E "$operator|NAME"
line 50
info "$operator version found are ☝️"
return 1
}
local label="operators.coreos.com/${operator}.$OPERATORS_NS="
info "Going to delete the following"
line 50 heavy
run kubectl get ns kepler || true
run kubectl get kepler -A
run kubectl get -n "$OPERATORS_NS" olm -l "$label"
run kubectl get operator,crd,clusterrole,clusterrolebinding -l "$label" -A
run kubectl get leases 0d9cbc82.sustainable.computing.io -n "$OPERATORS_NS" || true
run kubectl get catalogsource kepler-operator-catalog -n "$OPERATORS_NS" || true
line 50 heavy
! $DELETE_RESOURCES && {
info "Not deleting any resources, use --delete flag to force deletion"
return 0
}
header "Deleting Kepler Operator Version $OPERATOR_VERSION"
run kubectl delete kepler -A --all
run kubectl delete ns kepler || true
run kubectl delete -n "$OPERATORS_NS" olm -l "$label"
run kubectl delete operator,crd,clusterrole,clusterrolebinding -l "$label" -A
run kubectl delete leases 0d9cbc82.sustainable.computing.io -n "$OPERATORS_NS" || true
run kubectl delete catalogsource kepler-operator-catalog -n "$OPERATORS_NS" || true
ok "$operator version has been successfully uninstalled.\n"
}
main "$@"