Skip to content

Commit

Permalink
chore: support 0.9 api for mysql addon (#1036)
Browse files Browse the repository at this point in the history
  • Loading branch information
xuriwuyun authored Sep 13, 2024
1 parent aa39f81 commit 6935e5a
Show file tree
Hide file tree
Showing 11 changed files with 503 additions and 4 deletions.
2 changes: 1 addition & 1 deletion addons-cluster/mysql-cluster/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ annotations:
apiVersion: v2
name: mysql-cluster
type: application
version: 0.9.0
version: 0.9.3
description: MySQL is a widely used, open-source relational database management system (RDBMS)
dependencies:
- name: kblib
Expand Down
1 change: 1 addition & 0 deletions addons-cluster/mysql-cluster/templates/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ spec:
clusterDefinitionRef: mysql # ref clusterdefinition.name
componentSpecs:
- name: mysql
componentDef: {{ .Values.compdef }}
componentDefRef: mysql # ref clusterdefinition componentDefs.name
{{- include "kblib.componentMonitor" . | indent 6 }}
{{- include "mysql-cluster.replicaCount" . | indent 6 }}
Expand Down
11 changes: 11 additions & 0 deletions addons-cluster/mysql-cluster/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
"raftGroup"
]
},
"compdef": {
"title": "componentdefinition",
"description": "Cluster component definition.",
"type": "string",
"default": "mysql-8.0",
"enum": [
"mysql-5.7",
"mysql-8.0",
"mysql-8.4"
]
},
"replicas": {
"title": "Replicas",
"description": "The number of replicas.",
Expand Down
2 changes: 2 additions & 0 deletions addons-cluster/mysql-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ requests:
## @param storage size, the unit is Gi
##
storage: 20

compdef: mysql-8.0
4 changes: 2 additions & 2 deletions addons/mysql/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: MySQL is a widely used, open-source relational database management

type: application

version: 0.9.2
version: 0.9.3

# This is the version number of the ApeCloud MySQL being deployed,
# rather than the version number of ApeCloud MySQL-Scale itself.
Expand All @@ -28,4 +28,4 @@ sources:
annotations:
addon.kubeblocks.io/kubeblocks-version: ">=0.9.0"
addon.kubeblocks.io/model: "RDBMS"
addon.kubeblocks.io/provider: "community"
addon.kubeblocks.io/provider: "community"
181 changes: 180 additions & 1 deletion addons/mysql/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,79 @@ Create the name of the service account to use
{{- end }}
{{- end }}

{{/*
Define mysql component definition name
*/}}
{{- define "mysql.componentDefName" -}}
{{- if eq (len .Values.compDefinitionVersionSuffix) 0 -}}
mysql
{{- else -}}
{{- printf "mysql-%s" .Values.compDefinitionVersionSuffix -}}
{{- end -}}
{{- end -}}

{{/*
Define mysql component definition regex regular
*/}}
{{- define "mysql.componentDefRegex" -}}
^mysql-\d+\.\d+.*$
{{- end -}}

{{/*
Define mysql component definition name
*/}}
{{- define "mysql.componentDefName57" -}}
{{- if eq (len .Values.compDefinitionVersionSuffix) 0 -}}
mysql-5.7
{{- else -}}
{{- printf "mysql-5.7-%s" .Values.compDefinitionVersionSuffix -}}
{{- end -}}
{{- end -}}

{{/*
Define mysql component definition name
*/}}
{{- define "mysql.componentDefNameOrc57" -}}
{{- if eq (len .Values.compDefinitionVersionSuffix) 0 -}}
mysql-orc-5.7
{{- else -}}
{{- printf "mysql-orc-5.7-%s" .Values.compDefinitionVersionSuffix -}}
{{- end -}}
{{- end -}}

{{/*
Define mysql component definition name
*/}}
{{- define "mysql.componentDefName80" -}}
{{- if eq (len .Values.compDefinitionVersionSuffix) 0 -}}
mysql-8.0
{{- else -}}
{{- printf "mysql-8.0-%s" .Values.compDefinitionVersionSuffix -}}
{{- end -}}
{{- end -}}

{{/*
Define mysql component definition name
*/}}
{{- define "mysql.componentDefNameOrc80" -}}
{{- if eq (len .Values.compDefinitionVersionSuffix) 0 -}}
mysql-orc-8.0
{{- else -}}
{{- printf "mysql-orc-8.0-%s" .Values.compDefinitionVersionSuffix -}}
{{- end -}}
{{- end -}}

{{/*
Define mysql component definition name
*/}}
{{- define "mysql.componentDefName84" -}}
{{- if eq (len .Values.compDefinitionVersionSuffix) 0 -}}
mysql-8.4
{{- else -}}
{{- printf "mysql-8.4-%s" .Values.compDefinitionVersionSuffix -}}
{{- end -}}
{{- end -}}

{{/*
apecloud-otel config
*/}}
Expand Down Expand Up @@ -156,4 +229,110 @@ service:

{{- define "mysql.imagePullPolicy" -}}
{{ default "IfNotPresent" .Values.image.pullPolicy }}
{{- end }}
{{- end }}

{{- define "mysql.spec.common" -}}
provider: kubeblocks
serviceKind: mysql
description: mysql component definition for Kubernetes
updateStrategy: BestEffortParallel

services:
- name: mysql-server
serviceName: mysql-server
roleSelector: primary
spec:
ports:
- name: mysql
port: 3306
targetPort: mysql
- name: mysql
serviceName: mysql
podService: true
spec:
ports:
- name: mysql
port: 3306
targetPort: mysql

scripts:
- name: mysql-scripts
templateRef: mysql-scripts
namespace: {{ .Release.Namespace }}
volumeName: scripts
defaultMode: 0555
volumes:
- name: data
needSnapshot: true
systemAccounts:
- name: root
initAccount: true
passwordGenerationPolicy:
length: 10
numDigits: 5
numSymbols: 0
letterCase: MixedCases
vars:
- name: MYSQL_ROOT_USER
valueFrom:
credentialVarRef:
name: root
username: Required

- name: MYSQL_ROOT_PASSWORD
valueFrom:
credentialVarRef:
name: root
password: Required
lifecycleActions:
roleProbe:
builtinHandler: mysql
periodSeconds: {{ .Values.roleProbe.periodSeconds }}
timeoutSeconds: {{ .Values.roleProbe.timeoutSeconds }}
roles:
- name: primary
serviceable: true
writable: true
- name: secondary
serviceable: true
writable: false
{{- end }}

{{- define "mysql.spec.runtime.common" -}}
- command:
- cp
- -r
- /bin/syncer
- /config
- /tools/
image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.syncer.repository }}:{{ .Values.image.syncer.tag }}
imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }}
name: init-syncer
volumeMounts:
- mountPath: /tools
name: tools
{{- end }}

