From 24facbad5b584a7b0a9882288f10403d43a9da24 Mon Sep 17 00:00:00 2001 From: Marc Friedhoff Date: Fri, 3 Nov 2023 17:54:55 +0100 Subject: [PATCH] Fixed waitforelasticsearch to accept yellow. --- apigateway/helm/templates/deployment.yaml | 38 +++++++++++++++++++---- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/apigateway/helm/templates/deployment.yaml b/apigateway/helm/templates/deployment.yaml index 88288f7..d7c7888 100644 --- a/apigateway/helm/templates/deployment.yaml +++ b/apigateway/helm/templates/deployment.yaml @@ -62,13 +62,39 @@ spec: - -ec - | {{- $esSvc := ( include "apigateway.elasticservice" . ) }} - {{- $esUrl := printf "%s://%s:%s/_cluster/health?pretty" (ternary "https" "http" .Values.elasticsearch.tlsEnabled ) $esSvc ( .Values.elasticsearch.port | toString) }} - curl -s {{ $esUrl }} -u $username:$password | tee /tmp/tmpfile - until grep "status" /tmp/tmpfile | grep "green" ; do - echo "waiting for {{ $esSvc }}: status not yet 'green'." - sleep 2 - curl -k -s {{ $esUrl }} -u $username:$password | tee /tmp/tmpfile + {{- $esHost := printf "%s://%s:%s" (ternary "https" "http" .Values.elasticsearch.tlsEnabled ) $esSvc ( .Values.global.elasticsearch.port | toString) }} + + host="{{ $esHost }}" + until $(curl --output /dev/null --silent --head --fail -u $username:$password "$host" ) ; do + echo 'Checking if Elasticsearch server is up' + sleep 5 + counter=$((counter+1)) + done + + # First wait for ES to start... + response=$(curl $host) + + until [ "$response" = "200" ] ; do + response=$(curl --write-out %{http_code} --silent --output /dev/null -u $username:$password "$host") + >&2 echo "Elasticsearch is up but unavailable - No Reponse - sleeping" + sleep 10 + done + + + # next wait for ES status to turn to green or yellow + health="$(curl -fsSL -u $username:$password "$host/_cat/health?h=status")" + health="$(echo "$health" | sed -r 's/^[[:space:]]+|[[:space:]]+$//g')" # trim whitespace (otherwise we'll have "green ") + + until [ "$health" = 'yellow' ] || [ "$health" = 'green' ] ; do + health="$(curl -fsSL "$host/_cat/health?h=status")" + health="$(echo "$health" | sed -r 's/^[[:space:]]+|[[:space:]]+$//g')" + >&2 echo "Elasticsearch status is not green or yellow - sleeping" + sleep 10 + done + + echo "Elasticsearch is up and running. Status was: $health" + {{ end }} {{- if .Values.extraInitContainers }} {{- toYaml .Values.extraInitContainers | nindent 6 }}