From 4968def2dfc813e62e0abd5f5da59ace50d9d661 Mon Sep 17 00:00:00 2001 From: Leo Sok Date: Mon, 16 Jun 2025 18:52:45 +0300 Subject: [PATCH] elastic https disabled --- elasticsearch/templates/statefulset.yaml | 47 ++++++++++++++++++------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/elasticsearch/templates/statefulset.yaml b/elasticsearch/templates/statefulset.yaml index 8d06221..64fd423 100644 --- a/elasticsearch/templates/statefulset.yaml +++ b/elasticsearch/templates/statefulset.yaml @@ -237,43 +237,66 @@ spec: exec: command: - bash - - '-c' - - > + - -c + - | set -e - # If the node is starting up wait for the cluster to be ready + # Exit if ELASTIC_PASSWORD in unset + if [ -z "${ELASTIC_PASSWORD}" ]; then + echo "ELASTIC_PASSWORD variable is missing, exiting" + exit 1 + fi + + # If the node is starting up wait for the cluster to be ready (request params: "{{ .Values.clusterHealthCheckParams }}" ) # Once it has started only check that the node itself is responding START_FILE=/tmp/.es_start_file - # Disable nss cache (kept for compatibility) + # Disable nss cache to avoid filling dentry cache when calling curl + # This is required with Elasticsearch Docker using nss < 3.52 export NSS_SDB_USE_CACHE=no http () { local path="${1}" local args="${2}" - curl -XGET -s --output /dev/null -w "%{http_code}" "http://127.0.0.1:9200${path}" ${args} + set -- -XGET -s + + if [ "$args" != "" ]; then + set -- "$@" $args + fi + + set -- "$@" -u "elastic:${ELASTIC_PASSWORD}" + + curl --output /dev/null -k "$@" "{{ .Values.protocol }}://127.0.0.1:{{ .Values.httpPort }}${path}" } if [ -f "${START_FILE}" ]; then - echo 'Elasticsearch is already running, checking node health' - HTTP_CODE=$(http "/") + echo 'Elasticsearch is already running, lets check the node is healthy' + HTTP_CODE=$(http "/" "-w %{http_code}") + RC=$? + if [[ ${RC} -ne 0 ]]; then + echo "curl --output /dev/null -k -XGET -s -w '%{http_code}' \${BASIC_AUTH} {{ .Values.protocol }}://127.0.0.1:{{ .Values.httpPort }}/ failed with RC ${RC}" + exit ${RC} + fi + # ready if HTTP code 200, 503 is tolerable if ES version is 6.x if [[ ${HTTP_CODE} == "200" ]]; then exit 0 + elif [[ ${HTTP_CODE} == "503" && "{{ include "elasticsearch.esMajorVersion" . }}" == "6" ]]; then + exit 0 else - echo "Health check failed with HTTP code ${HTTP_CODE}" + echo "curl --output /dev/null -k -XGET -s -w '%{http_code}' \${BASIC_AUTH} {{ .Values.protocol }}://127.0.0.1:{{ .Values.httpPort }}/ failed with HTTP code ${HTTP_CODE}" exit 1 fi + else - echo 'Waiting for elasticsearch cluster to become ready' - if http "/_cluster/health?wait_for_status=green&timeout=1s" "--fail"; then + echo 'Waiting for elasticsearch cluster to become ready (request params: "{{ .Values.clusterHealthCheckParams }}" )' + if http "/_cluster/health?{{ .Values.clusterHealthCheckParams }}" "--fail" ; then touch ${START_FILE} exit 0 else - echo 'Cluster is not yet ready' + echo 'Cluster is not yet ready (request params: "{{ .Values.clusterHealthCheckParams }}" )' exit 1 fi fi - {{ toYaml .Values.readinessProbe | indent 10 }} ports: - name: http