Skip to content

Commit

Permalink
Fixed waitforelasticsearch to accept yellow.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Friedhoff committed Nov 3, 2023
1 parent 7a7ddb7 commit 24facba
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions apigateway/helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down

0 comments on commit 24facba

Please sign in to comment.