Commit 78147940 authored by Adrien Kohlbecker's avatar Adrien Kohlbecker Committed by Robert Speicher

Wait for elasticsearch to be green on install

parent 7343c4f2
...@@ -30,7 +30,8 @@ module Clusters ...@@ -30,7 +30,8 @@ module Clusters
version: VERSION, version: VERSION,
rbac: cluster.platform_kubernetes_rbac?, rbac: cluster.platform_kubernetes_rbac?,
chart: chart, chart: chart,
files: files files: files,
postinstall: post_install_script
) )
end end
...@@ -43,6 +44,10 @@ module Clusters ...@@ -43,6 +44,10 @@ module Clusters
) )
end end
def files
super.merge('wait-for-elasticsearch.sh': File.read("#{Rails.root}/vendor/elastic_stack/wait-for-elasticsearch.sh"))
end
def elasticsearch_client def elasticsearch_client
strong_memoize(:elasticsearch_client) do strong_memoize(:elasticsearch_client) do
next unless kube_client next unless kube_client
...@@ -69,10 +74,16 @@ module Clusters ...@@ -69,10 +74,16 @@ module Clusters
private private
def post_install_script
[
"timeout -t60 sh /data/helm/elastic-stack/config/wait-for-elasticsearch.sh http://elastic-stack-elasticsearch-client:9200"
]
end
def post_delete_script def post_delete_script
[ [
Gitlab::Kubernetes::KubectlCmd.delete("pvc", "--selector", "release=elastic-stack") Gitlab::Kubernetes::KubectlCmd.delete("pvc", "--selector", "release=elastic-stack")
].compact ]
end end
def kube_client def kube_client
......
---
title: Wait for elasticsearch to be green on install
merge_request: 24489
author:
type: added
...@@ -464,8 +464,8 @@ chart is used to install this application with a ...@@ -464,8 +464,8 @@ chart is used to install this application with a
file. file.
NOTE: **Note:** NOTE: **Note:**
The chart will deploy 4 Elasticsearch nodes: 2 masters, 1 data and 1 client node, The chart will deploy 5 Elasticsearch nodes: 2 masters, 2 data and 1 client node,
with resource requests totalling 0.1 CPU and 3GB RAM. Each data node requests 1.5GB of memory, with resource requests totalling 0.125 CPU and 4.5GB RAM. Each data node requests 1.5GB of memory,
which makes it incompatible with clusters of `f1-micro` and `g1-small` instance types. which makes it incompatible with clusters of `f1-micro` and `g1-small` instance types.
## Install using GitLab CI (alpha) ## Install using GitLab CI (alpha)
......
...@@ -100,7 +100,7 @@ module EE ...@@ -100,7 +100,7 @@ module EE
end end
def elastic_stack_available? def elastic_stack_available?
!!cluster.application_elastic_stack !!cluster.application_elastic_stack&.installed?
end end
private private
......
...@@ -174,7 +174,7 @@ describe Clusters::Platforms::Kubernetes do ...@@ -174,7 +174,7 @@ describe Clusters::Platforms::Kubernetes do
context 'when ElasticSearch is enabled' do context 'when ElasticSearch is enabled' do
let(:cluster) { create(:cluster, :project, platform_kubernetes: service) } let(:cluster) { create(:cluster, :project, platform_kubernetes: service) }
let!(:elastic_stack) { create(:clusters_applications_elastic_stack, cluster: cluster) } let!(:elastic_stack) { create(:clusters_applications_elastic_stack, :installed, cluster: cluster) }
before do before do
expect_any_instance_of(::Clusters::Applications::ElasticStack).to receive(:elasticsearch_client).at_least(:once).and_return(Elasticsearch::Transport::Client.new) expect_any_instance_of(::Clusters::Applications::ElasticStack).to receive(:elasticsearch_client).at_least(:once).and_return(Elasticsearch::Transport::Client.new)
......
...@@ -8,7 +8,7 @@ elasticsearch: ...@@ -8,7 +8,7 @@ elasticsearch:
client: client:
replicas: 1 replicas: 1
data: data:
replicas: 1 replicas: 2
kibana: kibana:
enabled: false enabled: false
......
#!/bin/bash
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
IFS=$'\n\t'
set -euo pipefail
HOST="$1"
printf 'Waiting for ES to be reachable ...'
until $(wget -O- -q "$HOST" &>/dev/null); do
printf '.'
sleep 1
done
echo " OK!"
printf 'Waiting for ES to be healthy ...'
while : ; do
HEALTH="$(wget -O- -q "$HOST/_cat/health?h=status" 2> /dev/null)"
HEALTH="$(echo "$HEALTH" | sed -r 's/^[[:space:]]+|[[:space:]]+$//g')" # trim whitespace (otherwise we'll have "green ")
([ "$HEALTH" != "green" ] && printf '.' && sleep 1) || break
done
echo " OK!"
echo "Elastic Search is up!"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment