Cleanup ChartMuseum at undeploy NONRTRIC
[it/dep.git] / bin / undeploy-nonrtric
1 #!/bin/bash
2 ################################################################################
3 #   Copyright (c) 2023 Nordix Foundation.                                      #
4 #   Copyright (C) 2024 OpenInfra Foundation Europe. All rights reserved.       #
5 #                                                                              #
6 #   Licensed under the Apache License, Version 2.0 (the "License");            #
7 #   you may not use this file except in compliance with the License.           #
8 #   You may obtain a copy of the License at                                    #
9 #                                                                              #
10 #       http://www.apache.org/licenses/LICENSE-2.0                             #
11 #                                                                              #
12 #   Unless required by applicable law or agreed to in writing, software        #
13 #   distributed under the License is distributed on an "AS IS" BASIS,          #
14 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
15 #   See the License for the specific language governing permissions and        #
16 #   limitations under the License.                                             #
17 ################################################################################
18
19 # This script to undeploy the NONRTRIC
20 ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
21 echo "** $ROOT_DIR"
22
23 COMPONENTS="controlpanel a1controller a1simulator policymanagementservice informationservice rappcatalogueservice rappcatalogueenhancedservice nonrtricgateway dmaapadapterservice dmaapmediatorservice helmmanager orufhrecovery ransliceassurance capifcore ranpm"
24 RECIPE_NAMESPACE=$(kubectl get cm --all-namespaces | grep nonrtric-recipe | awk '{print $1}')
25 kubectl get configmap  -n $RECIPE_NAMESPACE nonrtric-recipe  -o jsonpath='{.data.recipe}' > /tmp/recipe.yaml
26
27 if [ ! -s /tmp/recipe.yaml ]; then
28     echo "NONRTRIC recipe is not found. Are you sure it's deployed successfully?"
29     exit 0
30 fi
31
32 COMMON_BLOCK=$(cat /tmp/recipe.yaml | awk '/^common:/{getline; while ($0 ~ /^ +.*|^ *$/) {print $0; if (getline == 0) {break}}}')
33 NAMESPACE_BLOCK=$(cat /tmp/recipe.yaml | awk '/^  namespace:/{getline; while ($0 ~ /^    .*|^ *$/) {print $0; if (getline == 0) {break}}}')
34 NONRTRIC_NAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *nonrtric:/{print $2}')
35 RELEASE_PREFIX=$(echo "$COMMON_BLOCK" | awk '/^ *releasePrefix:/{print $2}')
36 INSTALL_KONG=$(cat /tmp/recipe.yaml | awk '/^  installKong:/{print $2}')
37 INSTALL_RANPM=$(cat /tmp/recipe.yaml | awk '/^  installRanpm:/{print $2}')
38
39 if [ "$INSTALL_KONG" = true ];then
40    echo "Uninstalling Kong"
41    helm delete kong-nonrtric --namespace kong
42 fi
43
44 ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
45
46 if [ "$INSTALL_RANPM" = true ];then
47    echo "Running uninstall-ranpm.sh"
48    chmod +x ${ROOT_DIR}/../ranpm/install/uninstall-ranpm.sh
49    ${ROOT_DIR}/../ranpm/install/uninstall-ranpm.sh
50    kubectl delete ns ran
51    echo "uninstall-ranpm.sh completed"
52 fi
53
54 echo "Undeploying NONRTRIC components [$COMPONENTS]"
55
56 IS_HELM3=$(helm version -c --short|grep -e "^v3")
57 HELM_FLAG=''
58 if [ $IS_HELM3 ]
59 then
60   HELM_FLAG=' -n '${NONRTRIC_NAMESPACE:-nonrtric}
61 else
62   HELM_FLAG='--purge'
63 fi
64
65 helm delete ${HELM_FLAG} ${RELEASE_PREFIX}
66
67 kubectl delete cm -n ${NONRTRIC_NAMESPACE:-nonrtric} nonrtric-recipe
68
69 kubectl delete ns ${NONRTRIC_NAMESPACE:-nonrtric}
70
71 kubectl delete ns onap
72
73 # Cleanup ChartMuseum
74 CM_PID_FILE="$ROOT_DIR/CM_PID.txt"
75 if [ -f $CM_PID_FILE ]; then
76   echo "Cleaning up ChartMuseum..."
77   PID=$(cat "$CM_PID_FILE")
78   echo "Killing ChartMuseum with PID $PID"
79   kill $PID
80   rm $CM_PID_FILE
81   echo "ChartMuseum cleanup completed"
82 fi