From 5eebed7c40e606daed0e45b7b03d1b4b12a5e610 Mon Sep 17 00:00:00 2001 From: demian0110 Date: Tue, 2 Jan 2024 20:54:33 +0800 Subject: [PATCH] chore: move apecloud mysql cluster info generation to clusterdef (#169) --- addons/apecloud-mysql/scripts/setup.sh | 38 ++++++++++++++++++ .../templates/clusterdefinition.yaml | 39 +++++++------------ addons/apecloud-mysql/values.yaml | 6 +-- 3 files changed, 55 insertions(+), 28 deletions(-) diff --git a/addons/apecloud-mysql/scripts/setup.sh b/addons/apecloud-mysql/scripts/setup.sh index af8c5d578..e20505e6a 100755 --- a/addons/apecloud-mysql/scripts/setup.sh +++ b/addons/apecloud-mysql/scripts/setup.sh @@ -1,3 +1,41 @@ #!/bin/bash +set -ex + +generate_cluster_info() { + local pod_name="${KB_POD_NAME:?missing pod name}" + local cluster_members="" + + echo "KB_MYSQL_N=${KB_MYSQL_N}" + for ((i = 0; i < KB_MYSQL_N; i++)); do + if [ $i -gt 0 ]; then + cluster_members="${cluster_members};" + fi + + host="KB_${i}_HOSTNAME" + echo "${host}=${!host:?missing member hostname}" + cluster_members="${cluster_members}${!host}:${MYSQL_CONSENSUS_PORT:-13306}" + + # compatiable with old version images + export KB_MYSQL_${i}_HOSTNAME=${!host} + done + export KB_MYSQL_CLUSTER_MEMBERS="${cluster_members}" + + export KB_MYSQL_CLUSTER_MEMBER_INDEX=${pod_name##*-}; + local pod_host="KB_${KB_MYSQL_CLUSTER_MEMBER_INDEX}_HOSTNAME" + export KB_MYSQL_CLUSTER_MEMBER_HOST=${!pod_host:?missing current member hostname} + + if [ -n "$KB_LEADER" ]; then + echo "KB_LEADER=${KB_LEADER}" + + local leader_index=${KB_LEADER##*-} + local leader_host="KB_${leader_index}_HOSTNAME" + export KB_MYSQL_CLUSTER_LEADER_HOST=${!leader_host:?missing leader hostname} + + # compatiable with old version images + export KB_MSYQL_LEADER=${KB_LEADER} + fi +} + rmdir /docker-entrypoint-initdb.d && mkdir -p /data/mysql/auditlog && mkdir -p /data/mysql/binlog && mkdir -p /data/mysql/docker-entrypoint-initdb.d && ln -s /data/mysql/docker-entrypoint-initdb.d /docker-entrypoint-initdb.d; +generate_cluster_info exec docker-entrypoint.sh diff --git a/addons/apecloud-mysql/templates/clusterdefinition.yaml b/addons/apecloud-mysql/templates/clusterdefinition.yaml index 831aabe1f..b3ed77962 100644 --- a/addons/apecloud-mysql/templates/clusterdefinition.yaml +++ b/addons/apecloud-mysql/templates/clusterdefinition.yaml @@ -111,6 +111,10 @@ spec: env: - name: SERVICE_PORT value: "3306" + - name: MYSQL_PORT + value: "3306" + - name: MYSQL_CONSENSUS_PORT + value: "13306" - name: MYSQL_ROOT_HOST value: {{ .Values.auth.rootHost | default "%" | quote }} - name: MYSQL_ROOT_USER @@ -147,31 +151,16 @@ spec: value: {{ if .Values.cluster.dynamicConfig }}{{ .Values.cluster.dynamicConfig }}{{ end }} - name: KB_EMBEDDED_WESQL value: {{ .Values.cluster.kbWeSQLImage | default "1" | quote }} - # - name: KB_MYSQL_LEADER - # valueFrom: - # configMapKeyRef: - # name: $(COMP_ENV_CM_NAME) - # key: KB_LEADER - # optional: false - # - name: KB_MYSQL_FOLLOWERS - # valueFrom: - # configMapKeyRef: - # name: $(COMP_ENV_CM_NAME) - # key: KB_FOLLOWERS - # optional: false - # - name: KB_MYSQL_N - # valueFrom: - # configMapKeyRef: - # name: $(COMP_ENV_CM_NAME) - # key: KB_REPLICA_COUNT - # optional: false - # - name: KB_MYSQL_CLUSTER_UID - # valueFrom: - # configMapKeyRef: - # name: $(COMP_ENV_CM_NAME) - # key: KB_CLUSTER_UID - # optional: false - + - name: KB_MYSQL_VOLUME_DIR + value: {{ .Values.mysqlConfigs.dataMountPath }} + - name: KB_MYSQL_CONF_FILE + value: "/opt/mysql/my.cnf" + - name: KB_MYSQL_CLUSTER_UID + value: $(KB_CLUSTER_UID) + - name: KB_MYSQL_N + value: $(KB_REPLICA_COUNT) + - name: KB_POD_NAME + value: $(KB_POD_NAME) command: ["/scripts/setup.sh"] lifecycle: preStop: diff --git a/addons/apecloud-mysql/values.yaml b/addons/apecloud-mysql/values.yaml index d3111f6f8..45fd79fcb 100644 --- a/addons/apecloud-mysql/values.yaml +++ b/addons/apecloud-mysql/values.yaml @@ -7,9 +7,9 @@ image: repository: apecloud/apecloud-mysql-server pullPolicy: IfNotPresent # Overrides the image tag whose default is the chart appVersion. - tag: 8.0.30-5.beta3.20231215.ge77d836.13 + tag: 8.0.30-5.beta3.20231215.ge77d836.14 audit: - tag: 8.0.30-5.beta3.auditlog.20231221.g6ba5e2e.13 + tag: 8.0.30-5.beta3.auditlog.20231221.g6ba5e2e.14 ## MySQL Cluster parameters cluster: @@ -122,4 +122,4 @@ wesqlscale: ## @param resourceNamePrefix Prefix for all resources name created by this chart, that can avoid name conflict ## if you install multiple releases of this chart. ## If specified, the cluster definition will use it as name. -resourceNamePrefix: "" \ No newline at end of file +resourceNamePrefix: ""