From d23a46f82883e687cf58cf261f4a05fe32a4022d Mon Sep 17 00:00:00 2001 From: Leo Sok Date: Thu, 24 Jul 2025 13:43:11 +0300 Subject: [PATCH] poststartup script moved to extra container, non init --- elasticsearch/values.yaml | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/elasticsearch/values.yaml b/elasticsearch/values.yaml index 8712428..962071e 100644 --- a/elasticsearch/values.yaml +++ b/elasticsearch/values.yaml @@ -179,7 +179,7 @@ extraContainers: - /bin/bash - -c - | - set -ex + set -ex echo "[template-loader] Waiting for Elasticsearch at $ES_URL..." for i in $(seq 1 ${MAX_RETRIES:-30}); do if curl -s "$ES_URL" >/dev/null; then @@ -189,16 +189,22 @@ extraContainers: echo "[template-loader] Attempt $i: ES not ready, sleeping..." sleep "${RETRY_INTERVAL:-5}" done - echo "[template-loader] Applying index templates..." + echo "[template-loader] Checking and applying index templates if needed..." for idx in "chat:$TEMPLATE_PATH_1" "message:$TEMPLATE_PATH_2" "user:$TEMPLATE_PATH_3"; do name="${idx%%:*}" path="${idx##*:}" - echo "[template-loader] Applying template: $name from $path..." - curl -X PUT "$ES_URL/$name" \ - -H 'Content-Type: application/json' \ - --data-binary @"$path" + # Check if index exists + if curl -sf -o /dev/null "$ES_URL/$name"; then + echo "[template-loader] Index $name already exists. Skipping." + else + echo "[template-loader] Creating index $name from $path..." + curl -X PUT "$ES_URL/$name" \ + -H 'Content-Type: application/json' \ + --data-binary @"$path" + fi done - echo "[template-loader] All templates applied. Exiting." + echo "[template-loader] All templates applied (or skipped). Exiting." + env: - name: ES_URL value: "http://elasticsearch-master:9200"