rameshiyer27 | a1954d4 | 2022-11-14 06:00:12 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # ============LICENSE_START==================================================== |
rameshiyer27 | f2e4da7 | 2024-01-13 21:26:09 +0000 | [diff] [blame] | 4 | # Copyright (C) 2022-2024 Nordix Foundation. |
rameshiyer27 | a1954d4 | 2022-11-14 06:00:12 +0000 | [diff] [blame] | 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 | # SPDX-License-Identifier: Apache-2.0 |
| 19 | # ============LICENSE_END====================================================== |
| 20 | |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 21 | # This script spins up kubernetes cluster in Microk8s for deploying policy helm charts. |
| 22 | # Runs CSITs in kubernetes. |
rameshiyer27 | 0700486 | 2023-01-23 11:50:01 +0000 | [diff] [blame] | 23 | |
rameshiyer27 | f575f92 | 2023-10-12 15:11:02 +0100 | [diff] [blame] | 24 | WORKSPACE=$(git rev-parse --show-toplevel) |
| 25 | export WORKSPACE |
adheli.tavares | 1153b6d | 2023-02-28 12:59:37 +0000 | [diff] [blame] | 26 | |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 27 | export GERRIT_BRANCH=$(awk -F= '$1 == "defaultbranch" { print $2 }' "${WORKSPACE}"/.gitreview) |
rameshiyer27 | d8f9180 | 2023-03-07 01:32:28 +0000 | [diff] [blame] | 28 | |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 29 | CSIT_SCRIPT="scripts/run-test.sh" |
| 30 | ROBOT_DOCKER_IMAGE="policy-csit-robot" |
rameshiyer27 | 3397d84 | 2024-08-18 11:12:23 +0100 | [diff] [blame^] | 31 | POLICY_CLAMP_ROBOT="policy-clamp-test.robot clamp-slas.robot" |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 32 | POLICY_API_ROBOT="api-test.robot api-slas.robot" |
| 33 | POLICY_PAP_ROBOT="pap-test.robot pap-slas.robot" |
| 34 | POLICY_APEX_PDP_ROBOT="apex-pdp-test.robot apex-slas.robot" |
| 35 | POLICY_XACML_PDP_ROBOT="xacml-pdp-test.robot" |
| 36 | POLICY_DROOLS_PDP_ROBOT="drools-pdp-test.robot" |
| 37 | POLICY_DISTRIBUTION_ROBOT="distribution-test.robot" |
rameshiyer27 | 0700486 | 2023-01-23 11:50:01 +0000 | [diff] [blame] | 38 | |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 39 | POLICY_API_CONTAINER="policy-api" |
| 40 | POLICY_PAP_CONTAINER="policy-pap" |
| 41 | POLICY_CLAMP_CONTAINER="policy-clamp-runtime-acm" |
| 42 | POLICY_APEX_CONTAINER="policy-apex-pdp" |
| 43 | POLICY_DROOLS_CONTAINER="policy-drools-pdp" |
| 44 | POLICY_XACML_CONTAINER="policy-xacml-pdp" |
| 45 | POLICY_DISTRIBUTION_CONTAINER="policy-distribution" |
| 46 | POLICY_K8S_PPNT_CONTAINER="policy-clamp-ac-k8s-ppnt" |
| 47 | POLICY_HTTP_PPNT_CONTAINER="policy-clamp-ac-http-ppnt" |
FrancescoFioraEst | 8fadfb9 | 2024-04-17 11:42:58 +0100 | [diff] [blame] | 48 | POLICY_SIM_PPNT_CONTAINER="policy-clamp-ac-sim-ppnt" |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 49 | POLICY_PF_PPNT_CONTAINER="policy-clamp-ac-pf-ppnt" |
saul.gill | 54d234d | 2024-06-27 17:22:12 +0100 | [diff] [blame] | 50 | JAEGER_CONTAINER="jaeger" |
rameshiyer27 | 31c61d4 | 2024-01-21 14:24:03 +0000 | [diff] [blame] | 51 | KAFKA_CONTAINER="kafka-deployment" |
| 52 | ZK_CONTAINER="zookeeper-deployment" |
| 53 | KAFKA_DIR=${WORKSPACE}/helm/cp-kafka |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 54 | SET_VALUES="" |
rameshiyer27 | a1954d4 | 2022-11-14 06:00:12 +0000 | [diff] [blame] | 55 | |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 56 | DISTRIBUTION_CSAR=${WORKSPACE}/csit/resources/tests/data/csar |
| 57 | DIST_TEMP_FOLDER=/tmp/distribution |
rameshiyer27 | a1954d4 | 2022-11-14 06:00:12 +0000 | [diff] [blame] | 58 | |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 59 | export PROJECT="" |
| 60 | export ROBOT_FILE="" |
| 61 | export ROBOT_LOG_DIR=${WORKSPACE}/csit/archives |
| 62 | export READINESS_CONTAINERS=() |
| 63 | |
rameshiyer27 | 31c61d4 | 2024-01-21 14:24:03 +0000 | [diff] [blame] | 64 | |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 65 | function spin_microk8s_cluster() { |
| 66 | echo "Verify if Microk8s cluster is running.." |
| 67 | microk8s version |
| 68 | exitcode="${?}" |
| 69 | |
| 70 | if [ "$exitcode" -ne 0 ]; then |
| 71 | echo "Microk8s cluster not available, Spinning up the cluster.." |
rameshiyer27 | a4530ef | 2024-07-01 15:35:39 +0000 | [diff] [blame] | 72 | sudo snap install microk8s --classic --channel=1.30/stable |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 73 | |
| 74 | if [ "${?}" -ne 0 ]; then |
| 75 | echo "Failed to install kubernetes cluster. Aborting.." |
| 76 | return 1 |
| 77 | fi |
| 78 | echo "Microk8s cluster installed successfully" |
| 79 | sudo usermod -a -G microk8s $USER |
rameshiyer27 | a4530ef | 2024-07-01 15:35:39 +0000 | [diff] [blame] | 80 | echo "Enabling DNS and Storage plugins" |
| 81 | sudo microk8s.enable dns hostpath-storage |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 82 | echo "Creating configuration file for Microk8s" |
| 83 | sudo mkdir -p $HOME/.kube |
| 84 | sudo chown -R $USER:$USER $HOME/.kube |
| 85 | sudo microk8s kubectl config view --raw >$HOME/.kube/config |
| 86 | sudo chmod 600 $HOME/.kube/config |
| 87 | echo "K8s installation completed" |
| 88 | echo "----------------------------------------" |
| 89 | else |
| 90 | echo "K8s cluster is already running" |
| 91 | echo "----------------------------------------" |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 92 | fi |
| 93 | |
FrancescoFioraEst | 8fadfb9 | 2024-04-17 11:42:58 +0100 | [diff] [blame] | 94 | echo "Verify if kubectl is running.." |
| 95 | kubectl version |
| 96 | exitcode="${?}" |
| 97 | |
| 98 | if [ "$exitcode" -ne 0 ]; then |
rameshiyer27 | a4530ef | 2024-07-01 15:35:39 +0000 | [diff] [blame] | 99 | echo "Kubectl not available, Installing.." |
| 100 | sudo snap install kubectl --classic --channel=1.30/stable |
FrancescoFioraEst | 8fadfb9 | 2024-04-17 11:42:58 +0100 | [diff] [blame] | 101 | |
| 102 | if [ "${?}" -ne 0 ]; then |
| 103 | echo "Failed to install Kubectl. Aborting.." |
| 104 | return 1 |
| 105 | fi |
| 106 | echo "Kubectl installation completed" |
| 107 | echo "----------------------------------------" |
| 108 | else |
| 109 | echo "Kubectl is already running" |
| 110 | echo "----------------------------------------" |
| 111 | return 0 |
| 112 | fi |
rameshiyer27 | a4530ef | 2024-07-01 15:35:39 +0000 | [diff] [blame] | 113 | |
| 114 | echo "Verify if helm is running.." |
| 115 | helm version |
| 116 | exitcode="${?}" |
| 117 | |
| 118 | if [ "$exitcode" -ne 0 ]; then |
| 119 | echo "Helm not available, Installing.." |
| 120 | sudo snap install helm --classic --channel=3.7 |
| 121 | |
| 122 | if [ "${?}" -ne 0 ]; then |
| 123 | echo "Failed to install Helm client. Aborting.." |
| 124 | return 1 |
| 125 | fi |
| 126 | echo "Helm installation completed" |
| 127 | echo "----------------------------------------" |
| 128 | else |
| 129 | echo "Helm is already running" |
| 130 | echo "----------------------------------------" |
| 131 | return 0 |
| 132 | fi |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 133 | } |
| 134 | |
rameshiyer27 | 31c61d4 | 2024-01-21 14:24:03 +0000 | [diff] [blame] | 135 | function install_kafka() { |
| 136 | echo "Installing Confluent kafka" |
| 137 | kubectl apply -f $KAFKA_DIR/zookeeper.yaml |
| 138 | kubectl apply -f $KAFKA_DIR/kafka.yaml |
| 139 | echo "----------------------------------------" |
| 140 | } |
| 141 | |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 142 | function uninstall_policy() { |
| 143 | echo "Removing the policy helm deployment" |
rameshiyer27 | a4530ef | 2024-07-01 15:35:39 +0000 | [diff] [blame] | 144 | sudo helm uninstall csit-policy |
| 145 | sudo helm uninstall prometheus |
| 146 | sudo helm uninstall csit-robot |
rameshiyer27 | 31c61d4 | 2024-01-21 14:24:03 +0000 | [diff] [blame] | 147 | sudo kubectl delete deploy $ZK_CONTAINER $KAFKA_CONTAINER |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 148 | rm -rf ${WORKSPACE}/helm/policy/Chart.lock |
| 149 | if [ "$PROJECT" == "clamp" ] || [ "$PROJECT" == "policy-clamp" ]; then |
rameshiyer27 | a4530ef | 2024-07-01 15:35:39 +0000 | [diff] [blame] | 150 | sudo helm uninstall policy-chartmuseum |
| 151 | sudo helm repo remove chartmuseum-git policy-chartmuseum |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 152 | fi |
| 153 | sudo rm -rf /dockerdata-nfs/mariadb-galera/ |
rameshiyer27 | a4530ef | 2024-07-01 15:35:39 +0000 | [diff] [blame] | 154 | sudo kubectl delete pvc --all |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 155 | echo "Policy deployment deleted" |
| 156 | echo "Clean up docker" |
| 157 | docker image prune -f |
| 158 | } |
| 159 | |
| 160 | function teardown_cluster() { |
| 161 | echo "Removing k8s cluster and k8s configuration file" |
| 162 | sudo snap remove microk8s;rm -rf $HOME/.kube/config |
rameshiyer27 | a4530ef | 2024-07-01 15:35:39 +0000 | [diff] [blame] | 163 | sudo snap remove helm; |
| 164 | sudo snap remove kubectl; |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 165 | echo "MicroK8s Cluster removed" |
| 166 | } |
| 167 | |
| 168 | function build_robot_image() { |
| 169 | echo "Build docker image for robot framework" |
| 170 | cd ${WORKSPACE}/csit/resources || exit |
| 171 | clone_models |
| 172 | if [ "${PROJECT}" == "distribution" ] || [ "${PROJECT}" == "policy-distribution" ]; then |
| 173 | copy_csar_file |
| 174 | fi |
| 175 | echo "Build robot framework docker image" |
| 176 | docker login -u docker -p docker nexus3.onap.org:10001 |
| 177 | docker build . --file Dockerfile \ |
| 178 | --build-arg CSIT_SCRIPT="$CSIT_SCRIPT" \ |
| 179 | --build-arg ROBOT_FILE="$ROBOT_FILE" \ |
| 180 | --tag "${ROBOT_DOCKER_IMAGE}" --no-cache |
| 181 | echo "---------------------------------------------" |
| 182 | } |
| 183 | |
| 184 | function start_csit() { |
| 185 | build_robot_image |
| 186 | if [ "${?}" -eq 0 ]; then |
| 187 | echo "Importing robot image into microk8s registry" |
| 188 | docker save -o policy-csit-robot.tar ${ROBOT_DOCKER_IMAGE}:latest |
| 189 | sudo microk8s ctr image import policy-csit-robot.tar |
| 190 | rm -rf ${WORKSPACE}/csit/resources/policy-csit-robot.tar |
| 191 | rm -rf ${WORKSPACE}/csit/resources/tests/models/ |
| 192 | echo "---------------------------------------------" |
| 193 | if [ "$PROJECT" == "clamp" ] || [ "$PROJECT" == "policy-clamp" ]; then |
| 194 | POD_READY_STATUS="0/1" |
| 195 | while [[ ${POD_READY_STATUS} != "1/1" ]]; do |
| 196 | echo "Waiting for chartmuseum pod to come up..." |
| 197 | sleep 5 |
rameshiyer27 | a4530ef | 2024-07-01 15:35:39 +0000 | [diff] [blame] | 198 | POD_READY_STATUS=$(sudo kubectl get pods | grep -e "policy-chartmuseum" | awk '{print $2}') |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 199 | done |
| 200 | push_acelement_chart |
| 201 | fi |
| 202 | echo "Installing Robot framework pod for running CSIT" |
| 203 | cd ${WORKSPACE}/helm |
| 204 | mkdir -p ${ROBOT_LOG_DIR} |
rameshiyer27 | a4530ef | 2024-07-01 15:35:39 +0000 | [diff] [blame] | 205 | sudo helm install csit-robot robot --set robot="$ROBOT_FILE" --set "readiness={${READINESS_CONTAINERS[*]}}" --set robotLogDir=$ROBOT_LOG_DIR |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 206 | print_robot_log |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 207 | fi |
| 208 | } |
| 209 | |
| 210 | function print_robot_log() { |
| 211 | count_pods=0 |
| 212 | while [[ ${count_pods} -eq 0 ]]; do |
| 213 | echo "Waiting for pods to come up..." |
| 214 | sleep 5 |
rameshiyer27 | a4530ef | 2024-07-01 15:35:39 +0000 | [diff] [blame] | 215 | count_pods=$(sudo kubectl get pods --output name | wc -l) |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 216 | done |
rameshiyer27 | a4530ef | 2024-07-01 15:35:39 +0000 | [diff] [blame] | 217 | robotpod=$(sudo kubectl get po | grep policy-csit) |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 218 | podName=$(echo "$robotpod" | awk '{print $1}') |
| 219 | echo "The robot tests will begin once the policy components {${READINESS_CONTAINERS[*]}} are up and running..." |
rameshiyer27 | a4530ef | 2024-07-01 15:35:39 +0000 | [diff] [blame] | 220 | sudo kubectl wait --for=jsonpath='{.status.phase}'=Running --timeout=18m pod/"$podName" |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 221 | echo "Policy deployment status:" |
rameshiyer27 | a4530ef | 2024-07-01 15:35:39 +0000 | [diff] [blame] | 222 | sudo kubectl get po |
| 223 | sudo kubectl get all -A |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 224 | echo "Robot Test logs:" |
rameshiyer27 | a4530ef | 2024-07-01 15:35:39 +0000 | [diff] [blame] | 225 | sudo kubectl logs -f "$podName" |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | function clone_models() { |
| 229 | |
| 230 | # download models examples |
| 231 | git clone -b "${GERRIT_BRANCH}" --single-branch https://github.com/onap/policy-models.git "${WORKSPACE}"/csit/resources/tests/models |
| 232 | |
| 233 | # create a couple of variations of the policy definitions |
| 234 | sed -e 's!Measurement_vGMUX!ADifferentValue!' \ |
| 235 | tests/models/models-examples/src/main/resources/policies/vCPE.policy.monitoring.input.tosca.json \ |
| 236 | >tests/models/models-examples/src/main/resources/policies/vCPE.policy.monitoring.input.tosca.v1_2.json |
| 237 | |
| 238 | sed -e 's!"version": "1.0.0"!"version": "2.0.0"!' \ |
| 239 | -e 's!"policy-version": 1!"policy-version": 2!' \ |
| 240 | tests/models/models-examples/src/main/resources/policies/vCPE.policy.monitoring.input.tosca.json \ |
| 241 | >tests/models/models-examples/src/main/resources/policies/vCPE.policy.monitoring.input.tosca.v2.json |
| 242 | } |
| 243 | |
| 244 | function copy_csar_file() { |
| 245 | zip -F ${DISTRIBUTION_CSAR}/sample_csar_with_apex_policy.csar \ |
| 246 | --out ${DISTRIBUTION_CSAR}/csar_temp.csar -q |
| 247 | # Remake temp directory |
| 248 | sudo rm -rf "${DIST_TEMP_FOLDER}" |
| 249 | sudo mkdir "${DIST_TEMP_FOLDER}" |
| 250 | sudo cp ${DISTRIBUTION_CSAR}/csar_temp.csar ${DISTRIBUTION_CSAR}/temp.csar |
| 251 | sudo mv ${DISTRIBUTION_CSAR}/temp.csar ${DIST_TEMP_FOLDER}/sample_csar_with_apex_policy.csar |
| 252 | } |
| 253 | |
| 254 | function set_project_config() { |
| 255 | echo "Setting project configuration for: $PROJECT" |
| 256 | case $PROJECT in |
| 257 | |
| 258 | clamp | policy-clamp) |
| 259 | export ROBOT_FILE=$POLICY_CLAMP_ROBOT |
saul.gill | 54d234d | 2024-06-27 17:22:12 +0100 | [diff] [blame] | 260 | export READINESS_CONTAINERS=($POLICY_CLAMP_CONTAINER,$POLICY_APEX_CONTAINER,$POLICY_PF_PPNT_CONTAINER,$POLICY_K8S_PPNT_CONTAINER, |
| 261 | $POLICY_HTTP_PPNT_CONTAINER,$POLICY_SIM_PPNT_CONTAINER,$JAEGER_CONTAINER) |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 262 | export SET_VALUES="--set $POLICY_CLAMP_CONTAINER.enabled=true --set $POLICY_APEX_CONTAINER.enabled=true |
FrancescoFioraEst | 8fadfb9 | 2024-04-17 11:42:58 +0100 | [diff] [blame] | 263 | --set $POLICY_PF_PPNT_CONTAINER.enabled=true --set $POLICY_K8S_PPNT_CONTAINER.enabled=true |
saul.gill | 54d234d | 2024-06-27 17:22:12 +0100 | [diff] [blame] | 264 | --set $POLICY_HTTP_PPNT_CONTAINER.enabled=true --set $POLICY_SIM_PPNT_CONTAINER.enabled=true |
| 265 | --set $JAEGER_CONTAINER.enabled=true" |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 266 | install_chartmuseum |
| 267 | ;; |
| 268 | |
| 269 | api | policy-api) |
| 270 | export ROBOT_FILE=$POLICY_API_ROBOT |
| 271 | export READINESS_CONTAINERS=($POLICY_API_CONTAINER) |
| 272 | ;; |
| 273 | |
| 274 | pap | policy-pap) |
| 275 | export ROBOT_FILE=$POLICY_PAP_ROBOT |
| 276 | export READINESS_CONTAINERS=($POLICY_APEX_CONTAINER,$POLICY_PAP_CONTAINER,$POLICY_API_CONTAINER,$POLICY_XACML_CONTAINER) |
| 277 | export SET_VALUES="--set $POLICY_APEX_CONTAINER.enabled=true --set $POLICY_XACML_CONTAINER.enabled=true" |
| 278 | ;; |
| 279 | |
| 280 | apex-pdp | policy-apex-pdp) |
| 281 | export ROBOT_FILE=$POLICY_APEX_PDP_ROBOT |
| 282 | export READINESS_CONTAINERS=($POLICY_APEX_CONTAINER,$POLICY_API_CONTAINER,$POLICY_PAP_CONTAINER) |
| 283 | export SET_VALUES="--set $POLICY_APEX_CONTAINER.enabled=true" |
| 284 | ;; |
| 285 | |
| 286 | xacml-pdp | policy-xacml-pdp) |
| 287 | export ROBOT_FILE=($POLICY_XACML_PDP_ROBOT) |
| 288 | export READINESS_CONTAINERS=($POLICY_API_CONTAINER,$POLICY_PAP_CONTAINER,$POLICY_XACML_CONTAINER) |
| 289 | export SET_VALUES="--set $POLICY_XACML_CONTAINER.enabled=true" |
| 290 | ;; |
| 291 | |
| 292 | drools-pdp | policy-drools-pdp) |
| 293 | export ROBOT_FILE=($POLICY_DROOLS_PDP_ROBOT) |
| 294 | export READINESS_CONTAINERS=($POLICY_DROOLS_CONTAINER) |
| 295 | export SET_VALUES="--set $POLICY_DROOLS_CONTAINER.enabled=true" |
| 296 | ;; |
| 297 | |
| 298 | distribution | policy-distribution) |
| 299 | export ROBOT_FILE=($POLICY_DISTRIBUTION_ROBOT) |
rameshiyer27 | 5c67a88 | 2024-06-27 22:36:27 +0000 | [diff] [blame] | 300 | export READINESS_CONTAINERS=($POLICY_APEX_CONTAINER,$POLICY_API_CONTAINER,$POLICY_PAP_CONTAINER,$POLICY_DISTRIBUTION_CONTAINER) |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 301 | export SET_VALUES="--set $POLICY_APEX_CONTAINER.enabled=true --set $POLICY_DISTRIBUTION_CONTAINER.enabled=true" |
| 302 | ;; |
| 303 | |
| 304 | *) |
| 305 | echo "Unknown project supplied. Enabling all policy charts for the deployment" |
saul.gill | d589fbb | 2023-10-20 16:32:57 +0100 | [diff] [blame] | 306 | export READINESS_CONTAINERS=($POLICY_APEX_CONTAINER,$POLICY_API_CONTAINER,$POLICY_PAP_CONTAINER, |
| 307 | $POLICY_DISTRIBUTION_CONTAINER,$POLICY_DROOLS_CONTAINER,$POLICY_XACML_CONTAINER, |
| 308 | $POLICY_CLAMP_CONTAINER,$POLICY_PF_PPNT_CONTAINER,$POLICY_K8S_PPNT_CONTAINER, |
FrancescoFioraEst | 8fadfb9 | 2024-04-17 11:42:58 +0100 | [diff] [blame] | 309 | $POLICY_HTTP_PPNT_CONTAINER,$POLICY_SIM_PPNT_CONTAINER) |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 310 | export SET_VALUES="--set $POLICY_APEX_CONTAINER.enabled=true --set $POLICY_XACML_CONTAINER.enabled=true |
rameshiyer27 | f2e4da7 | 2024-01-13 21:26:09 +0000 | [diff] [blame] | 311 | --set $POLICY_DISTRIBUTION_CONTAINER.enabled=true --set $POLICY_DROOLS_CONTAINER.enabled=true |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 312 | --set $POLICY_CLAMP_CONTAINER.enabled=true --set $POLICY_PF_PPNT_CONTAINER.enabled=true |
FrancescoFioraEst | 8fadfb9 | 2024-04-17 11:42:58 +0100 | [diff] [blame] | 313 | --set $POLICY_K8S_PPNT_CONTAINER.enabled=true --set $POLICY_HTTP_PPNT_CONTAINER.enabled=true |
| 314 | --set $POLICY_SIM_PPNT_CONTAINER.enabled=true" |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 315 | ;; |
| 316 | esac |
| 317 | |
| 318 | } |
| 319 | |
| 320 | function install_chartmuseum () { |
rameshiyer27 | a4530ef | 2024-07-01 15:35:39 +0000 | [diff] [blame] | 321 | echo "---------------------------------------------" |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 322 | echo "Installing Chartmuseum helm repository..." |
rameshiyer27 | a4530ef | 2024-07-01 15:35:39 +0000 | [diff] [blame] | 323 | sudo helm repo add chartmuseum-git https://chartmuseum.github.io/charts |
| 324 | sudo helm repo update |
| 325 | sudo helm install policy-chartmuseum chartmuseum-git/chartmuseum --set env.open.DISABLE_API=false --set service.type=NodePort --set service.nodePort=30208 |
| 326 | sudo helm plugin install https://github.com/chartmuseum/helm-push |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 327 | echo "---------------------------------------------" |
| 328 | } |
| 329 | |
| 330 | function push_acelement_chart() { |
| 331 | echo "Pushing acelement chart to the chartmuseum repo..." |
rameshiyer27 | a4530ef | 2024-07-01 15:35:39 +0000 | [diff] [blame] | 332 | sudo helm repo add policy-chartmuseum http://localhost:30208 |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 333 | |
| 334 | # download clamp repo |
| 335 | git clone -b "${GERRIT_BRANCH}" --single-branch https://github.com/onap/policy-clamp.git "${WORKSPACE}"/csit/resources/tests/clamp |
| 336 | ACELEMENT_CHART=${WORKSPACE}/csit/resources/tests/clamp/examples/src/main/resources/clamp/acm/acelement-helm/acelement |
rameshiyer27 | a4530ef | 2024-07-01 15:35:39 +0000 | [diff] [blame] | 337 | sudo helm cm-push $ACELEMENT_CHART policy-chartmuseum |
| 338 | sudo helm repo update |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 339 | rm -rf ${WORKSPACE}/csit/resources/tests/clamp/ |
| 340 | echo "-------------------------------------------" |
| 341 | } |
rameshiyer27 | a1954d4 | 2022-11-14 06:00:12 +0000 | [diff] [blame] | 342 | |
saul.gill | d589fbb | 2023-10-20 16:32:57 +0100 | [diff] [blame] | 343 | function get_pod_name() { |
rameshiyer27 | a4530ef | 2024-07-01 15:35:39 +0000 | [diff] [blame] | 344 | pods=$(kubectl get pods --no-headers -o custom-columns=':metadata.name' | grep $1) |
rameshiyer27 | 5c67a88 | 2024-06-27 22:36:27 +0000 | [diff] [blame] | 345 | read -rd '' -a pod_array <<< "$pods" |
| 346 | echo "${pod_array[@]}" |
saul.gill | d589fbb | 2023-10-20 16:32:57 +0100 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | wait_for_pods_running() { |
| 350 | local namespace="$1" |
| 351 | shift |
| 352 | local timeout_seconds="$1" |
| 353 | shift |
| 354 | |
rameshiyer27 | 5c67a88 | 2024-06-27 22:36:27 +0000 | [diff] [blame] | 355 | IFS=',' read -ra pod_names <<< "$@" |
saul.gill | d589fbb | 2023-10-20 16:32:57 +0100 | [diff] [blame] | 356 | shift |
| 357 | |
| 358 | local pending_pods=("${pod_names[@]}") |
saul.gill | d589fbb | 2023-10-20 16:32:57 +0100 | [diff] [blame] | 359 | local start_time |
| 360 | start_time=$(date +%s) |
| 361 | |
| 362 | while [ ${#pending_pods[@]} -gt 0 ]; do |
| 363 | local current_time |
| 364 | current_time=$(date +%s) |
| 365 | local elapsed_time |
| 366 | elapsed_time=$((current_time - start_time)) |
| 367 | |
| 368 | if [ "$elapsed_time" -ge "$timeout_seconds" ]; then |
rameshiyer27 | 7c61607 | 2024-08-06 11:10:19 +0100 | [diff] [blame] | 369 | echo "Timed out waiting for the pods to reach 'Running' state." |
| 370 | echo "Printing the current status of the deployment before exiting.." |
rameshiyer27 | 0b5f6e0 | 2024-08-06 16:00:45 +0100 | [diff] [blame] | 371 | kubectl get po; |
rameshiyer27 | 7c61607 | 2024-08-06 11:10:19 +0100 | [diff] [blame] | 372 | kubectl describe pods; |
| 373 | echo "------------------------------------------------------------" |
| 374 | for pod in "${pending_pods[@]}"; do |
| 375 | echo "Logs of the pod $pod" |
| 376 | kubectl logs $pod |
| 377 | echo "---------------------------------------------------------" |
| 378 | done |
saul.gill | d589fbb | 2023-10-20 16:32:57 +0100 | [diff] [blame] | 379 | exit 1 |
| 380 | fi |
| 381 | |
| 382 | local newly_running_pods=() |
| 383 | |
| 384 | for pod_name_prefix in "${pending_pods[@]}"; do |
rameshiyer27 | 5c67a88 | 2024-06-27 22:36:27 +0000 | [diff] [blame] | 385 | local pod_names=$(get_pod_name "$pod_name_prefix") |
| 386 | IFS=' ' read -r -a pod_array <<< "$pod_names" |
| 387 | if [ "${#pod_array[@]}" -eq 0 ]; then |
| 388 | echo "*** Error: No pods found for the deployment $pod_name_prefix . Exiting ***" |
| 389 | return -1 |
saul.gill | d589fbb | 2023-10-20 16:32:57 +0100 | [diff] [blame] | 390 | fi |
rameshiyer27 | 5c67a88 | 2024-06-27 22:36:27 +0000 | [diff] [blame] | 391 | for pod in "${pod_array[@]}"; do |
| 392 | local pod_status |
| 393 | local pod_ready |
| 394 | pod_status=$(kubectl get pod "$pod" -n "$namespace" --no-headers -o custom-columns=STATUS:.status.phase 2>/dev/null) |
| 395 | pod_ready=$(kubectl get pod "$pod" -o jsonpath='{.status.containerStatuses[*].ready}') |
| 396 | |
| 397 | if [ "$pod_status" == "Running" ] && [ "$pod_ready" == "true" ]; then |
| 398 | echo "Pod '$pod' in namespace '$namespace' is now in 'Running' state and 'Readiness' is true" |
| 399 | else |
| 400 | newly_running_pods+=("$pod") |
| 401 | echo "Waiting for pod '$pod' in namespace '$namespace' to reach 'Running' and 'Ready' state..." |
| 402 | fi |
| 403 | |
| 404 | done |
saul.gill | d589fbb | 2023-10-20 16:32:57 +0100 | [diff] [blame] | 405 | done |
| 406 | |
| 407 | pending_pods=("${newly_running_pods[@]}") |
| 408 | |
| 409 | sleep 5 |
| 410 | done |
| 411 | |
saul.gill | aed46b6 | 2024-05-09 11:59:37 +0100 | [diff] [blame] | 412 | echo "All specified pods are in the 'Running and Ready' state. Exiting the function." |
saul.gill | d589fbb | 2023-10-20 16:32:57 +0100 | [diff] [blame] | 413 | } |
| 414 | |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 415 | OPERATION="$1" |
| 416 | PROJECT="$2" |
rameshiyer27 | bdced49 | 2023-06-28 12:15:14 +0100 | [diff] [blame] | 417 | if [ -z "$3" ] |
| 418 | then |
| 419 | LOCALIMAGE="false" |
| 420 | else |
| 421 | LOCALIMAGE="$3" |
| 422 | fi |
| 423 | |
rameshiyer27 | a1954d4 | 2022-11-14 06:00:12 +0000 | [diff] [blame] | 424 | |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 425 | if [ $OPERATION == "install" ]; then |
| 426 | spin_microk8s_cluster |
| 427 | if [ "${?}" -eq 0 ]; then |
rameshiyer27 | 31c61d4 | 2024-01-21 14:24:03 +0000 | [diff] [blame] | 428 | export KAFKA_CONTAINERS=($KAFKA_CONTAINER,$ZK_CONTAINER) |
| 429 | install_kafka |
| 430 | wait_for_pods_running default 300 $KAFKA_CONTAINERS |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 431 | set_project_config |
| 432 | echo "Installing policy helm charts in the default namespace" |
| 433 | source ${WORKSPACE}/compose/get-k8s-versions.sh |
rameshiyer27 | bdced49 | 2023-06-28 12:15:14 +0100 | [diff] [blame] | 434 | if [ $LOCALIMAGE == "true" ]; then |
| 435 | echo "loading local image" |
| 436 | source ${WORKSPACE}/compose/get-versions.sh |
| 437 | ${WORKSPACE}/compose/loaddockerimage.sh |
| 438 | fi |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 439 | cd ${WORKSPACE}/helm || exit |
rameshiyer27 | a4530ef | 2024-07-01 15:35:39 +0000 | [diff] [blame] | 440 | sudo helm dependency build policy |
| 441 | sudo helm install csit-policy policy ${SET_VALUES} |
| 442 | sudo helm install prometheus prometheus |
rameshiyer27 | 9c4e66a | 2024-07-17 23:19:44 +0000 | [diff] [blame] | 443 | wait_for_pods_running default 900 ${READINESS_CONTAINERS[@]} |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 444 | echo "Policy chart installation completed" |
| 445 | echo "-------------------------------------------" |
| 446 | fi |
| 447 | |
| 448 | if [ "$PROJECT" ]; then |
| 449 | export ROBOT_LOG_DIR=${WORKSPACE}/csit/archives/${PROJECT} |
| 450 | echo "CSIT will be invoked from $ROBOT_FILE" |
| 451 | echo "Readiness containers: ${READINESS_CONTAINERS[*]}" |
| 452 | echo "-------------------------------------------" |
| 453 | start_csit |
| 454 | else |
| 455 | echo "No project supplied for running CSIT" |
| 456 | fi |
| 457 | |
| 458 | elif [ $OPERATION == "uninstall" ]; then |
| 459 | uninstall_policy |
| 460 | |
| 461 | elif [ $OPERATION == "clean" ]; then |
| 462 | teardown_cluster |
| 463 | |
| 464 | else |
rameshiyer27 | bdced49 | 2023-06-28 12:15:14 +0100 | [diff] [blame] | 465 | echo "Invalid arguments provided. Usage: $0 [options..] {install {project_name} | uninstall | clean} {uselocalimage = true/false}" |
rameshiyer27 | 65fc375 | 2023-04-05 13:47:15 +0100 | [diff] [blame] | 466 | fi |