Cleanup ChartMuseum at undeploy NONRTRIC
[it/dep.git] / bin / undeploy-nonrtric
index 2a6c3fd..d6c827a 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/bash
 ################################################################################
-#   Copyright (c) 2020 Nordix Foundation.                                      #
+#   Copyright (c) 2023 Nordix Foundation.                                      #
+#   Copyright (C) 2024 OpenInfra Foundation Europe. All rights reserved.       #
 #                                                                              #
 #   Licensed under the Apache License, Version 2.0 (the "License");            #
 #   you may not use this file except in compliance with the License.           #
 ################################################################################
 
 # This script to undeploy the NONRTRIC
+ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
+echo "** $ROOT_DIR"
+
+COMPONENTS="controlpanel a1controller a1simulator policymanagementservice informationservice rappcatalogueservice rappcatalogueenhancedservice nonrtricgateway dmaapadapterservice dmaapmediatorservice helmmanager orufhrecovery ransliceassurance capifcore ranpm"
+RECIPE_NAMESPACE=$(kubectl get cm --all-namespaces | grep nonrtric-recipe | awk '{print $1}')
+kubectl get configmap  -n $RECIPE_NAMESPACE nonrtric-recipe  -o jsonpath='{.data.recipe}' > /tmp/recipe.yaml
+
+if [ ! -s /tmp/recipe.yaml ]; then
+    echo "NONRTRIC recipe is not found. Are you sure it's deployed successfully?"
+    exit 0
+fi
+
+COMMON_BLOCK=$(cat /tmp/recipe.yaml | awk '/^common:/{getline; while ($0 ~ /^ +.*|^ *$/) {print $0; if (getline == 0) {break}}}')
+NAMESPACE_BLOCK=$(cat /tmp/recipe.yaml | awk '/^  namespace:/{getline; while ($0 ~ /^    .*|^ *$/) {print $0; if (getline == 0) {break}}}')
+NONRTRIC_NAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *nonrtric:/{print $2}')
+RELEASE_PREFIX=$(echo "$COMMON_BLOCK" | awk '/^ *releasePrefix:/{print $2}')
+INSTALL_KONG=$(cat /tmp/recipe.yaml | awk '/^  installKong:/{print $2}')
+INSTALL_RANPM=$(cat /tmp/recipe.yaml | awk '/^  installRanpm:/{print $2}')
+
+if [ "$INSTALL_KONG" = true ];then
+   echo "Uninstalling Kong"
+   helm delete kong-nonrtric --namespace kong
+fi
 
 ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
-$ROOT_DIR/../nonrtric/bin/uninstall
+
+if [ "$INSTALL_RANPM" = true ];then
+   echo "Running uninstall-ranpm.sh"
+   chmod +x ${ROOT_DIR}/../ranpm/install/uninstall-ranpm.sh
+   ${ROOT_DIR}/../ranpm/install/uninstall-ranpm.sh
+   kubectl delete ns ran
+   echo "uninstall-ranpm.sh completed"
+fi
+
+echo "Undeploying NONRTRIC components [$COMPONENTS]"
+
+IS_HELM3=$(helm version -c --short|grep -e "^v3")
+HELM_FLAG=''
+if [ $IS_HELM3 ]
+then
+  HELM_FLAG=' -n '${NONRTRIC_NAMESPACE:-nonrtric}
+else
+  HELM_FLAG='--purge'
+fi
+
+helm delete ${HELM_FLAG} ${RELEASE_PREFIX}
+
+kubectl delete cm -n ${NONRTRIC_NAMESPACE:-nonrtric} nonrtric-recipe
+
+kubectl delete ns ${NONRTRIC_NAMESPACE:-nonrtric}
+
+kubectl delete ns onap
+
+# Cleanup ChartMuseum
+CM_PID_FILE="$ROOT_DIR/CM_PID.txt"
+if [ -f $CM_PID_FILE ]; then
+  echo "Cleaning up ChartMuseum..."
+  PID=$(cat "$CM_PID_FILE")
+  echo "Killing ChartMuseum with PID $PID"
+  kill $PID
+  rm $CM_PID_FILE
+  echo "ChartMuseum cleanup completed"
+fi