{{- define "mysql.spec.runtime.exporter" -}}
command:
- bash
- -c
- |
mysqld_exporter --mysqld.username=${MYSQLD_EXPORTER_USER} --web.listen-address=:${EXPORTER_WEB_PORT} --log.level={{.Values.metrics.logLevel}}
env:
- name: MYSQLD_EXPORTER_USER
value: $(MYSQL_ROOT_USER)
- name: MYSQLD_EXPORTER_PASSWORD
value: $(MYSQL_ROOT_PASSWORD)
- name: EXPORTER_WEB_PORT
value: "{{ .Values.metrics.service.port }}"
image: {{ .Values.metrics.image.registry | default ( .Values.image.registry | default "docker.io" ) }}/{{ .Values.metrics.image.repository }}:{{ default .Values.metrics.image.tag }}
imagePullPolicy: IfNotPresent
ports:
- name: http-metrics
containerPort: {{ .Values.metrics.service.port }}
volumeMounts:
- name: scripts
mountPath: /scripts
{{- end -}}

96 changes: 96 additions & 0 deletions addons/mysql/templates/cmpd-mysql57.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
apiVersion: apps.kubeblocks.io/v1alpha1
kind: ComponentDefinition
metadata:
name: {{ include "mysql.componentDefName57" . }}
labels:
{{- include "mysql.labels" . | nindent 4 }}
spec:
{{- include "mysql.spec.common" . | nindent 2 }}
serviceVersion: 5.7.44

configs:
- name: mysql-replication-config
templateRef: oracle-mysql5.7-config-template
constraintRef: oracle-mysql8.0-config-constraints
volumeName: mysql-config
namespace: {{ .Release.Namespace }}
reRenderResourceTypes:
- vscale
runtime:
initContainers:
- image: {{ .Values.image.registry | default "docker.io" }}/apecloud/mysql_audit_log:5.7.44
name: init-data
command:
- bash
- -c
- |
mkdir -p {{ .Values.dataMountPath }}/{log,binlog,auditlog}
cp /usr/lib/mysql/plugin/ {{ .Values.dataMountPath }}/plugin -r
imagePullPolicy: {{ default .Values.image.pullPolicy "IfNotPresent" }}
volumeMounts:
- mountPath: {{ .Values.dataMountPath }}
name: data
- command:
- cp
- -r
- /xtrabackup
- /tools/xtrabackup
image: {{ .Values.image.registry | default "docker.io" }}/apecloud/xtrabackup:2.4
imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }}
name: init-xtrabackup
volumeMounts:
- mountPath: /tools
name: tools
{{- include "mysql.spec.runtime.common" . | nindent 6 }}
containers:
- name: mysql
image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:5.7.44
imagePullPolicy: {{ default .Values.image.pullPolicy "IfNotPresent" }}
command:
- syncer
- --config-path
- /tools/config/components
- --port
- "3601"
- --
- bash
- -c
- |
mv {{ .Values.dataMountPath }}/plugin/audit_log.so /usr/lib64/mysql/plugin/
rm -rf {{ .Values.dataMountPath }}/plugin
chown -R mysql:root {{ .Values.dataMountPath }}
skip_slave_start="OFF"
if [ -f {{ .Values.dataMountPath }}/data/.restore_new_cluster ]; then
skip_slave_start="ON"
fi
/scripts/docker-entrypoint.sh mysqld --server-id $(( ${KB_POD_NAME##*-} + 1)) \
--ignore-db-dir=lost+found \
--plugin-load-add=rpl_semi_sync_master=semisync_master.so \
--plugin-load-add=rpl_semi_sync_slave=semisync_slave.so \
--plugin-load-add=audit_log=audit_log.so \
--log-bin={{.Values.dataMountPath}}/binlog/$(KB_POD_NAME)-bin \
--skip-slave-start=$skip_slave_start
volumeMounts:
- mountPath: {{ .Values.dataMountPath }}
name: data
- mountPath: /etc/mysql/conf.d
name: mysql-config
- name: scripts
mountPath: /scripts
- mountPath: /tools
name: tools
ports:
- containerPort: 3306
name: mysql
- containerPort: 3601
name: ha
env:
- name: PATH
value: /tools/xtrabackup/bin:/tools/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- name: KB_SERVICE_CHARACTER_TYPE
value: mysql
- name: MYSQL_INITDB_SKIP_TZINFO
value: "1"
- name: MYSQL_ROOT_HOST
value: {{ .Values.auth.rootHost | default "%" | quote }}

Loading

0 comments on commit 6935e5a

Please sign in to comment.