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