poststartup script changed to init container
This commit is contained in:
parent
cff5c00aac
commit
d7b1ece3b2
@ -178,279 +178,46 @@ extraContainers: []
|
|||||||
# command: ['do', 'something']
|
# command: ['do', 'something']
|
||||||
|
|
||||||
|
|
||||||
extraInitContainers: []
|
extraInitContainers:
|
||||||
# - name: es-index-init
|
- name: elasticsearch-template-loader
|
||||||
# image: alpine/curl:latest
|
image: alpine/curl:latest
|
||||||
# command: ['/bin/sh', '-c']
|
command:
|
||||||
# args:
|
- /bin/bash
|
||||||
# - |
|
- -c
|
||||||
# ES_HOST="elasticsearch-master" # Match your ES service name
|
- |
|
||||||
# ES_PORT="9200"
|
set -ex
|
||||||
# ELASTIC_PASSWORD=$(cat /etc/elasticsearch-password/password)
|
echo "[initContainer] Waiting for Elasticsearch at $ES_URL..."
|
||||||
# curl -u "elastic:${ELASTIC_PASSWORD}" -X PUT "http://${ES_HOST}:${ES_PORT}/chat_v1_idx?pretty" -H 'Content-Type: application/json' -d'
|
for i in $(seq 1 ${MAX_RETRIES:-30}); do
|
||||||
# {
|
if curl -s "$ES_URL" >/dev/null; then
|
||||||
# "settings": {
|
echo "[initContainer] Elasticsearch is up!"
|
||||||
# "index": {
|
break
|
||||||
# "number_of_shards": 3,
|
fi
|
||||||
# "number_of_replicas": 1,
|
echo "[initContainer] Attempt $i: ES not ready, sleeping..."
|
||||||
# "max_ngram_diff": 2
|
sleep "${RETRY_INTERVAL:-5}"
|
||||||
# },
|
done
|
||||||
# "analysis": {
|
|
||||||
# "analyzer": {
|
echo "[initContainer] Applying templates..."
|
||||||
# "ngram_analyzer": {
|
for idx in "chat:$TEMPLATE_PATH_1" "message:$TEMPLATE_PATH_2" "user:$TEMPLATE_PATH_3"; do
|
||||||
# "type": "custom",
|
name="${idx%%:*}"
|
||||||
# "tokenizer": "ngram_tokenizer",
|
path="${idx##*:}"
|
||||||
# "filter": [
|
echo "[initContainer] Applying $name from $path..."
|
||||||
# "lowercase"
|
curl -X PUT "$ES_URL/$name" \
|
||||||
# ]
|
-H 'Content-Type: application/json' \
|
||||||
# },
|
--data-binary @"$path"
|
||||||
# "standard_search_analyzer_lowercase": {
|
done
|
||||||
# "type": "custom",
|
echo "[initContainer] Done applying templates."
|
||||||
# "tokenizer": "standard",
|
env:
|
||||||
# "filter": [
|
- name: ES_URL
|
||||||
# "lowercase"
|
value: "http://elasticsearch-master:9200"
|
||||||
# ]
|
- name: TEMPLATE_PATH_1
|
||||||
# }
|
value: "/templates/chat.json"
|
||||||
# },
|
- name: TEMPLATE_PATH_2
|
||||||
# "tokenizer": {
|
value: "/templates/message.json"
|
||||||
# "ngram_tokenizer": {
|
- name: TEMPLATE_PATH_3
|
||||||
# "type": "ngram",
|
value: "/templates/user.json"
|
||||||
# "min_gram": 3,
|
volumeMounts:
|
||||||
# "max_gram": 5,
|
- name: index-template
|
||||||
# "token_chars": []
|
mountPath: /templates
|
||||||
# }
|
|
||||||
# },
|
|
||||||
# "normalizer": {
|
|
||||||
# "lowercase_normalizer": {
|
|
||||||
# "type": "custom",
|
|
||||||
# "filter": [
|
|
||||||
# "lowercase"
|
|
||||||
# ]
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# },
|
|
||||||
# "mappings": {
|
|
||||||
# "properties": {
|
|
||||||
# "id": {
|
|
||||||
# "type": "long"
|
|
||||||
# },
|
|
||||||
# "name": {
|
|
||||||
# "type": "keyword",
|
|
||||||
# "normalizer": "lowercase_normalizer"
|
|
||||||
# },
|
|
||||||
# "name_ngram": {
|
|
||||||
# "type": "text",
|
|
||||||
# "analyzer": "ngram_analyzer",
|
|
||||||
# "search_analyzer": "ngram_analyzer",
|
|
||||||
# "index_options": "offsets",
|
|
||||||
# "term_vector": "with_positions_offsets"
|
|
||||||
# },
|
|
||||||
# "description": {
|
|
||||||
# "type": "text",
|
|
||||||
# "analyzer": "standard",
|
|
||||||
# "search_analyzer": "standard_search_analyzer_lowercase",
|
|
||||||
# "index_options": "offsets",
|
|
||||||
# "term_vector": "with_positions_offsets"
|
|
||||||
# },
|
|
||||||
# "_class": {
|
|
||||||
# "type": "text",
|
|
||||||
# "fields": {
|
|
||||||
# "keyword": {
|
|
||||||
# "ignore_above": 256.0,
|
|
||||||
# "type": "keyword"
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# curl -u "elastic:${ELASTIC_PASSWORD}" -X PUT "http://${ES_HOST}:${ES_PORT}/message_v1_idx?pretty" -H 'Content-Type: application/json' -d'
|
|
||||||
# {
|
|
||||||
# "settings": {
|
|
||||||
# "index": {
|
|
||||||
# "number_of_shards": "3",
|
|
||||||
# "number_of_replicas": "1"
|
|
||||||
# },
|
|
||||||
# "analysis": {
|
|
||||||
# "analyzer": {
|
|
||||||
# "edge_ngram_index_analyzer": {
|
|
||||||
# "tokenizer": "edge_ngram_index_tokenizer",
|
|
||||||
# "filter": [
|
|
||||||
# "lowercase",
|
|
||||||
# "apostrophe",
|
|
||||||
# "classic"
|
|
||||||
# ]
|
|
||||||
# },
|
|
||||||
# "message_search_analyzer": {
|
|
||||||
# "tokenizer": "standard"
|
|
||||||
# }
|
|
||||||
# },
|
|
||||||
# "tokenizer": {
|
|
||||||
# "edge_ngram_index_tokenizer": {
|
|
||||||
# "type": "edge_ngram",
|
|
||||||
# "min_gram": 1,
|
|
||||||
# "max_gram": 20,
|
|
||||||
# "token_chars": [
|
|
||||||
# "letter",
|
|
||||||
# "digit"
|
|
||||||
# ]
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# },
|
|
||||||
# "mappings": {
|
|
||||||
# "properties": {
|
|
||||||
# "chatId": {
|
|
||||||
# "type": "long"
|
|
||||||
# },
|
|
||||||
# "messageId": {
|
|
||||||
# "type": "long"
|
|
||||||
# },
|
|
||||||
# "serverTime": {
|
|
||||||
# "type": "long"
|
|
||||||
# },
|
|
||||||
# "_class": {
|
|
||||||
# "type": "text",
|
|
||||||
# "fields": {
|
|
||||||
# "keyword": {
|
|
||||||
# "ignore_above": 256.0,
|
|
||||||
# "type": "keyword"
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# },
|
|
||||||
# "id": {
|
|
||||||
# "type": "keyword"
|
|
||||||
# },
|
|
||||||
# "text": {
|
|
||||||
# "type": "text",
|
|
||||||
# "analyzer": "edge_ngram_index_analyzer",
|
|
||||||
# "search_analyzer": "message_search_analyzer",
|
|
||||||
# "index_options": "offsets",
|
|
||||||
# "term_vector": "with_positions_offsets"
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# curl -u "elastic:${ELASTIC_PASSWORD}" -X PUT "http://${ES_HOST}:${ES_PORT}/user_v1_idx?pretty" -H 'Content-Type: application/json' -d'
|
|
||||||
# {
|
|
||||||
# "settings": {
|
|
||||||
# "index": {
|
|
||||||
# "number_of_shards": 3,
|
|
||||||
# "number_of_replicas": 1,
|
|
||||||
# "max_ngram_diff": 2
|
|
||||||
# },
|
|
||||||
# "analysis": {
|
|
||||||
# "analyzer": {
|
|
||||||
# "ngram_analyzer": {
|
|
||||||
# "type": "custom",
|
|
||||||
# "tokenizer": "ngram_tokenizer",
|
|
||||||
# "filter": [
|
|
||||||
# "lowercase"
|
|
||||||
# ]
|
|
||||||
# },
|
|
||||||
# "standard_search_analyzer_lowercase": {
|
|
||||||
# "type": "custom",
|
|
||||||
# "tokenizer": "standard",
|
|
||||||
# "filter": [
|
|
||||||
# "lowercase"
|
|
||||||
# ]
|
|
||||||
# }
|
|
||||||
# },
|
|
||||||
# "tokenizer": {
|
|
||||||
# "ngram_tokenizer": {
|
|
||||||
# "type": "ngram",
|
|
||||||
# "min_gram": 3,
|
|
||||||
# "max_gram": 5,
|
|
||||||
# "token_chars": []
|
|
||||||
# }
|
|
||||||
# },
|
|
||||||
# "normalizer": {
|
|
||||||
# "lowercase_normalizer": {
|
|
||||||
# "type": "custom",
|
|
||||||
# "filter": [
|
|
||||||
# "lowercase"
|
|
||||||
# ]
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# },
|
|
||||||
# "mappings": {
|
|
||||||
# "properties": {
|
|
||||||
# "id": {
|
|
||||||
# "type": "long"
|
|
||||||
# },
|
|
||||||
# "username": {
|
|
||||||
# "type": "keyword",
|
|
||||||
# "normalizer": "lowercase_normalizer"
|
|
||||||
# },
|
|
||||||
# "username_ngram": {
|
|
||||||
# "type": "text",
|
|
||||||
# "analyzer": "ngram_analyzer",
|
|
||||||
# "search_analyzer": "ngram_analyzer",
|
|
||||||
# "index_options": "offsets",
|
|
||||||
# "term_vector": "with_positions_offsets"
|
|
||||||
# },
|
|
||||||
# "nickname": {
|
|
||||||
# "type": "keyword",
|
|
||||||
# "normalizer": "lowercase_normalizer"
|
|
||||||
# },
|
|
||||||
# "nickname_ngram": {
|
|
||||||
# "type": "text",
|
|
||||||
# "analyzer": "ngram_analyzer",
|
|
||||||
# "search_analyzer": "ngram_analyzer",
|
|
||||||
# "index_options": "offsets",
|
|
||||||
# "term_vector": "with_positions_offsets"
|
|
||||||
# },
|
|
||||||
# "phone": {
|
|
||||||
# "type": "keyword",
|
|
||||||
# "normalizer": "lowercase_normalizer"
|
|
||||||
# },
|
|
||||||
# "phone_ngram": {
|
|
||||||
# "type": "text",
|
|
||||||
# "analyzer": "ngram_analyzer",
|
|
||||||
# "search_analyzer": "ngram_analyzer",
|
|
||||||
# "index_options": "offsets",
|
|
||||||
# "term_vector": "with_positions_offsets"
|
|
||||||
# },
|
|
||||||
# "email": {
|
|
||||||
# "type": "keyword",
|
|
||||||
# "normalizer": "lowercase_normalizer"
|
|
||||||
# },
|
|
||||||
# "email_ngram": {
|
|
||||||
# "type": "text",
|
|
||||||
# "analyzer": "ngram_analyzer",
|
|
||||||
# "search_analyzer": "ngram_analyzer",
|
|
||||||
# "index_options": "offsets",
|
|
||||||
# "term_vector": "with_positions_offsets"
|
|
||||||
# },
|
|
||||||
# "job_title": {
|
|
||||||
# "type": "keyword",
|
|
||||||
# "normalizer": "lowercase_normalizer"
|
|
||||||
# },
|
|
||||||
# "job_title_ngram": {
|
|
||||||
# "type": "text",
|
|
||||||
# "analyzer": "ngram_analyzer",
|
|
||||||
# "search_analyzer": "ngram_analyzer",
|
|
||||||
# "index_options": "offsets",
|
|
||||||
# "term_vector": "with_positions_offsets"
|
|
||||||
# },
|
|
||||||
# "_class": {
|
|
||||||
# "type": "text",
|
|
||||||
# "fields": {
|
|
||||||
# "keyword": {
|
|
||||||
# "ignore_above": 256.0,
|
|
||||||
# "type": "keyword"
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# volumeMounts:
|
|
||||||
# - name: elasticsearch-password
|
|
||||||
# mountPath: /etc/elasticsearch-password
|
|
||||||
# readOnly: true
|
|
||||||
|
|
||||||
extraVolumes:
|
extraVolumes:
|
||||||
# Mount the JSON template
|
# Mount the JSON template
|
||||||
@ -576,51 +343,51 @@ nameOverride: ""
|
|||||||
fullnameOverride: ""
|
fullnameOverride: ""
|
||||||
healthNameOverride: ""
|
healthNameOverride: ""
|
||||||
lifecycle: {}
|
lifecycle: {}
|
||||||
postStart:
|
postStart: {}
|
||||||
exec:
|
# exec:
|
||||||
command:
|
# command:
|
||||||
- /bin/bash
|
# - /bin/bash
|
||||||
- -c
|
# - -c
|
||||||
- |
|
# - |
|
||||||
echo "[postStart] Starting postStart hook..." >&2
|
# echo "[postStart] Starting postStart hook..." >&2
|
||||||
# Default values (override in env)
|
# # Default values (override in env)
|
||||||
MAX_RETRIES="${MAX_RETRIES:-30}"
|
# MAX_RETRIES="${MAX_RETRIES:-30}"
|
||||||
RETRY_INTERVAL="${RETRY_INTERVAL:-5}"
|
# RETRY_INTERVAL="${RETRY_INTERVAL:-5}"
|
||||||
# Validate required env vars
|
# # Validate required env vars
|
||||||
REQUIRED_VARS=( "ES_URL" "TEMPLATE_PATH_1" "TEMPLATE_PATH_2" "TEMPLATE_PATH_3")
|
# REQUIRED_VARS=( "ES_URL" "TEMPLATE_PATH_1" "TEMPLATE_PATH_2" "TEMPLATE_PATH_3")
|
||||||
for var in "${REQUIRED_VARS[@]}"; do
|
# for var in "${REQUIRED_VARS[@]}"; do
|
||||||
if [ -z "${!var:-}" ]; then
|
# if [ -z "${!var:-}" ]; then
|
||||||
echo "[postStart] ERROR: Required env var '$var' is not set!" >&2
|
# echo "[postStart] ERROR: Required env var '$var' is not set!" >&2
|
||||||
exit 1
|
# exit 1
|
||||||
fi
|
# fi
|
||||||
done
|
# done
|
||||||
echo "[postStart] Waiting for Elasticsearch at $ES_URL to be ready..." >&2
|
# echo "[postStart] Waiting for Elasticsearch at $ES_URL to be ready..." >&2
|
||||||
for ((i=1; i<=MAX_RETRIES; i++)); do
|
# for ((i=1; i<=MAX_RETRIES; i++)); do
|
||||||
if /usr/bin/curl -s "$ES_URL" >/dev/null; then
|
# if /usr/bin/curl -s "$ES_URL" >/dev/null; then
|
||||||
echo "[postStart] Elasticsearch is up after $i attempts!" >&2
|
# echo "[postStart] Elasticsearch is up after $i attempts!" >&2
|
||||||
break
|
# break
|
||||||
fi
|
# fi
|
||||||
if [ "$i" -eq "$MAX_RETRIES" ]; then
|
# if [ "$i" -eq "$MAX_RETRIES" ]; then
|
||||||
echo "[postStart] ERROR: Elasticsearch did not become ready after $MAX_RETRIES attempts." >&2
|
# echo "[postStart] ERROR: Elasticsearch did not become ready after $MAX_RETRIES attempts." >&2
|
||||||
exit 1
|
# exit 1
|
||||||
fi
|
# fi
|
||||||
echo "[postStart] Attempt $i: Elasticsearch not ready, retrying in $RETRY_INTERVAL seconds..." >&2
|
# echo "[postStart] Attempt $i: Elasticsearch not ready, retrying in $RETRY_INTERVAL seconds..." >&2
|
||||||
sleep "$RETRY_INTERVAL"
|
# sleep "$RETRY_INTERVAL"
|
||||||
done
|
# done
|
||||||
echo "[postStart] Applying index templates..." >&2
|
# echo "[postStart] Applying index templates..." >&2
|
||||||
for idx in "chat:$TEMPLATE_PATH_1" "message:$TEMPLATE_PATH_2" "user:$TEMPLATE_PATH_3"; do
|
# for idx in "chat:$TEMPLATE_PATH_1" "message:$TEMPLATE_PATH_2" "user:$TEMPLATE_PATH_3"; do
|
||||||
name="${idx%%:*}"
|
# name="${idx%%:*}"
|
||||||
path="${idx##*:}"
|
# path="${idx##*:}"
|
||||||
if ! /usr/bin/curl -X PUT "$ES_URL/$name" \
|
# if ! /usr/bin/curl -X PUT "$ES_URL/$name" \
|
||||||
-H 'Content-Type: application/json' \
|
# -H 'Content-Type: application/json' \
|
||||||
--data-binary @"$path"; then
|
# --data-binary @"$path"; then
|
||||||
echo "[postStart] ERROR: Failed to apply index template for '$name' from '$path'" >&2
|
# echo "[postStart] ERROR: Failed to apply index template for '$name' from '$path'" >&2
|
||||||
exit 1
|
# exit 1
|
||||||
fi
|
# fi
|
||||||
echo "[postStart] Applied template: $name" >&2
|
# echo "[postStart] Applied template: $name" >&2
|
||||||
done
|
# done
|
||||||
echo "[postStart] All index templates applied successfully." >&2
|
# echo "[postStart] All index templates applied successfully." >&2
|
||||||
|
#
|
||||||
sysctlInitContainer:
|
sysctlInitContainer:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user