Skip to content

Commit

Permalink
adapt 1.0 api
Browse files Browse the repository at this point in the history
  • Loading branch information
cjc7373 committed Oct 25, 2024
1 parent 81459e5 commit 36c1936
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 17 deletions.
10 changes: 5 additions & 5 deletions addons/tidb/scripts/pd_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

set -exo pipefail

SUBDOMAIN=${KB_CLUSTER_COMP_NAME}-headless
MY_PEER=$KB_POD_FQDN".cluster.local"
SUBDOMAIN=${PD_COMPONENT_NAME}-headless
MY_PEER=${CURRENT_POD_NAME}.${SUBDOMAIN}.${DOMAIN}

DATA_DIR="/var/lib/pd"
ARGS="--name=$HOSTNAME \
Expand All @@ -28,14 +28,14 @@ if [[ -f $DATA_DIR/join ]]; then
ARGS="${ARGS} --join=${join}"
elif [[ ! -d $DATA_DIR/member/wal ]]; then
echo "first started pod"
replicas=$(echo "${KB_POD_LIST}" | tr ',' '\n')
replicas=$(echo "${PD_POD_NAME_LIST}" | tr ',' '\n')
# FIXME: Relying on leader status to determine whether to join or initialize a cluster
# is unreliable. Consider a scenario with 3 pods: 2 start normally, while the 3rd pod
# pulls image slowly and is still initializing. During this time, the PD cluster
# achieves quorum and begins to work, thus KB's role probe succeeds.
# When the third pod eventually starts, it mistakenly attempts to join the
# cluster based on the KB_LEADER env, leading to a failure.
if [[ -n $KB_LEADER || -n $KB_FOLLOWERS ]]; then
# cluster, leading to a failure.
if [[ -n $PD_LEADER_POD_NAME ]]; then
echo "joining an existing cluster"
join=""

