Skip to content

trying auto discover #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/elastic/helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- define "elasticsearch.masterNodes" -}}
es-master-0.es-master,es-master-1.es-master,es-master-2.es-master
{{- end -}}
2 changes: 1 addition & 1 deletion examples/elastic/helm/templates/identity.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
kind: identity
name: {{ .Values.elasticsearch.identity.name }}
name: {{ .Values.elasticsearch.identity.name }}{{ .Values.elasticsearch.nameSuffix }}
6 changes: 3 additions & 3 deletions examples/elastic/helm/templates/policy.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
kind: policy
name: elasticsearch-policy-{{ .Values.cpln.gvc }}
name: elasticsearch-policy-{{ .Values.cpln.gvc }}{{ .Values.elasticsearch.nameSuffix }}
origin: default
bindings:
- permissions:
Expand All @@ -8,5 +8,5 @@ bindings:
- //gvc/{{ .Values.cpln.gvc }}/identity/{{ .Values.elasticsearch.identity.name }}
targetKind: secret
targetLinks:
- //secret/elasticsearch-config-{{ .Values.cpln.gvc }}
- //secret/elasticsearch-init-{{ .Values.cpln.gvc }}
- //secret/elasticsearch-config-{{ .Values.cpln.gvc }}{{ .Values.elasticsearch.nameSuffix }}
- //secret/elasticsearch-init-{{ .Values.cpln.gvc }}{{ .Values.elasticsearch.nameSuffix }}
117 changes: 48 additions & 69 deletions examples/elastic/helm/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
kind: secret
name: elasticsearch-config-{{ .Values.cpln.gvc }}
name: elasticsearch-config-{{ .Values.cpln.gvc }}{{ .Values.elasticsearch.nameSuffix }}
type: opaque
data:
encoding: plain
Expand All @@ -10,20 +10,49 @@ data:
xpack.security.enabled: {{ .Values.elasticsearch.config.security.enabled }}
node.name: node-name-placeholder

# Recovery and allocation settings
cluster.routing.allocation.node_concurrent_incoming_recoveries: {{ .Values.elasticsearch.config.recovery.incomingRecoveries }}
cluster.routing.allocation.node_concurrent_outgoing_recoveries: {{ .Values.elasticsearch.config.recovery.outgoingRecoveries }}
indices.recovery.max_bytes_per_sec: {{ .Values.elasticsearch.config.recovery.maxBytesPerSec }}

# Bulk operation settings
http.max_content_length: 100mb
http.max_initial_line_length: 4kb
http.max_header_size: 8kb
http.compression: true
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-methods: OPTIONS, HEAD, GET, POST, PUT, DELETE
http.cors.allow-headers: X-Requested-With, X-Auth-Token, Content-Type, Content-Length, Authorization

# Node roles based on environment variable
node.roles: ${NODE_ROLES}

# Discovery configuration
discovery.seed_hosts:
{{- if .Values.elasticsearch.nodes.master.enabled }}
{{- range $i := until (.Values.elasticsearch.nodes.master.replicas | int) }}
- es-master-{{ $i }}.es-master
{{- range $nodeType, $config := .Values.elasticsearch.nodes }}
{{- if $config.enabled }}
- es-{{ $nodeType }}.{{ $.Values.cpln.gvc }}.cpln.local
{{- end }}
{{- end }}

# Network settings
network.publish_host: ${POD_NAME}.{{ .Values.cpln.gvc }}.cpln.local
network.bind_host: 0.0.0.0

# Cluster settings
cluster.initial_master_nodes:
{{- range $nodeType, $config := .Values.elasticsearch.nodes }}
{{- if $config.enabled }}
{{- range $i, $e := until (int $config.replicas) }}
- es-{{ $nodeType }}-{{ $i }}.{{ $.Values.cpln.gvc }}.cpln.local
{{- end }}
{{- end }}
{{- end }}

---
kind: secret
name: elasticsearch-init-{{ .Values.cpln.gvc }}
name: elasticsearch-init-{{ .Values.cpln.gvc }}{{ .Values.elasticsearch.nameSuffix }}
type: opaque
data:
encoding: plain
Expand All @@ -35,75 +64,25 @@ data:
set -o pipefail
set -x

error(){
local message="${1:?missing message}"
echo "ERROR: ${message}"
exit 1
}
# Debug: Print environment variables
echo "Environment variables:"
env | sort

