blob: eaaa8b48a47b8d3c7eb9723d02fbc6fefcf4f26e [file] [log] [blame]
rameshiyer27a1954d42022-11-14 06:00:12 +00001#!/bin/bash
2#
3# ============LICENSE_START====================================================
rameshiyer27f2e4da72024-01-13 21:26:09 +00004# Copyright (C) 2022-2024 Nordix Foundation.
rameshiyer27a1954d42022-11-14 06:00:12 +00005# =============================================================================
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
rameshiyer2765fc3752023-04-05 13:47:15 +010021# This script spins up kubernetes cluster in Microk8s for deploying policy helm charts.
22# Runs CSITs in kubernetes.
rameshiyer2707004862023-01-23 11:50:01 +000023
rameshiyer27f575f922023-10-12 15:11:02 +010024WORKSPACE=$(git rev-parse --show-toplevel)
25export WORKSPACE
adheli.tavares1153b6d2023-02-28 12:59:37 +000026
rameshiyer2765fc3752023-04-05 13:47:15 +010027export GERRIT_BRANCH=$(awk -F= '$1 == "defaultbranch" { print $2 }' "${WORKSPACE}"/.gitreview)
rameshiyer27d8f91802023-03-07 01:32:28 +000028
rameshiyer2765fc3752023-04-05 13:47:15 +010029CSIT_SCRIPT="scripts/run-test.sh"
30ROBOT_DOCKER_IMAGE="policy-csit-robot"
rameshiyer273397d842024-08-18 11:12:23 +010031POLICY_CLAMP_ROBOT="policy-clamp-test.robot clamp-slas.robot"
rameshiyer2765fc3752023-04-05 13:47:15 +010032POLICY_API_ROBOT="api-test.robot api-slas.robot"
33POLICY_PAP_ROBOT="pap-test.robot pap-slas.robot"
34POLICY_APEX_PDP_ROBOT="apex-pdp-test.robot apex-slas.robot"
35POLICY_XACML_PDP_ROBOT="xacml-pdp-test.robot"
36POLICY_DROOLS_PDP_ROBOT="drools-pdp-test.robot"
37POLICY_DISTRIBUTION_ROBOT="distribution-test.robot"
rameshiyer2707004862023-01-23 11:50:01 +000038
rameshiyer2765fc3752023-04-05 13:47:15 +010039POLICY_API_CONTAINER="policy-api"
40POLICY_PAP_CONTAINER="policy-pap"
41POLICY_CLAMP_CONTAINER="policy-clamp-runtime-acm"
42POLICY_APEX_CONTAINER="policy-apex-pdp"
43POLICY_DROOLS_CONTAINER="policy-drools-pdp"
44POLICY_XACML_CONTAINER="policy-xacml-pdp"
45POLICY_DISTRIBUTION_CONTAINER="policy-distribution"
46POLICY_K8S_PPNT_CONTAINER="policy-clamp-ac-k8s-ppnt"
47POLICY_HTTP_PPNT_CONTAINER="policy-clamp-ac-http-ppnt"
FrancescoFioraEst8fadfb92024-04-17 11:42:58 +010048POLICY_SIM_PPNT_CONTAINER="policy-clamp-ac-sim-ppnt"
rameshiyer2765fc3752023-04-05 13:47:15 +010049POLICY_PF_PPNT_CONTAINER="policy-clamp-ac-pf-ppnt"
saul.gill54d234d2024-06-27 17:22:12 +010050JAEGER_CONTAINER="jaeger"
rameshiyer2731c61d42024-01-21 14:24:03 +000051KAFKA_CONTAINER="kafka-deployment"
52ZK_CONTAINER="zookeeper-deployment"
53KAFKA_DIR=${WORKSPACE}/helm/cp-kafka
rameshiyer2765fc3752023-04-05 13:47:15 +010054SET_VALUES=""
rameshiyer27a1954d42022-11-14 06:00:12 +000055
rameshiyer2765fc3752023-04-05 13:47:15 +010056DISTRIBUTION_CSAR=${WORKSPACE}/csit/resources/tests/data/csar
57DIST_TEMP_FOLDER=/tmp/distribution
rameshiyer27a1954d42022-11-14 06:00:12 +000058
rameshiyer2765fc3752023-04-05 13:47:15 +010059export PROJECT=""
60export ROBOT_FILE=""
61export ROBOT_LOG_DIR=${WORKSPACE}/csit/archives
62export READINESS_CONTAINERS=()
63
rameshiyer2731c61d42024-01-21 14:24:03 +000064
rameshiyer2765fc3752023-04-05 13:47:15 +010065function 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.."
rameshiyer27a4530ef2024-07-01 15:35:39 +000072 sudo snap install microk8s --classic --channel=1.30/stable
rameshiyer2765fc3752023-04-05 13:47:15 +010073
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
rameshiyer27a4530ef2024-07-01 15:35:39 +000080 echo "Enabling DNS and Storage plugins"
81 sudo microk8s.enable dns hostpath-storage
rameshiyer2765fc3752023-04-05 13:47:15 +010082 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 "----------------------------------------"
rameshiyer2765fc3752023-04-05 13:47:15 +010092 fi
93
FrancescoFioraEst8fadfb92024-04-17 11:42:58 +010094 echo "Verify if kubectl is running.."
95 kubectl version
96 exitcode="${?}"
97
98 if [ "$exitcode" -ne 0 ]; then
rameshiyer27a4530ef2024-07-01 15:35:39 +000099 echo "Kubectl not available, Installing.."
100 sudo snap install kubectl --classic --channel=1.30/stable
FrancescoFioraEst8fadfb92024-04-17 11:42:58 +0100101
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
rameshiyer27a4530ef2024-07-01 15:35:39 +0000113
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
rameshiyer2765fc3752023-04-05 13:47:15 +0100133}
134
rameshiyer2731c61d42024-01-21 14:24:03 +0000135function 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
rameshiyer2765fc3752023-04-05 13:47:15 +0100142function uninstall_policy() {
143 echo "Removing the policy helm deployment"
rameshiyer27a4530ef2024-07-01 15:35:39 +0000144 sudo helm uninstall csit-policy
145 sudo helm uninstall prometheus
146 sudo helm uninstall csit-robot
rameshiyer2731c61d42024-01-21 14:24:03 +0000147 sudo kubectl delete deploy $ZK_CONTAINER $KAFKA_CONTAINER
rameshiyer2765fc3752023-04-05 13:47:15 +0100148 rm -rf ${WORKSPACE}/helm/policy/Chart.lock
149 if [ "$PROJECT" == "clamp" ] || [ "$PROJECT" == "policy-clamp" ]; then
rameshiyer27a4530ef2024-07-01 15:35:39 +0000150 sudo helm uninstall policy-chartmuseum
151 sudo helm repo remove chartmuseum-git policy-chartmuseum
rameshiyer2765fc3752023-04-05 13:47:15 +0100152 fi
153 sudo rm -rf /dockerdata-nfs/mariadb-galera/
rameshiyer27a4530ef2024-07-01 15:35:39 +0000154 sudo kubectl delete pvc --all
rameshiyer2765fc3752023-04-05 13:47:15 +0100155 echo "Policy deployment deleted"
156 echo "Clean up docker"
157 docker image prune -f
158}
159
160function teardown_cluster() {
161 echo "Removing k8s cluster and k8s configuration file"
162 sudo snap remove microk8s;rm -rf $HOME/.kube/config
rameshiyer27a4530ef2024-07-01 15:35:39 +0000163 sudo snap remove helm;
164 sudo snap remove kubectl;
rameshiyer2765fc3752023-04-05 13:47:15 +0100165 echo "MicroK8s Cluster removed"
166}
167
168function 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
184function 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
rameshiyer27a4530ef2024-07-01 15:35:39 +0000198 POD_READY_STATUS=$(sudo kubectl get pods | grep -e "policy-chartmuseum" | awk '{print $2}')
rameshiyer2765fc3752023-04-05 13:47:15 +0100199 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}
rameshiyer27a4530ef2024-07-01 15:35:39 +0000205 sudo helm install csit-robot robot --set robot="$ROBOT_FILE" --set "readiness={${READINESS_CONTAINERS[*]}}" --set robotLogDir=$ROBOT_LOG_DIR
rameshiyer2765fc3752023-04-05 13:47:15 +0100206 print_robot_log
rameshiyer2765fc3752023-04-05 13:47:15 +0100207 fi
208}
209
210function 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
rameshiyer27a4530ef2024-07-01 15:35:39 +0000215 count_pods=$(sudo kubectl get pods --output name | wc -l)
rameshiyer2765fc3752023-04-05 13:47:15 +0100216 done
rameshiyer27a4530ef2024-07-01 15:35:39 +0000217 robotpod=$(sudo kubectl get po | grep policy-csit)
rameshiyer2765fc3752023-04-05 13:47:15 +0100218 podName=$(echo "$robotpod" | awk '{print $1}')
219 echo "The robot tests will begin once the policy components {${READINESS_CONTAINERS[*]}} are up and running..."
rameshiyer27a4530ef2024-07-01 15:35:39 +0000220 sudo kubectl wait --for=jsonpath='{.status.phase}'=Running --timeout=18m pod/"$podName"
rameshiyer2765fc3752023-04-05 13:47:15 +0100221 echo "Policy deployment status:"
rameshiyer27a4530ef2024-07-01 15:35:39 +0000222 sudo kubectl get po
223 sudo kubectl get all -A
rameshiyer2765fc3752023-04-05 13:47:15 +0100224 echo "Robot Test logs:"
rameshiyer27a4530ef2024-07-01 15:35:39 +0000225 sudo kubectl logs -f "$podName"
rameshiyer2765fc3752023-04-05 13:47:15 +0100226}
227
228function 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
244function 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
254function 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.gill54d234d2024-06-27 17:22:12 +0100260 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)
rameshiyer2765fc3752023-04-05 13:47:15 +0100262 export SET_VALUES="--set $POLICY_CLAMP_CONTAINER.enabled=true --set $POLICY_APEX_CONTAINER.enabled=true
FrancescoFioraEst8fadfb92024-04-17 11:42:58 +0100263 --set $POLICY_PF_PPNT_CONTAINER.enabled=true --set $POLICY_K8S_PPNT_CONTAINER.enabled=true
saul.gill54d234d2024-06-27 17:22:12 +0100264 --set $POLICY_HTTP_PPNT_CONTAINER.enabled=true --set $POLICY_SIM_PPNT_CONTAINER.enabled=true
265 --set $JAEGER_CONTAINER.enabled=true"
rameshiyer2765fc3752023-04-05 13:47:15 +0100266 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)
rameshiyer275c67a882024-06-27 22:36:27 +0000300 export READINESS_CONTAINERS=($POLICY_APEX_CONTAINER,$POLICY_API_CONTAINER,$POLICY_PAP_CONTAINER,$POLICY_DISTRIBUTION_CONTAINER)
rameshiyer2765fc3752023-04-05 13:47:15 +0100301 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.gilld589fbb2023-10-20 16:32:57 +0100306 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,
FrancescoFioraEst8fadfb92024-04-17 11:42:58 +0100309 $POLICY_HTTP_PPNT_CONTAINER,$POLICY_SIM_PPNT_CONTAINER)
rameshiyer2765fc3752023-04-05 13:47:15 +0100310 export SET_VALUES="--set $POLICY_APEX_CONTAINER.enabled=true --set $POLICY_XACML_CONTAINER.enabled=true
rameshiyer27f2e4da72024-01-13 21:26:09 +0000311 --set $POLICY_DISTRIBUTION_CONTAINER.enabled=true --set $POLICY_DROOLS_CONTAINER.enabled=true
rameshiyer2765fc3752023-04-05 13:47:15 +0100312 --set $POLICY_CLAMP_CONTAINER.enabled=true --set $POLICY_PF_PPNT_CONTAINER.enabled=true
FrancescoFioraEst8fadfb92024-04-17 11:42:58 +0100313 --set $POLICY_K8S_PPNT_CONTAINER.enabled=true --set $POLICY_HTTP_PPNT_CONTAINER.enabled=true
314 --set $POLICY_SIM_PPNT_CONTAINER.enabled=true"
rameshiyer2765fc3752023-04-05 13:47:15 +0100315 ;;
316 esac
317
318}
319
320function install_chartmuseum () {
rameshiyer27a4530ef2024-07-01 15:35:39 +0000321 echo "---------------------------------------------"
rameshiyer2765fc3752023-04-05 13:47:15 +0100322 echo "Installing Chartmuseum helm repository..."
rameshiyer27a4530ef2024-07-01 15:35:39 +0000323 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
rameshiyer2765fc3752023-04-05 13:47:15 +0100327 echo "---------------------------------------------"
328}
329
330function push_acelement_chart() {
331 echo "Pushing acelement chart to the chartmuseum repo..."
rameshiyer27a4530ef2024-07-01 15:35:39 +0000332 sudo helm repo add policy-chartmuseum http://localhost:30208
rameshiyer2765fc3752023-04-05 13:47:15 +0100333
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
rameshiyer27a4530ef2024-07-01 15:35:39 +0000337 sudo helm cm-push $ACELEMENT_CHART policy-chartmuseum
338 sudo helm repo update
rameshiyer2765fc3752023-04-05 13:47:15 +0100339 rm -rf ${WORKSPACE}/csit/resources/tests/clamp/
340 echo "-------------------------------------------"
341}
rameshiyer27a1954d42022-11-14 06:00:12 +0000342
saul.gilld589fbb2023-10-20 16:32:57 +0100343function get_pod_name() {
rameshiyer27a4530ef2024-07-01 15:35:39 +0000344 pods=$(kubectl get pods --no-headers -o custom-columns=':metadata.name' | grep $1)
rameshiyer275c67a882024-06-27 22:36:27 +0000345 read -rd '' -a pod_array <<< "$pods"
346 echo "${pod_array[@]}"
saul.gilld589fbb2023-10-20 16:32:57 +0100347}
348
349wait_for_pods_running() {
350 local namespace="$1"
351 shift
352 local timeout_seconds="$1"
353 shift
354
rameshiyer275c67a882024-06-27 22:36:27 +0000355 IFS=',' read -ra pod_names <<< "$@"
saul.gilld589fbb2023-10-20 16:32:57 +0100356 shift
357
358 local pending_pods=("${pod_names[@]}")
saul.gilld589fbb2023-10-20 16:32:57 +0100359 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
rameshiyer277c616072024-08-06 11:10:19 +0100369 echo "Timed out waiting for the pods to reach 'Running' state."
370 echo "Printing the current status of the deployment before exiting.."
rameshiyer270b5f6e02024-08-06 16:00:45 +0100371 kubectl get po;
rameshiyer277c616072024-08-06 11:10:19 +0100372 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.gilld589fbb2023-10-20 16:32:57 +0100379 exit 1
380 fi
381
382 local newly_running_pods=()
383
384 for pod_name_prefix in "${pending_pods[@]}"; do
rameshiyer275c67a882024-06-27 22:36:27 +0000385 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.gilld589fbb2023-10-20 16:32:57 +0100390 fi
rameshiyer275c67a882024-06-27 22:36:27 +0000391 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.gilld589fbb2023-10-20 16:32:57 +0100405 done
406
407 pending_pods=("${newly_running_pods[@]}")
408
409 sleep 5
410 done
411
saul.gillaed46b62024-05-09 11:59:37 +0100412 echo "All specified pods are in the 'Running and Ready' state. Exiting the function."
saul.gilld589fbb2023-10-20 16:32:57 +0100413}
414
rameshiyer2765fc3752023-04-05 13:47:15 +0100415OPERATION="$1"
416PROJECT="$2"
rameshiyer27bdced492023-06-28 12:15:14 +0100417if [ -z "$3" ]
418then
419 LOCALIMAGE="false"
420else
421 LOCALIMAGE="$3"
422fi
423
rameshiyer27a1954d42022-11-14 06:00:12 +0000424
rameshiyer2765fc3752023-04-05 13:47:15 +0100425if [ $OPERATION == "install" ]; then
426 spin_microk8s_cluster
427 if [ "${?}" -eq 0 ]; then
rameshiyer2731c61d42024-01-21 14:24:03 +0000428 export KAFKA_CONTAINERS=($KAFKA_CONTAINER,$ZK_CONTAINER)
429 install_kafka
430 wait_for_pods_running default 300 $KAFKA_CONTAINERS
rameshiyer2765fc3752023-04-05 13:47:15 +0100431 set_project_config
432 echo "Installing policy helm charts in the default namespace"
433 source ${WORKSPACE}/compose/get-k8s-versions.sh
rameshiyer27bdced492023-06-28 12:15:14 +0100434 if [ $LOCALIMAGE == "true" ]; then
435 echo "loading local image"
436 source ${WORKSPACE}/compose/get-versions.sh
437 ${WORKSPACE}/compose/loaddockerimage.sh
438 fi
rameshiyer2765fc3752023-04-05 13:47:15 +0100439 cd ${WORKSPACE}/helm || exit
rameshiyer27a4530ef2024-07-01 15:35:39 +0000440 sudo helm dependency build policy
441 sudo helm install csit-policy policy ${SET_VALUES}
442 sudo helm install prometheus prometheus
rameshiyer279c4e66a2024-07-17 23:19:44 +0000443 wait_for_pods_running default 900 ${READINESS_CONTAINERS[@]}
rameshiyer2765fc3752023-04-05 13:47:15 +0100444 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
458elif [ $OPERATION == "uninstall" ]; then
459 uninstall_policy
460
461elif [ $OPERATION == "clean" ]; then
462 teardown_cluster
463
464else
rameshiyer27bdced492023-06-28 12:15:14 +0100465 echo "Invalid arguments provided. Usage: $0 [options..] {install {project_name} | uninstall | clean} {uselocalimage = true/false}"
rameshiyer2765fc3752023-04-05 13:47:15 +0100466fi