Expand Down
36 changes: 31 additions & 5 deletions addons/tidb/templates/componentdefinition-pd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,41 @@ spec:
description: tidb's metadata server
updateStrategy: BestEffortParallel
vars:
- name: CLUSTER_NAMESPACE
valueFrom:
clusterVarRef:
namespace: Required
- name: DOMAIN
value: "$(KB_NAMESPACE).svc{{ .Values.clusterDomain }}"
value: "$(CLUSTER_NAMESPACE).svc{{ .Values.clusterDomain }}"
- name: PD_COMPONENT_NAME
valueFrom:
componentVarRef:
compDef: tidb-pd-7
optional: false
componentName: Required
- name: PD_POD_NAME_LIST
valueFrom:
componentVarRef:
compDef: tidb-pd-7
optional: false
podNames: Required
- name: PD_LEADER_POD_NAME
valueFrom:
componentVarRef:
optional: true
podNamesForRole:
role: leader
option: Optional
runtime:
containers:
- name: pd
imagePullPolicy: IfNotPresent
env:
- name: CURRENT_POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
ports:
- containerPort: 2379
name: client
Expand Down Expand Up @@ -54,7 +83,6 @@ spec:
lifecycleActions:
roleProbe:
exec:
image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.pd.repository }}:{{ default .Chart.AppVersion .Values.image.tag }}
command:
- bash
- -c
Expand All @@ -70,12 +98,10 @@ spec:
fi
memberLeave:
exec:
# FIXME: seems like image is not needed
# this action will be executed in lorry container
image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.pd.repository }}:{{ default .Chart.AppVersion .Values.image.tag }}
command:
- bash
- -c
# FIXME: remove KB_MEMBER_ADDRESSES
- |
ADDRESS=${KB_MEMBER_ADDRESSES%%,*}
echo $KB_LEAVE_MEMBER_POD_NAME
Expand Down
22 changes: 20 additions & 2 deletions addons/tidb/templates/componentdefinition-tidb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ spec:
serviceKind: MySQL
updateStrategy: BestEffortParallel
vars:
- name: CLUSTER_NAMESPACE
valueFrom:
clusterVarRef:
namespace: Required
- name: DOMAIN
value: "$(CLUSTER_NAMESPACE).svc{{ .Values.clusterDomain }}"
- name: TIDB_COMPONENT_NAME
valueFrom:
componentVarRef:
compDef: tidb-7
optional: false
componentName: Required
- name: PD_HOST
valueFrom:
serviceVarRef:
Expand All @@ -22,11 +34,17 @@ spec:
port:
name: client
- name: PD_ADDRESS
value: "$(PD_HOST).$(KB_NAMESPACE).svc{{ .Values.clusterDomain }}:$(PD_PORT)"
value: "$(PD_HOST).$(CLUSTER_NAMESPACE).svc{{ .Values.clusterDomain }}:$(PD_PORT)"
runtime:
containers:
- name: tidb
imagePullPolicy: IfNotPresent
env:
- name: CURRENT_POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
ports:
- containerPort: 4000
name: client
Expand All @@ -38,7 +56,7 @@ spec:
- |
echo "start tidb..."
exec /tidb-server --store=tikv \
--advertise-address=${KB_POD_FQDN}{{ .Values.clusterDomain }} \
--advertise-address=${CURRENT_POD_NAME}.${TIDB_COMPONENT_NAME}-headless.${DOMAIN} \
--host=0.0.0.0 \
--path=${PD_ADDRESS} \
--log-slow-query=/var/log/tidb/slowlog \
Expand Down
26 changes: 21 additions & 5 deletions addons/tidb/templates/componentdefinition-tikv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ spec:
description: a distributed transactional key-value database
updateStrategy: BestEffortParallel
vars:
- name: CLUSTER_NAMESPACE
valueFrom:
clusterVarRef:
namespace: Required
- name: DOMAIN
value: "$(CLUSTER_NAMESPACE).svc{{ .Values.clusterDomain }}"
- name: TIKV_COMPONENT_NAME
valueFrom:
componentVarRef:
compDef: tikv-7
optional: false
componentName: Required
- name: PD_HOST
valueFrom:
serviceVarRef:
Expand All @@ -21,7 +33,7 @@ spec:
port:
name: client
- name: PD_ADDRESS
value: "$(PD_HOST).$(KB_NAMESPACE).svc{{ .Values.clusterDomain }}:$(PD_PORT)"
value: "$(PD_HOST).$(CLUSTER_NAMESPACE).svc{{ .Values.clusterDomain }}:$(PD_PORT)"
- name: TIKV_HEADLESS_SVC_HOST
valueFrom:
serviceVarRef:
Expand All @@ -31,11 +43,17 @@ spec:
optional: true
host: Required
- name: TIKV_HEADLESS_SVC_ADDRESS
value: "$(TIKV_HEADLESS_SVC_HOST).$(KB_NAMESPACE).svc{{ .Values.clusterDomain }}:20160"
value: "$(TIKV_HEADLESS_SVC_HOST).$(CLUSTER_NAMESPACE).svc{{ .Values.clusterDomain }}:20160"
runtime:
containers:
- name: tikv
imagePullPolicy: IfNotPresent
env:
- name: CURRENT_POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
ports:
- containerPort: 20160
name: peer
Expand All @@ -51,11 +69,10 @@ spec:
- -c
- |
echo "start tikv..."
DOMAIN=$KB_NAMESPACE".svc{{ .Values.clusterDomain }}"
exec /tikv-server --pd=http://${PD_ADDRESS} \
--data-dir=/var/lib/tikv \
--addr=0.0.0.0:20160 \
--advertise-addr=${KB_POD_FQDN}{{ .Values.clusterDomain }}:20160 \
--advertise-addr=${CURRENT_POD_NAME}.${TIKV_COMPONENT_NAME}-headless.${DOMAIN}:20160 \
--status-addr=0.0.0.0:20180 \
--config=/etc/tikv/tikv.toml
volumes:
Expand All @@ -70,7 +87,6 @@ spec:
lifecycleActions:
memberLeave:
exec:
image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.pd.repository }}:{{ default .Chart.AppVersion .Values.image.tag }}
command:
- bash
- -c
Expand Down
9 changes: 9 additions & 0 deletions addons/tidb/templates/componentversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ spec:
serviceVersion: "7.5.2"
images:
pd: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.pd.repository }}:v7.5.2
roleProbe: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.pd.repository }}:v7.5.2
memberLeave: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.pd.repository }}:v7.5.2
- name: "7.1.5"
serviceVersion: "7.1.5"
images:
pd: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.pd.repository }}:v7.1.5
roleProbe: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.pd.repository }}:v7.1.5
memberLeave: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.pd.repository }}:v7.1.5
- name: "6.5.10"
serviceVersion: "6.5.10"
images:
pd: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.pd.repository }}:v6.5.10
roleProbe: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.pd.repository }}:v6.5.10
memberLeave: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.pd.repository }}:v6.5.10
compatibilityRules:
- compDefs:
- "tidb-pd-7"
Expand Down Expand Up @@ -71,14 +77,17 @@ spec:
serviceVersion: "7.5.2"
images:
tikv: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.tikv.repository }}:v7.5.2
memberLeave: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.pd.repository }}:v7.5.2
- name: "7.1.5"
serviceVersion: "7.1.5"
images:
tikv: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.tikv.repository }}:v7.1.5
memberLeave: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.pd.repository }}:v7.1.5
- name: "6.5.10"
serviceVersion: "6.5.10"
images:
tikv: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.tikv.repository }}:v6.5.10
memberLeave: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.pd.repository }}:v6.5.10
compatibilityRules:
- compDefs:
- "tikv-7"
Expand Down

0 comments on commit 36c1936

Please sign in to comment.