cp /usr/share/elasticsearch/config-custom/elasticsearch.yml /usr/share/elasticsearch/config/elasticsearch.yml
# Set node name
NODE_NAME="${POD_NAME}.{{ .Values.cpln.gvc }}.cpln.local"
echo "Setting node name to: $NODE_NAME"

# Copy and configure elasticsearch.yml
cp /usr/share/elasticsearch/config-custom/elasticsearch.yml /usr/share/elasticsearch/config/elasticsearch.yml
ELASTIC_CONFIG_FILE=/usr/share/elasticsearch/config/elasticsearch.yml

replace_placeholder() {
local placeholder="${1:?missing placeholder value}"
local value="${2:?missing value}"
sed -i "s/$placeholder/$value/g" "$ELASTIC_CONFIG_FILE"
}

POD_ID=$(echo "$POD_NAME" | rev | cut -d'-' -f 1 | rev)
WORKLOAD_NAME=$(echo $CPLN_WORKLOAD | sed 's|.*/workload/\([^/]*\)$|\1|')

replace_placeholder "node-name-placeholder" "${POD_NAME}.${WORKLOAD_NAME}"

echo "Starting Elasticsearch process in the background..."
/usr/local/bin/docker-entrypoint.sh &

ELASTIC_PID=$!

echo "Waiting for Elasticsearch service to be available..."
while ! curl -s http://localhost:9200 > /dev/null; do
echo "Elasticsearch is not yet available. Retrying in 5 seconds..."
sleep 5
done

# Check if this is a master node
if [[ "$NODE_ROLES" == *"master"* ]]; then
CLUSTER_STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:9200/_cluster/health || echo "000")

if [[ "$CLUSTER_STATUS" -ne 200 ]]; then
echo "Cluster is not initialized. Adding cluster.initial_master_nodes to configuration."

# Add cluster.initial_master_nodes only if not already present
if ! grep -q "cluster.initial_master_nodes" "$ELASTIC_CONFIG_FILE"; then
echo "Adding cluster.initial_master_nodes..."
cat <<EOF >> "$ELASTIC_CONFIG_FILE"

cluster.initial_master_nodes:
{{- if .Values.elasticsearch.nodes.master.enabled }}
{{- range $i := until (.Values.elasticsearch.nodes.master.replicas | int) }}
- es-master-{{ $i }}.es-master
{{- end }}
{{- end }}
EOF
else
echo "cluster.initial_master_nodes already present in configuration. Skipping."
fi
else
echo "Cluster is already initialized. Skipping cluster.initial_master_nodes configuration."
fi
else
echo "This node is not a master node. Skipping cluster.initial_master_nodes configuration."
fi

# Stop the initial Elasticsearch process
echo "Stopping the initial Elasticsearch process..."
kill $ELASTIC_PID
wait $ELASTIC_PID 2>/dev/null || true
# Replace node name placeholder
sed -i "s/node-name-placeholder/$NODE_NAME/g" "$ELASTIC_CONFIG_FILE"

echo "Printing elasticsearch.yml"
# Print configuration for debugging
echo "Elasticsearch configuration:"
cat $ELASTIC_CONFIG_FILE

