Skip to content
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

feat: support account provision for tidb #1493

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
6 changes: 6 additions & 0 deletions addons/tidb/scripts/tidb_accountprovision.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

set -ex

eval statement=\"${KB_ACCOUNT_STATEMENT}\"
mysql -h127.0.0.1 -P"$TIDB_PORT" -u root -p"$TIDB_ROOT_PASSWORD" -e "${statement}"
5 changes: 5 additions & 0 deletions addons/tidb/scripts/tidb_postprovision.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

set -ex

mysql -h127.0.0.1 -P"$TIDB_PORT" -u root -e "set password for 'root'@'%' = '$TIDB_ROOT_PASSWORD'"
51 changes: 40 additions & 11 deletions addons/tidb/templates/componentdefinition-tidb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ spec:
name: client
- name: PD_ADDRESS
value: "$(PD_HOST).$(CLUSTER_NAMESPACE).svc{{ .Values.clusterDomain }}:$(PD_PORT)"
- name: TIDB_PORT
valueFrom:
serviceVarRef:
port:
name: client
- name: TIDB_ROOT_PASSWORD
valueFrom:
credentialVarRef:
name: root
password: Required
runtime:
containers:
- name: tidb
Expand Down Expand Up @@ -91,17 +101,36 @@ spec:
constraintRef: {{ include "tidb.tidb.configConstraintName" . }}
namespace: {{ .Release.Namespace }}
volumeName: config
# TODO: account provision is unsupported for now because lorry doesn't support accountProvision lifecycle action
# systemAccounts:
# - name: root
# lifecycleActions:
# accountProvision:
# exec:
# image: {{ .Values.image.registry | default "docker.io" }}/imega/mysql-client:10.6.4
# command:
# - mysql
# args:
# -
systemAccounts:
- name: root
initAccount: true
passwordGenerationPolicy: &defaultPasswordGenerationPolicy
length: 16
numDigits: 5
numSymbols: 0
letterCase: MixedCases
- name: kbadmin
passwordGenerationPolicy: *defaultPasswordGenerationPolicy
statement:
create: CREATE USER '${KB_ACCOUNT_NAME}'@'%' IDENTIFIED BY '${KB_ACCOUNT_PASSWORD}';GRANT ALL PRIVILEGES ON *.* TO '${KB_ACCOUNT_NAME}'@'%';
lifecycleActions:
postProvision:
preCondition: RuntimeReady
exec:
image: {{ .Values.image.registry | default "docker.io" }}/arey/mysql-client:latest
command:
- sh
- -c
- |
{{- .Files.Get "scripts/tidb_postprovision.sh" | nindent 12 }}
accountProvision:
exec:
image: {{ .Values.image.registry | default "docker.io" }}/arey/mysql-client:latest
command:
- sh
- -c
- |
{{- .Files.Get "scripts/tidb_accountprovision.sh" | nindent 12 }}
exporter:
containerName: tidb
scrapePort: "10080"
Expand Down
Loading