Add monitor loop for Gitea API operations
Change-Id: I76b2a3f6928e7cf64933e52d9fda34a978e1121b
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
diff --git a/installers/mgmt-cluster/gitea/admin/api.sh b/installers/mgmt-cluster/gitea/admin/api.sh
index 753e6b2..2c635cc 100755
--- a/installers/mgmt-cluster/gitea/admin/api.sh
+++ b/installers/mgmt-cluster/gitea/admin/api.sh
@@ -23,6 +23,7 @@
HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")")
. "$HERE/../library/functions.sh"
. "$HERE/../library/trap.sh"
+. "$HERE/../library/helpers.sh"
SERVER_URL=$1
TOKEN=$2
@@ -30,20 +31,30 @@
URI=$4
DATA=$5
-if [ -z "$DATA" ]; then
- kubectl exec statefulset/gitea --container=gitea --namespace=gitea --quiet -- \
- curl --silent --fail \
- "${SERVER_URL}/api/v1/${URI}" \
- --request "${VERB}" \
- --header "Authorization: token ${TOKEN}" \
- --header 'Accept: application/json'
-else
- kubectl exec statefulset/gitea --container=gitea --namespace=gitea --quiet -- \
- curl --silent --fail \
- --request "$VERB" \
- "${SERVER_URL}/api/v1/${URI}" \
- --header "Authorization: token ${TOKEN}" \
- --header 'Accept: application/json' \
- --header 'Content-Type: application/json' \
- --data "${DATA}"
+function gitea_api_operation() {
+ if [ -z "$DATA" ]; then
+ kubectl exec statefulset/gitea --container=gitea --namespace=gitea --quiet -- \
+ curl --silent --fail \
+ "${SERVER_URL}/api/v1/${URI}" \
+ --request "${VERB}" \
+ --header "Authorization: token ${TOKEN}" \
+ --header 'Accept: application/json'
+ else
+ kubectl exec statefulset/gitea --container=gitea --namespace=gitea --quiet -- \
+ curl --silent --fail \
+ --request "$VERB" \
+ "${SERVER_URL}/api/v1/${URI}" \
+ --header "Authorization: token ${TOKEN}" \
+ --header 'Accept: application/json' \
+ --header 'Content-Type: application/json' \
+ --data "${DATA}"
+ fi
+}
+
+monitor_condition gitea_api_operation "Gitea API operation did not succeed yet...\n" 120 5
+RET=$?
+if [[ $RET -ne 0 ]]
+then
+ echo -e "\nFATAL: Gitea API operation did not succeed after several retries. ABORTED.\n"
+ exit $RET
fi