diff --git a/tools/kubeblocks_helm/pika-master-slave/script/admin.sh b/tools/kubeblocks_helm/pika-master-slave/script/admin.sh index dc50fa674..e69de29bb 100644 --- a/tools/kubeblocks_helm/pika-master-slave/script/admin.sh +++ b/tools/kubeblocks_helm/pika-master-slave/script/admin.sh @@ -1,21 +0,0 @@ -#! /bin/bash -set -x - -# 获取当前Pod的索引 -INDEX=${HOSTNAME##*-} -echo "index:${INDEX}" -# PIKA配置文件路径 -PIKA_CONF="../data/pika.conf" - -# 确保配置文件存在 - -touch $PIKA_CONF -echo $? -if [ "$INDEX" = "0" ]; then - # 如果是pika-0,配置为主节点 - ../pika/bin/pika -c ../data/pika.conf -else - # 如果不是pika-0,配置为从节点 - sed -i "s/#slaveof : master-ip:master-port/slaveof : pika-master-slave-cluster-pika:9221/" $PIKA_CONF - ../pika/bin/pika -c ../data/pika.conf -fi diff --git a/tools/kubeblocks_helm/pika-master-slave/templates/componentdefinition-pika.yaml b/tools/kubeblocks_helm/pika-master-slave/templates/componentdefinition-pika.yaml index ca6dff3a6..f06ed8b53 100644 --- a/tools/kubeblocks_helm/pika-master-slave/templates/componentdefinition-pika.yaml +++ b/tools/kubeblocks_helm/pika-master-slave/templates/componentdefinition-pika.yaml @@ -32,15 +32,30 @@ spec: volumes: - name: data lifecycleActions: - memberJoin: + postProvision: customHandler: - image: {{ include "redis.image" . }} + image: {{ include "redis.image" .}} exec: command: - - /bin/sh + - /bin/bash - -c - - "redis-cli -h ${CURRENT_POD_IP} -p ${KB_SERVICE_PORT} slaveof $(KB_MEMBER_ADDRESSES%%,*)" - preCondition: RuntimeReady + - | + IFS=',' read -r -a pod_name_array <<< ${KB_CLUSTER_COMPONENT_POD_NAME_LIST} + IFS=',' read -r -a pod_ip_array <<< ${KB_CLUSTER_COMPONENT_POD_IP_LIST} + # Ergodic name and ip array + for i in "${!pod_name_array[@]}"; do + pod_name=${pod_name_array[${i}]} + pod_ip=${pod_ip_array[${i}]} + # Extracting the digital portion of the pod + pod_number=$(echo "${pod_name}" | grep -o '[0-9]*') + # If the pod number is greater than 0 + if (( pod_number > 0 )); then + pod0_ip=${pod_ip_array[0]} + echo "exec:redis-cli -h ${pod_ip} -p 9221 slaveof ${pod0_ip}:9221" + redis-cli -h "${pod_ip}" -p 9221 slaveof "${pod0_ip}" 9221 + fi + done + preCondition: ComponentReady runtime: initContainers: - name: init-config diff --git a/tools/kubeblocks_helm/pika-master-slave/values.yaml b/tools/kubeblocks_helm/pika-master-slave/values.yaml index 4e3bd3544..58db96475 100644 --- a/tools/kubeblocks_helm/pika-master-slave/values.yaml +++ b/tools/kubeblocks_helm/pika-master-slave/values.yaml @@ -8,7 +8,7 @@ image: pullPolicy: IfNotPresent redis: registry: docker.io - repository: redislabs/redis + repository: redis pullPolicy: IfNotPresent roleProbe: pika: