blob: fbdbe5abb0cc921869daa739dffa87ad6f0bc7d7 [file] [log] [blame]
garciadeblascf603f52025-06-04 11:57:28 +02001#!/usr/bin/env bash
2
3# Copyright 2020 Telefónica Investigación y Desarrollo S.A.U.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")")
18
19source "${HERE}/00-default-install-options.rc"
20[ ! -f "${OSM_HOME_DIR}/user-install-options.rc" ] || source "${OSM_HOME_DIR}/user-install-options.rc"
21source "${CREDENTIALS_DIR}/git_environment.rc"
22export KUBECONFIG="${OSM_HOME_DIR}/clusters/kubeconfig-osm.yaml"
23
24# Default values
25sampling_period=5 # seconds
garciadeblasb59b3202025-06-19 10:09:16 +020026time_for_readiness=2 # minutes ready
garciadeblascf603f52025-06-04 11:57:28 +020027time_for_failure=7 # minutes broken
28
29oks_threshold=$((time_for_readiness*60/${sampling_period})) # No. ok samples to declare the system ready
30failures_threshold=$((time_for_failure*60/${sampling_period})) # No. nok samples to declare the system broken
31failures_in_a_row=0
32oks_in_a_row=0
33
34
35# Show status of the OSM services deployed with helm
36echo "helm -n ${OSM_NAMESPACE} list"
37helm -n ${OSM_NAMESPACE} list
38echo "helm -n ${OSM_NAMESPACE} status ${OSM_HELM_RELEASE}"
39helm -n ${OSM_NAMESPACE} status ${OSM_HELM_RELEASE}
40
41####################################################################################
42# Loop to check system readiness
43####################################################################################
44while [[ (${failures_in_a_row} -lt ${failures_threshold}) && (${oks_in_a_row} -lt ${oks_threshold}) ]]
45do
46
47 # State of Deployments
48 DEPLOYMENTS_STATE=$(kubectl get deployment -n ${OSM_NAMESPACE} --no-headers 2>&1)
49 DEPLOYMENTS_READY=$(echo "${DEPLOYMENTS_STATE}" | awk '$2=="1/1" && $4=="1" {printf ("%20s\t%s\t%s\n", $1, $2, $4)}')
50 DEPLOYMENTS_NOT_READY=$(echo "${DEPLOYMENTS_STATE}" | awk '$2!="1/1" || $4!="1" {printf ("%20s\t%s\t%s\n", $1, $2, $4)}')
51 COUNT_DEPLOYMENTS_READY=$(echo "${DEPLOYMENTS_READY}" | grep -v -e '^$' | wc -l || true)
52 COUNT_DEPLOYMENTS_NOT_READY=$(echo "${DEPLOYMENTS_NOT_READY}" | grep -v -e '^$' | wc -l || true)
53
54 # State of Statefulsets
55 STS_STATE=$(kubectl get statefulset -n ${OSM_NAMESPACE} --no-headers 2>&1)
56 STS_READY=$(echo "${STS_STATE}" | awk '$2=="1/1" || $2=="2/2" || $2=="3/3" {printf ("%20s\t%s\t%s\n", $1, $2, $4)}')
57 STS_NOT_READY=$(echo "${STS_STATE}" | awk '$2!="1/1" && $2!="2/2" && $2!="3/3" {printf ("%20s\t%s\t%s\n", $1, $2, $4)}')
58 COUNT_STS_READY=$(echo "${STS_READY}" | grep -v -e '^$' | wc -l || true)
59 COUNT_STS_NOT_READY=$(echo "${STS_NOT_READY}" | grep -v -e '^$' | wc -l || true)
60
61 # OK sample
62 if [[ $((${COUNT_DEPLOYMENTS_NOT_READY}+${COUNT_STS_NOT_READY})) -eq 0 ]]
63 then
64 ((++oks_in_a_row))
65 failures_in_a_row=0
66 echo -ne ===\> Successful checks: "${oks_in_a_row}"/${oks_threshold}\\r
67 # NOK sample
68 else
69 ((++failures_in_a_row))
70 oks_in_a_row=0
71 echo
72 echo Bootstraping... "${failures_in_a_row}" attempts of ${failures_threshold}
73
74 # Reports failed deployments
75 if [[ "${COUNT_DEPLOYMENTS_NOT_READY}" -ne 0 ]]
76 then
77 echo ${COUNT_DEPLOYMENTS_NOT_READY} of $((${COUNT_DEPLOYMENTS_NOT_READY}+${COUNT_DEPLOYMENTS_READY})) deployments starting:
78 echo "${DEPLOYMENTS_NOT_READY}"
79 echo
80 fi
81
82 # Reports failed statefulsets
83 if [[ "${COUNT_STS_NOT_READY}" -ne 0 ]]
84 then
85 echo ${COUNT_STS_NOT_READY} of $((${COUNT_STS_NOT_READY}+${COUNT_STS_READY})) statefulsets starting:
86 echo "${STS_NOT_READY}"
87 echo
88 fi
89 fi
90
91 #------------ NEXT SAMPLE
92 sleep ${sampling_period}
93
94done
95
96
97####################################################################################
98# OUTCOME
99####################################################################################
100if [[ (${failures_in_a_row} -ge ${failures_threshold}) ]]
101then
102 echo
103 echo SYSTEM IS BROKEN
104 exit 1
105else
106 echo
107 echo SYSTEM IS READY
108fi
109
110exit 0