diff options
author | saul.gill <saul.gill@est.tech> | 2023-10-20 16:32:57 +0100 |
---|---|---|
committer | Saul Gill <saul.gill@est.tech> | 2023-10-25 09:24:10 +0000 |
commit | d589fbbdf1592a0230dbbd4d4bb7b4e8ad3f2e7e (patch) | |
tree | 78b52bf4ba0e9b74e5be0481011658b5953180bd /csit/run-k8s-csit.sh | |
parent | f2633ef7de167236682f8fe67db0bc9c2427f537 (diff) |
Fix issues in scripts for s3ps
Issue-ID: POLICY-4856
Change-Id: I0e69bfe59b1316e738ad78f1b2f9cdefc4e9afe4
Signed-off-by: saul.gill <saul.gill@est.tech>
Diffstat (limited to 'csit/run-k8s-csit.sh')
-rwxr-xr-x | csit/run-k8s-csit.sh | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/csit/run-k8s-csit.sh b/csit/run-k8s-csit.sh index 248a494f..9fd6159c 100755 --- a/csit/run-k8s-csit.sh +++ b/csit/run-k8s-csit.sh @@ -248,6 +248,10 @@ function set_project_config() { *) echo "Unknown project supplied. Enabling all policy charts for the deployment" + export READINESS_CONTAINERS=($POLICY_APEX_CONTAINER,$POLICY_API_CONTAINER,$POLICY_PAP_CONTAINER, + $POLICY_DISTRIBUTION_CONTAINER,$POLICY_DROOLS_CONTAINER,$POLICY_XACML_CONTAINER, + $POLICY_CLAMP_CONTAINER,$POLICY_PF_PPNT_CONTAINER,$POLICY_K8S_PPNT_CONTAINER, + $POLICY_HTTP_PPNT_CONTAINER) export SET_VALUES="--set $POLICY_APEX_CONTAINER.enabled=true --set $POLICY_XACML_CONTAINER.enabled=true --set $POLICY_DISTRIBUTION_CONTAINER.enabled=true --set $POLICY_POLICY_DROOLS_CONTAINER.enabled=true --set $POLICY_CLAMP_CONTAINER.enabled=true --set $POLICY_PF_PPNT_CONTAINER.enabled=true @@ -279,6 +283,58 @@ function push_acelement_chart() { echo "-------------------------------------------" } +function get_pod_name() { + microk8s kubectl get pods --no-headers -o custom-columns=':metadata.name' | grep $1 +} + +wait_for_pods_running() { + local namespace="$1" + shift + local timeout_seconds="$1" + shift + + IFS=',' read -ra pod_names <<< "$1" + shift + + local pending_pods=("${pod_names[@]}") + + local start_time + start_time=$(date +%s) + + while [ ${#pending_pods[@]} -gt 0 ]; do + local current_time + current_time=$(date +%s) + local elapsed_time + elapsed_time=$((current_time - start_time)) + + if [ "$elapsed_time" -ge "$timeout_seconds" ]; then + echo "Timed out waiting for all pods to reach 'Running' state." + exit 1 + fi + + local newly_running_pods=() + + for pod_name_prefix in "${pending_pods[@]}"; do + local pod_name=$(get_pod_name "$pod_name_prefix") + local pod_status + pod_status=$(kubectl get pod "$pod_name" -n "$namespace" --no-headers -o custom-columns=STATUS:.status.phase 2>/dev/null) + + if [ "$pod_status" == "Running" ]; then + echo "Pod '$pod_name' in namespace '$namespace' is now in 'Running' state." + else + newly_running_pods+=("$pod_name") + echo "Waiting for pod '$pod_name' in namespace '$namespace' to reach 'Running' state..." + fi + done + + pending_pods=("${newly_running_pods[@]}") + + sleep 5 + done + + echo "All specified pods are in the 'Running' state. Exiting the function." +} + OPERATION="$1" PROJECT="$2" @@ -305,6 +361,7 @@ if [ $OPERATION == "install" ]; then sudo microk8s helm dependency build policy sudo microk8s helm install csit-policy policy ${SET_VALUES} sudo microk8s helm install prometheus prometheus + wait_for_pods_running default 300 $READINESS_CONTAINERS echo "Policy chart installation completed" echo "-------------------------------------------" fi |