From 6205e070699bff4bc2aac0ff32fd757178d1e682 Mon Sep 17 00:00:00 2001 From: Vineet Badrinath Date: Fri, 11 Mar 2022 17:27:47 +0530 Subject: [PATCH] Cleanup for DR Resources This commit adds a script for cleaning up DR resources from hub and spoke cluster Signed-off-by: Vineet Badrinath --- clean.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 clean.sh diff --git a/clean.sh b/clean.sh new file mode 100755 index 00000000..82aa13a7 --- /dev/null +++ b/clean.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +SECRET_LABEL_KEY="multicluster.odf.openshift.io/secret-type" +SOURCE_LABEL="BLUE" +DESTINATION_LABEL="GREEN" +INTERNAL_LABEL="INTERNAL" +IGNORE_LABEL="IGNORE" +RAMEN_HUB_NAMESPACE="openshift-dr-system" + +function clean-hub-cluster { + echo "Cleaning up hub cluster" + oc delete mirrorpeers --all + for NAMESPACE in "$@"; do + oc delete managedclusteraddon tokenexchange -n "${NAMESPACE}" + echo "$SECRET_LABEL_KEY in ($SOURCE_LABEL, $DESTINATION_LABEL, $INTERNAL_LABEL, $IGNORE_LABEL)" + oc delete secrets -l "$SECRET_LABEL_KEY in ($SOURCE_LABEL, $DESTINATION_LABEL, $INTERNAL_LABEL, $IGNORE_LABEL)" -n "${NAMESPACE}" + done +} + + +function clean-spoke-cluster { + echo "Cleaning spoke cluster" + + # Delete all VolumeReplicationClasses + oc delete vrcs --all + + # Delete all Object Bucket Claims that contain "odrbucket" + oc get obc -n ${RAMEN_HUB_NAMESPACE} --no-headers=true | awk '/odrbucket/{print $1}'| xargs oc delete -n ${RAMEN_HUB_NAMESPACE} obc +} + +while getopts "h:s:" op; do + case "${op}" in + h) + echo "Cleaning up DR Resources in hub cluster" + export KUBECONFIG="$OPTARG" + shift 2 + clean-hub-cluster "$@" + ;; + s) + echo "Cleaning up DR Resources in spoke cluster" + export KUBECONFIG="$OPTARG" + shift 2 + clean-spoke-cluster "$@" + ;; + *) + echo "Invalid option" + esac +done \ No newline at end of file