Move sample rApp resources to seperate directory
[nonrtric/plt/rappmanager.git] / scripts / install / install-acm.sh
1 #!/bin/bash
2
3 #  ============LICENSE_START===============================================
4 #  Copyright (C) 2023 Nordix Foundation. 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 #  ============LICENSE_END=================================================
18 #
19
20 echo "######### Installing ACM components #########"
21
22 ENABLE_COMPONENTS=(policy-models-simulator policy-clamp-runtime-acm policy-clamp-ac-kserve-ppnt policy-clamp-ac-k8s-ppnt policy-clamp-ac-a1pms-ppnt)
23 DISABLE_COMPONENTS=(policy-api policy-pap policy-apex-pdp policy-pdpd-cl policy-xacml-pdp policy-distribution policy-clamp-ac-pf-ppnt policy-clamp-ac-http-ppnt)
24
25 ACM_VALUES_FILE="docker/helm/policy/values.yaml"
26 A1PMS_CONFIGURATION_FILE="docker/helm/policy/components/policy-clamp-ac-a1pms-ppnt/resources/config/A1pmsParticipantParameters.yaml"
27 K8S_CONFIGURATION_FILE="docker/helm/policy/components/policy-clamp-ac-k8s-ppnt/values.yaml"
28 K8S_VERSIONS_FILE="docker/compose/get-k8s-versions.sh"
29
30 IP_ADDRESS=$(hostname -I | awk '{print $1}')
31 echo "IP Address : $IP_ADDRESS"
32
33 git clone "https://gerrit.onap.org/r/policy/docker"
34
35 CWD=$(pwd)
36 export WORKSPACE="$CWD/docker"
37
38 #Temporary workaround. Should be removed once this gets fixed in policy/docker repo
39 echo "Update policy-db-migrator version..."
40 yq eval '.dbmigrator.image="onap/policy-db-migrator:3.0-SNAPSHOT-latest"' -i $ACM_VALUES_FILE
41 sed -i 's/component=policy-clamp-ac-kserve-ppnt/component=policy-clamp-ac-sim-ppnt/g' $K8S_VERSIONS_FILE
42 PARAMETER_STRING="metrics:\n  security:\n    disabled: false"
43 echo -e "$PARAMETER_STRING" >> docker/helm/policy/components/policy-clamp-runtime-acm/resources/config/acRuntimeParameters.yaml
44
45 echo "Updating policy docker image versions..."
46 bash $K8S_VERSIONS_FILE
47
48 echo "Enabling the access for the clusterroles..."
49 kubectl apply -f resources/acm-role-binding.yaml
50
51 for element in "${ENABLE_COMPONENTS[@]}"; do
52   echo "Enabling component $element"
53   yq eval ".$element.enabled"="true" -i $ACM_VALUES_FILE
54 done
55
56 for element in "${DISABLE_COMPONENTS[@]}"; do
57   echo "Disabling component $element"
58   yq eval ".$element.enabled"="false" -i $ACM_VALUES_FILE
59 done
60
61 echo "Updating A1PMS Participant"
62 yq eval '.a1pms.baseUrl="http://policymanagementservice.nonrtric:9080"' -i $A1PMS_CONFIGURATION_FILE
63
64 echo "Updating the k8s participant repo list"
65 yq eval '.repoList.helm.repos += {"repoName":"local","address":"http://'$IP_ADDRESS':8879/charts"}' -i $K8S_CONFIGURATION_FILE
66
67 echo "Building policy helm charts..."
68 helm dependency build docker/helm/policy/
69
70 echo "Installing policy helm charts..."
71 helm install csit-policy docker/helm/policy/ -n default
72
73 while [[ $TIME -lt 2000 ]]; do
74   NONRTRIC_PODS=$(kubectl get pods -n default --field-selector=status.phase!=Running,status.phase!=Succeeded --no-headers)
75   if [[ -z "$NONRTRIC_PODS" ]]; then
76     echo "All ACM Components are running."
77     kubectl get pods -n default
78     break
79   fi
80
81   echo "Waiting for ACM Components to be running..."
82   echo "These pods are not running"
83   echo "$NONRTRIC_PODS"
84   TIME=$(expr $TIME + 5)
85   sleep 5
86 done
87
88 echo "ACM Components Installation Completed."