Add uninstallation scripts 60/1960/2
authorjingzhao <Jingzhao.Ni@arm.com>
Tue, 12 Nov 2019 13:47:04 +0000 (21:47 +0800)
committerjingzhao <Jingzhao.Ni@arm.com>
Wed, 13 Nov 2019 06:41:59 +0000 (14:41 +0800)
In this patch, some un-install scripts were added into IEC project.
It will be used for removing the iec infrastructure from K8s Master
node and slave node.

Signed-off-by: jingzhao <Jingzhao.Ni@arm.com>
Change-Id: I8a300a0b3f8a3121c62e881e722958c793945b7c

src/foundation/scripts/nginx.sh
src/foundation/scripts/uninstall.sh [new file with mode: 0644]

index 3e419b9..96ee728 100755 (executable)
@@ -61,7 +61,7 @@ done
 [ $attempts -gt 0 ] || exit 1
 
 svcip=$(kubectl get services nginx  -o json | grep clusterIP | cut -f4 -d'"')
 [ $attempts -gt 0 ] || exit 1
 
 svcip=$(kubectl get services nginx  -o json | grep clusterIP | cut -f4 -d'"')
-sleep 10
+sleep 20
 wget -O /dev/null "http://$svcip"
 kubectl delete -f "${NGINX_APP}"
 rm -f "${NGINX_APP}"
 wget -O /dev/null "http://$svcip"
 kubectl delete -f "${NGINX_APP}"
 rm -f "${NGINX_APP}"
diff --git a/src/foundation/scripts/uninstall.sh b/src/foundation/scripts/uninstall.sh
new file mode 100644 (file)
index 0000000..550cc5c
--- /dev/null
@@ -0,0 +1,100 @@
+#!/bin/bash
+set -x
+#Uninstall the k8s-master & k8s-worker node from Mgnt node
+#
+
+# Get OS version
+if grep -q -e rhel /etc/*-release; then
+  OS_ID_LIKE=${1:-rhel}
+elif grep -q -e debian /etc/*-release; then
+  OS_ID_LIKE=${1:-debian}
+fi
+
+#
+# Destroy k8s.
+#
+Destroy_k8s(){
+
+  KUBEADM_DESTROY_CMD="kubeadm reset -f"
+
+  for worker in "${K8S_WORKER_GROUP[@]}"
+  do
+    ip_addr="$(cut -d',' -f1 <<<${worker})"
+    passwd="$(cut -d',' -f2 <<<${worker})"
+    echo "Destroy k8s on ${ip_addr}. password:${passwd}"
+
+    sshpass -p ${passwd} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${ip_addr} ${KUBEADM_DESTROY_CMD}
+    sleep 2
+  done
+
+  #Destroy master k8s env
+  sshpass -p ${K8S_MASTERPW} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${K8S_MASTER_IP} ${KUBEADM_DESTROY_CMD}
+}
+
+
+#
+# Uninstall software.
+#
+Uninstall () {
+  OS_VERSION=$1
+  case ${OS_VERSION:-} in
+  debian)
+    UNINSTALL_CMD="sudo apt purge -y kubernetes-cni kubeadm kubectl kubelet kube* docker-ce --allow-change-held-packages &&\
+              sudo apt -y autoremove"
+    ;;
+  rhel)
+    UNINSTALL_CMD="sudo yum remove -y kubeadm kubectl kubelet kubernetes-cni kube* docker-ce &&\
+               sudo yum -y autoremove"
+    ;;
+  *)
+    echo 'Unsupported distribution detected!'
+    exit 1
+    ;;
+  esac
+
+  for worker in "${K8S_WORKER_GROUP[@]}"
+  do
+    ip_addr="$(cut -d',' -f1 <<<${worker})"
+    passwd="$(cut -d',' -f2 <<<${worker})"
+    echo "Destroy k8s on ${ip_addr}. password:${passwd}"
+
+    sshpass -p ${passwd} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${ip_addr} "${UNINSTALL_CMD}"
+    sleep 2
+  done
+
+  #master k8s env
+  sshpass -p ${K8S_MASTERPW} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${K8S_MASTER_IP} "${UNINSTALL_CMD}"
+}
+
+
+#
+# Recover system configuration.
+#
+Recover_conf(){
+
+  REC_CMD="sudo swapon -a"
+
+  for worker in "${K8S_WORKER_GROUP[@]}"
+  do
+    ip_addr="$(cut -d',' -f1 <<<${worker})"
+    passwd="$(cut -d',' -f2 <<<${worker})"
+    echo "Destroy k8s on ${ip_addr}. password:${passwd}"
+
+    sshpass -p ${passwd} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${ip_addr} "${REC_CMD}"
+    sleep 2
+  done
+
+  #master k8s env
+  sshpass -p ${K8S_MASTERPW} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${K8S_MASTER_IP} "${REC_CMD}"
+}
+
+# Read the configuration file
+source config
+
+Destroy_k8s ${OS_ID_LIKE}
+
+Uninstall ${OS_ID_LIKE}
+sleep 10
+
+Recover_conf ${OS_ID_LIKE}
+sleep 20