diff options
author | James Gu <james.gu@att.com> | 2020-05-04 13:57:29 -0700 |
---|---|---|
committer | James Gu <james.gu@att.com> | 2020-10-05 21:25:18 +0000 |
commit | da4f1540dec64779c01f7d0258b1a748ace9b131 (patch) | |
tree | 47856f75607849dc848dadcbcb1a7d048f91f7f7 /tools/clean-genesis.sh | |
parent | 05686a28172cd3e79c71987cf495e0e67e064eb1 (diff) |
Treasuremap 1.8 integration
Upgrade pod 17 to Treasuremap 1.8 prime for CNTT RI-1.
Added deploy script enhancement to include pregenesis, certs, and wrapper
for shipyard cli command.
Added clean-genesis script to properly clean genesis node for redeployment.
Signed-off-by: James Gu <james.gu@att.com>
Change-Id: I4c150ef216d5eb631a0980c72b3c6c80a55788d0
Signed-off-by: James Gu <james.gu@att.com>
Diffstat (limited to 'tools/clean-genesis.sh')
-rw-r--r-- | tools/clean-genesis.sh | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/tools/clean-genesis.sh b/tools/clean-genesis.sh new file mode 100644 index 0000000..4d18f78 --- /dev/null +++ b/tools/clean-genesis.sh @@ -0,0 +1,158 @@ +#!/bin/bash + +set -x + +log () { + printf "$(date)\t%s\n" "${1}" +} + +TO_RM=( + "/etc/cni" + "/etc/coredns" + "/etc/etcd" + "/etc/genesis" + "/etc/kubernetes" + "/etc/promenade" + "/etc/systemd/system/kubelet.service" + "/home/ceph" + "/tmp/tmp.*" + "/var/lib/etcd" + "/var/lib/kubelet" + "/var/lib/openstack-helm" + "/var/log/containers" + "/var/log/pods" + "/var/log/armada" + "/etc/modprobe.d/krbd_blacklist.conf" + "/srv/elasticsearch-data" + "/srv/elasticsearch-master" + "/srv/prometheus-data" +) + +prune_docker() { + log "Docker prune" + docker volume prune -f + docker system prune -a -f +} + +remove_containers() { + log "Remove all Docker containers" + docker ps -aq 2> /dev/null | xargs --no-run-if-empty docker rm -fv + log "Remove all containerd pods" + systemctl restart containerd || true + sleep 60 + crictl rmp -a -f || true + log "Remove any remaining containerd containers" + crictl rm -a -f || true + systemctl stop containerd || true +} + +remove_files() { + for item in "${TO_RM[@]}"; do + log "Removing ${item}" + rm -rf "${item}" + done +} + +reset_docker() { + log "Remove all local Docker images" + docker images -qa | xargs --no-run-if-empty docker rmi -f + log "Remove remaining Docker files" + systemctl stop docker + if ! rm -rf /var/lib/docker/*; then + log "Failed to cleanup some files in /var/lib/docker" + find /var/lib/docker + fi + log "Remove all local containerd data" + if ! rm -rf /var/lib/containerd/*; then + log "Failed to cleanup some files in /var/lib/containerd/" + find /var/lib/containerd + fi +} + +stop_kubelet() { + log "Stop Kubelet and clean pods" + systemctl stop kubelet || true + # Issue with orhan PODS + # https://github.com/kubernetes/kubernetes/issues/38498 + find /var/lib/kubelet/pods 2> /dev/null | while read orphan_pod; do + if [[ ${orphan_pod} == *io~secret/* ]] || [[ ${orphan_pod} == *empty-dir/* ]]; then + umount "${orphan_pod}" || true + rm -rf "${orphan_pod}" + fi + done +} + +wipe_disk() { + CEPH_VG=$(vgs | tail -n +1 | awk '{print $1}' | grep ceph-vg- | paste -d " " - -) + + if [[ x$CEPH_VG != 'x' ]]; then + vgremove -f $CEPH_VG + fi + + log "Wipe out CEPH disks" + apt install --yes gdisk + echo "====Earsing disk sdb====" + sudo sgdisk -Z /dev/sdb + sudo dd if=/dev/zero of=/dev/sdb bs=1M count=200 +} + +service_exists() { + local n=$1 + if [[ $(systemctl list-units --all -t service --full --no-legend "$n.service" | cut -f1 -d' ') == $n.service ]]; then + return 0 + else + return 1 + fi +} + +FORCE=0 +RESET_DOCKER=0 +while getopts "fk" opt; do + case "${opt}" in + f) + FORCE=1 + ;; + k) + RESET_DOCKER=1 + ;; + *) + echo "Unknown option" + exit 1 + ;; + esac +done + +if [[ $FORCE == "0" ]]; then + echo Warning: This cleanup script is very aggresive. Run with -f to avoid this prompt. + while true; do + read -p "Are you sure you wish to proceed with aggressive cleanup?" yn + case $yn in + [Yy]*) + RESET_DOCKER=1 + break + ;; + *) + echo Exitting. + exit 1 + esac + done +fi + +if service_exists kubelet; then + stop_kubelet + remove_containers + remove_files + prune_docker + systemctl daemon-reload + systemctl start containerd.service + if [[ $RESET_DOCKER == "1" ]]; then + echo "hi" + reset_docker + fi + systemctl start containerd +#sudo crictl pull docker.io/busybox:1.28.3 +#sudo crictl pull docker.io/haproxy:1.8.19 + service docker restart +fi +wipe_disk + |