Fix ACM installation to support kafka
[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 #  Copyright (C) 2023-2024 OpenInfra Foundation Europe. All rights reserved.
6 #  ========================================================================
7 #  Licensed under the Apache License, Version 2.0 (the "License");
8 #  you may not use this file except in compliance with the License.
9 #  You may obtain a copy of the License at
10 #
11 #       http://www.apache.org/licenses/LICENSE-2.0
12 #
13 #  Unless required by applicable law or agreed to in writing, software
14 #  distributed under the License is distributed on an "AS IS" BASIS,
15 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 #  See the License for the specific language governing permissions and
17 #  limitations under the License.
18 #  ============LICENSE_END=================================================
19 #
20
21 echo "######### Installing ACM components #########"
22
23 ENABLE_COMPONENTS=(policy-models-simulator policy-clamp-runtime-acm policy-clamp-ac-kserve-ppnt policy-clamp-ac-k8s-ppnt policy-clamp-ac-a1pms-ppnt)
24 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)
25
26 ACM_VALUES_FILE="docker/helm/policy/values.yaml"
27 A1PMS_CONFIGURATION_FILE="docker/helm/policy/components/policy-clamp-ac-a1pms-ppnt/resources/config/A1pmsParticipantParameters.yaml"
28 K8S_CONFIGURATION_FILE="docker/helm/policy/components/policy-clamp-ac-k8s-ppnt/values.yaml"
29 K8S_VERSIONS_FILE="docker/compose/get-k8s-versions.sh"
30 KAFKA_DIR="docker/helm/cp-kafka"
31
32 IP_ADDRESS=$(hostname -I | awk '{print $1}')
33 echo "IP Address : $IP_ADDRESS"
34
35 A1PMS_HOST=${A1PMS_HOST:-http://policymanagementservice.nonrtric:9080}
36 CHART_REPO_HOST=${CHART_REPO_HOST:-'http://'$IP_ADDRESS':8879/charts'}
37
38 function wait_for_pods_to_be_running() {
39     while [[ $TIME -lt 2000 ]]; do
40       NONRTRIC_PODS=$(kubectl get pods -n default --field-selector=status.phase!=Running,status.phase!=Succeeded --no-headers)
41       if [[ -z "$NONRTRIC_PODS" ]]; then
42         echo "All Components are running."
43         kubectl get pods -n default
44         break
45       fi
46
47       echo "Waiting for the below Components to be running..."
48       echo "$NONRTRIC_PODS"
49       TIME=$(expr $TIME + 5)
50       sleep 5
51     done
52 }
53
54 git clone "https://gerrit.onap.org/r/policy/docker"
55
56 CWD=$(pwd)
57 export WORKSPACE="$CWD/docker"
58
59 #Temporary workaround, Should be removed once https://gerrit.onap.org/r/c/policy/docker/+/137075 or similar change is merged
60 echo "Updating kafka advertised listeners..."
61 sed -i 's|PLAINTEXT_INTERNAL://kafka:9092|PLAINTEXT_INTERNAL://kafka.default.svc.cluster.local:9092|g' $KAFKA_DIR/kafka.yaml
62
63 # Kafka installation
64 echo "Installing Confluent kafka"
65 kubectl apply -f $KAFKA_DIR/zookeeper.yaml
66 kubectl apply -f $KAFKA_DIR/kafka.yaml
67 wait_for_pods_to_be_running
68
69 #Temporary workaround. Should be removed once this gets fixed in policy/docker repo
70 echo "Update policy-db-migrator version..."
71 yq eval '.dbmigrator.image="onap/policy-db-migrator:3.1-SNAPSHOT-latest"' -i $ACM_VALUES_FILE
72
73 echo "Updating policy docker image versions..."
74 bash $K8S_VERSIONS_FILE
75
76 echo "Enabling the access for the clusterroles..."
77 kubectl apply -f resources/acm-role-binding.yaml
78
79 for element in "${ENABLE_COMPONENTS[@]}"; do
80   echo "Enabling component $element"
81   yq eval ".$element.enabled"="true" -i $ACM_VALUES_FILE
82 done
83
84 for element in "${DISABLE_COMPONENTS[@]}"; do
85   echo "Disabling component $element"
86   yq eval ".$element.enabled"="false" -i $ACM_VALUES_FILE
87 done
88
89 echo "Updating A1PMS Participant"
90
91 #Temporary workaround, Should be removed once https://gerrit.onap.org/r/c/policy/docker/+/137075 or similar change is merged
92 sed -i 's|{{ \.Values\.global\.kafkaServer }}:9092|"\0"|g' $A1PMS_CONFIGURATION_FILE
93
94 yq eval '.a1pms.baseUrl="'$A1PMS_HOST'"' -i $A1PMS_CONFIGURATION_FILE
95
96 echo "Updating the k8s participant repo list"
97 yq eval '.repoList.helm.repos += {"repoName":"local","address":"'$CHART_REPO_HOST'"}' -i $K8S_CONFIGURATION_FILE
98
99 echo "Building policy helm charts..."
100 helm dependency build docker/helm/policy/
101
102 echo "Installing policy helm charts..."
103 helm install csit-policy docker/helm/policy/ -n default
104
105 wait_for_pods_to_be_running
106
107 echo "ACM Components Installation Completed."