-
Notifications
You must be signed in to change notification settings - Fork 0
/
ceph-uninstall.sh
executable file
·103 lines (88 loc) · 3.31 KB
/
ceph-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
#!/bin/bash
# Copyright (c) 2023 Ho Kim ([email protected]). All rights reserved.
# Use of this source code is governed by a GPL-3-style license that can be
# found in the LICENSE file.
# Prehibit errors
set -e -o pipefail
###########################################################
# Configuration #
###########################################################
# Configure default environment variables
OPENARK_HOME_DEFAULT="${HOME}/Library/ipis-dev-env/netai-cloud"
# Configure environment variables
OPENARK_HOME="${OPENARK_HOME:-$OPENARK_HOME_DEFAULT}"
if [ "x${SSH_KEYFILE_PATH}" = 'x' ]; then
echo "Environment variable \"SSH_KEYFILE_PATH\" is not set."
exit 1
fi
###########################################################
# Main Function #
###########################################################
function box_ssh() {
local box_ip="$1"
ssh \
-i "${SSH_KEYFILE_PATH}" \
-o 'LogLevel=ERROR' \
-o 'StrictHostKeyChecking no' \
-o 'UserKnownHostsFile=/dev/null' \
"kiss@${box_ip}" ${@:2}
}
for cluster_name in $("$(dirname "$0")/ceph-ls.sh"); do
echo -n '* '
kubectl config use-context "${cluster_name}"
# Uninstall Rook-Ceph
if
kubectl \
--context "${cluster_name}" \
get namespace 'csi-rook-ceph' \
>/dev/null 2>/dev/null
then
pushd "${OPENARK_HOME}/templates/csi/rook-ceph/"
./uninstall.sh || true
popd
fi
# Cleanup Disks
for box_ip in $(
kubectl get nodes \
--context "${cluster_name}" \
--output jsonpath \
--template '{.items[?(@.status.conditions[-1].status == "True")].status.addresses[0].address}'
); do
echo " - Cleanup: ${box_ip}"
for box_disk_uuid in $(
box_ssh "${box_ip}" sudo lshw -class disk |
grep -Po 'logical name\: +/dev/\K[0-9a-z]+' |
sort
); do
# Skip if used disk
if
box_ssh "${box_ip}" ls -l /dev/disk/by-partuuid/ |
grep "/${box_disk_uuid}" >/dev/null
then
continue
fi
# Skip if not physical disk
if
! box_ssh "${box_ip}" ls -l /dev/disk/by-id/ |
grep "${box_disk_uuid}" >/dev/null
then
continue
fi
echo " - /dev/${box_disk_uuid}"
box_ssh "${box_ip}" sudo wipefs --all --force "/dev/${box_disk_uuid}" >/dev/null &&
box_ssh "${box_ip}" sync || true
box_ssh "${box_ip}" sudo sgdisk --zap-all "/dev/${box_disk_uuid}" >/dev/null &&
box_ssh "${box_ip}" sync || true
box_ssh "${box_ip}" sudo dd if='/dev/zero' of="/dev/${box_disk_uuid}" bs=1M count=1024 status=none &&
box_ssh "${box_ip}" sync || true
box_ssh "${box_ip}" sudo blkdiscard --force "/dev/${box_disk_uuid}" >/dev/null 2>/dev/null &&
box_ssh "${box_ip}" sync || true
box_ssh "${box_ip}" sudo partprobe "/dev/${box_disk_uuid}" >/dev/null &&
box_ssh "${box_ip}" sync || true
done
done
done
# Cleanup
kubectl config use-context 'default'
# Done
exec echo 'Finished!'