# Restart Elasticsearch process to apply configuration changes
echo "Restarting Elasticsearch process..."
# Start Elasticsearch
echo "Starting Elasticsearch process..."
exec /usr/local/bin/docker-entrypoint.sh
8 changes: 4 additions & 4 deletions examples/elastic/helm/templates/volumeset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
{{- if $config.enabled }}
---
kind: volumeset
name: es-{{ $nodeType }}-data
name: es-{{ $nodeType }}-data{{ $.Values.elasticsearch.nameSuffix }}
description: "Elasticsearch {{ $nodeType }} volume"
spec:
fileSystemType: {{ $.Values.elasticsearch.volume.fileSystemType }}
initialCapacity: {{ index $.Values.elasticsearch.volume $nodeType "initialCapacity" }}
performanceClass: {{ $.Values.elasticsearch.volume.performanceClass }}
fileSystemType: {{ $config.volume.fileSystemType | default $.Values.elasticsearch.volume.fileSystemType }}
initialCapacity: {{ $config.volume.initialCapacity }}
performanceClass: {{ $config.volume.performanceClass | default $.Values.elasticsearch.volume.performanceClass }}
{{- end }}
{{- end }}
13 changes: 11 additions & 2 deletions examples/elastic/helm/templates/workload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{- if $config.enabled }}
---
kind: workload
name: es-{{ $nodeType }}
name: es-{{ $nodeType }}{{ $.Values.elasticsearch.nameSuffix }}
description: "Elasticsearch {{ $nodeType }} node"
spec:
type: stateful
Expand All @@ -19,6 +19,15 @@ spec:
env:
- name: NODE_ROLES
value: "[{{ $config.roles }}]"
{{- if $config.jvm }}
- name: ES_JAVA_OPTS
value: >-
-Xms{{ $config.jvm.heapSize }}
-Xmx{{ $config.jvm.heapSize }}
-XX:MaxDirectMemorySize={{ $config.jvm.maxDirectMemorySize }}
-XX:InitiatingHeapOccupancyPercent={{ $config.jvm.initiatingHeapOccupancyPercent }}
-XX:G1ReservePercent={{ $config.jvm.g1ReservePercent }}
{{- end }}
livenessProbe:
exec:
command:
Expand Down Expand Up @@ -50,7 +59,7 @@ spec:
volumes:
- path: /usr/share/elasticsearch/data
recoveryPolicy: retain
uri: 'cpln://volumeset/es-{{ $nodeType }}-data'
uri: 'cpln://volumeset/es-{{ $nodeType }}-data{{ $.Values.elasticsearch.nameSuffix }}'
- path: /usr/share/elasticsearch/config-custom/elasticsearch.yml
recoveryPolicy: retain
uri: 'cpln://secret/elasticsearch-config-{{ $.Values.cpln.gvc }}'
Expand Down
85 changes: 62 additions & 23 deletions examples/elastic/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,8 @@ elasticsearch:
name: elasticsearch

volume:
fileSystemType: ext4
fileSystemType: xfs
performanceClass: general-purpose-ssd
master:
initialCapacity: 10
data:
initialCapacity: 20
ingest:
initialCapacity: 10

config:
clusterName: "elasticsearch-cluster"
Expand All @@ -27,42 +21,87 @@ elasticsearch:
allowMmap: false
security:
enabled: false
recovery:
incomingRecoveries: 50
outgoingRecoveries: 50
maxBytesPerSec: "2000mb"
discovery:
initialMasterNodes: ["es-master-0.es-master", "es-master-1.es-master", "es-master-2.es-master"]
zen:
minimumMasterNodes: 2
pingTimeout: 10s
joinTimeout: 30s
cluster:
initialMasterNodes: ["es-master-0.es-master", "es-master-1.es-master", "es-master-2.es-master"]
waitForActiveShards: "majority"
network:
host: "0.0.0.0"
publish_host: "${HOSTNAME}.${WORKLOAD_NAME}"
bootstrap:
memory_lock: true

nodes:
master:
enabled: true
replicas: 3
roles: master # Comma separated list https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-node.html
resources:
cpu: 2000m
memory: 4Gi
cpu: "3000m"
memory: "16Gi"
roles: "master,remote_cluster_client"
volume:
fileSystemType: "xfs"
size: "100Gi"
initialCapacity: 100
data:
enabled: true
replicas: 3
roles: data # Comma separated list https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-node.html
resources:
cpu: 4000m
memory: 16Gi
cpu: "4000m"
memory: "16Gi"
roles: "data,data_content,data_hot,data_warm,data_cold"
volume:
fileSystemType: "xfs"
size: "100Gi"
initialCapacity: 100

ingest:
enabled: true
replicas: 2
roles: ingest # Comma separated list https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-node.html
roles: "ingest,remote_cluster_client"
resources:
cpu: 2000m
memory: 8Gi
cpu: "3000m"
memory: "16Gi"
volume:
initialCapacity: 10
fileSystemType: xfs
performanceClass: general-purpose-ssd

coordinator:
enabled: true
replicas: 2
roles: "remote_cluster_client"
resources:
cpu: "3000m"
memory: "16Gi"
volume:
initialCapacity: 10
fileSystemType: xfs
performanceClass: general-purpose-ssd

probes:
liveness:
initialDelay: 60
period: 15
timeout: 3
initialDelay: 120
period: 30
timeout: 5
readiness:
initialDelay: 10
period: 5
timeout: 3
initialDelay: 30
period: 10
timeout: 5

ports:
- number: 9200
protocol: http
- number: 9300
protocol: tcp
protocol: tcp

nameSuffix: ""