-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathremove-node.sh
executable file
·68 lines (56 loc) · 2.16 KB
/
remove-node.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
#!/usr/bin/env bash
#
# This file is part of MinIO DirectPV
# Copyright (c) 2023 MinIO, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -e -C -o pipefail
declare NODE
function delete_resource() {
resource="$1"
selector="directpv.min.io/node=${NODE}"
# unset the finalizers
kubectl get "${resource}" --selector="${selector}" -o custom-columns=NAME:.metadata.name --no-headers | while read -r name; do
kubectl patch "${resource}" "${name}" -p '{"metadata":{"finalizers":null}}' --type=merge
done
# delete the objects
kubectl delete "${resource}" --selector="${selector}" --ignore-not-found=true
}
function init() {
if [[ $# -ne 1 ]]; then
cat <<EOF
usage: remove-node.sh <NODE>
This script forcefully removes all the DirectPV resources from the node.
CAUTION: Remove operation is irreversible and may incur data loss if not used cautiously.
EOF
exit 255
fi
if ! which kubectl >/dev/null 2>&1; then
echo "kubectl not found; please install"
exit 255
fi
NODE="$1"
if kubectl get --ignore-not-found=true csinode "${NODE}" -o go-template='{{range .spec.drivers}}{{if eq .name "directpv-min-io"}}{{.name}}{{break}}{{end}}{{end}}' | grep -q .; then
echo "node ${NODE} is still in use; remove node ${NODE} from DirectPV DaemonSet and try again"
exit 255
fi
}
function main() {
delete_resource directpvvolumes
delete_resource directpvdrives
delete_resource directpvinitrequests
kubectl delete directpvnode "${NODE}" --ignore-not-found=true
}
init "$@"
main "$@"