Skip to content

Commit

Permalink
chore: move apecloud mysql cluster info generation to clusterdef (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
demian0110 authored Jan 2, 2024
1 parent 1a107f7 commit 5eebed7
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 28 deletions.
38 changes: 38 additions & 0 deletions addons/apecloud-mysql/scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -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
39 changes: 14 additions & 25 deletions addons/apecloud-mysql/templates/clusterdefinition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions addons/apecloud-mysql/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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: ""
resourceNamePrefix: ""

0 comments on commit 5eebed7

Please sign in to comment.