Skip to content

Commit 3421ca7

Browse files
committed
cluster,config,sidecar,utils: support the MySQL8.0 #176
1 parent a6386c7 commit 3421ca7

File tree

14 files changed

+302
-108
lines changed

14 files changed

+302
-108
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ docker-build: test ## Build docker image with the manager.
7373
docker build -t ${IMG} .
7474
docker build -f Dockerfile.sidecar -t ${SIDECAR_IMG} .
7575
docker build -f hack/xenon/Dockerfile -t ${XENON_IMG} hack/xenon
76-
76+
mysql8-sidecar:
77+
docker build --build-arg XTRABACKUP_PKG=percona-xtrabackup-80 -f Dockerfile.sidecar -t ${SIDECAR_IMG} .
7778
docker-push: ## Push docker image with the manager.
7879
docker push ${IMG}
7980
docker push ${SIDECAR_IMG}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
apiVersion: mysql.radondb.com/v1alpha1
2+
kind: MysqlCluster
3+
metadata:
4+
name: mysql8-sample
5+
spec:
6+
replicas: 3
7+
mysqlVersion: "8.0"
8+
# the backupSecretName specify the secret file name which store S3 information,
9+
# if you want S3 backup or restore, please create backup_secret.yaml, uncomment below and fill secret name:
10+
# backupSecretName:
11+
12+
# if you want create mysqlcluster from S3, uncomment and fill the directory in S3 bucket below:
13+
# restoreFrom: "backup_2022324174848"
14+
mysqlOpts:
15+
rootPassword: "RadonDB@123"
16+
rootHost: localhost
17+
user: radondb_usr
18+
password: RadonDB@123
19+
database: radondb
20+
# A simple map between string and string.
21+
# Such as:
22+
# mysqlConf:
23+
# expire_logs_days: "7"
24+
mysqlConf: {}
25+
resources:
26+
requests:
27+
cpu: 100m
28+
memory: 256Mi
29+
limits:
30+
cpu: 500m
31+
memory: 1Gi
32+
xenonOpts:
33+
image: radondb/xenon:1.1.5-alpha
34+
admitDefeatHearbeatCount: 5
35+
electionTimeout: 10000
36+
resources:
37+
requests:
38+
cpu: 50m
39+
memory: 128Mi
40+
limits:
41+
cpu: 100m
42+
memory: 256Mi
43+
metricsOpts:
44+
enabled: false
45+
image: prom/mysqld-exporter:v0.12.1
46+
resources:
47+
requests:
48+
cpu: 10m
49+
memory: 32Mi
50+
limits:
51+
cpu: 100m
52+
memory: 128Mi
53+
podPolicy:
54+
imagePullPolicy: Always
55+
sidecarImage: # fill here with image sidecar for mysql8
56+
busyboxImage: busybox:1.32
57+
slowLogTail: false
58+
auditLogTail: false
59+
labels: {}
60+
annotations: {}
61+
affinity: {}
62+
priorityClassName: ""
63+
tolerations: []
64+
schedulerName: ""
65+
# extraResources defines quotas for containers other than mysql or xenon.
66+
extraResources:
67+
requests:
68+
cpu: 10m
69+
memory: 32Mi
70+
persistence:
71+
enabled: true
72+
accessModes:
73+
- ReadWriteOnce
74+
#storageClass: ""
75+
size: 20Gi
76+
backupSecretName: sample-backup-secret
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Deploy
2+
use sample `config/samples/mysql_v1alpha1_mysqlcluster_mysql8.yaml` , modify the `spec.podPolicy.sidecarImage` to MySQL8 version sidecar image.
3+
install step
4+
[deploy reference](deploy_radondb-mysql_operator_on_kubesphere.md)
5+
# How to build sidecar images?
6+
After you had installed docker , use command:
7+
```
8+
make mysql8-sidecar
9+
```
10+
it will build mysql8 sidecar image.Then `docker push xxx` to push to docker hub.

mysqlcluster/container/init_mysql.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ func (c *initMysql) getImage() string {
4444

4545
// getCommand get the container command.
4646
func (c *initMysql) getCommand() []string {
47-
return nil
47+
// Because initialize mysql contain error, so do it in commands.
48+
return []string{"sh", "-c", "/docker-entrypoint.sh mysqld;if test -f /docker-entrypoint-initdb.d/special.sh; then /docker-entrypoint-initdb.d/special.sh; fi "}
4849
}
4950

5051
// getEnvVars get the container env.

mysqlcluster/container/init_mysql_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func TestGetInitMysqlImage(t *testing.T) {
115115
}
116116

117117
func TestGetInitMysqlCommand(t *testing.T) {
118-
assert.Nil(t, initMysqlCase.Command)
118+
assert.Equal(t, initMysqlCase.Command, []string{"sh", "-c", "/docker-entrypoint.sh mysqld;if test -f /docker-entrypoint-initdb.d/special.sh; then /docker-entrypoint-initdb.d/special.sh; fi "})
119119
}
120120

121121
func TestGetInitMysqlEnvVar(t *testing.T) {

mysqlcluster/mysqlcluster.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ func (c *MysqlCluster) Validate() error {
7070
if utils.StringInArray(c.Spec.MysqlOpts.User, []string{"root", utils.ReplicationUser, utils.OperatorUser, utils.MetricsUser}) {
7171
return fmt.Errorf("spec.mysqlOpts.user cannot be root|%s|%s|%s", utils.ReplicationUser, utils.OperatorUser, utils.MetricsUser)
7272
}
73-
73+
// MySQL8 nerver support TokuDB
74+
// https://www.percona.com/blog/2021/05/21/tokudb-support-changes-and-future-removal-from-percona-server-for-mysql-8-0/
75+
if c.Spec.MysqlVersion == "8.0" && c.Spec.MysqlOpts.InitTokuDB {
76+
log.Info("TokuDB is not supported in MySQL 8.0 any more, the value in Cluster.spec.mysqlOpts.initTokuDB should be set false")
77+
return nil
78+
}
7479
// https://github.com/percona/percona-docker/blob/main/percona-server-5.7/ps-entry.sh#L159
7580
// ERROR 1396 (HY000): Operation CREATE USER failed for 'root'@'127.0.0.1'.
7681
if c.Spec.MysqlOpts.RootHost == "127.0.0.1" {
@@ -91,12 +96,17 @@ func (c *MysqlCluster) GetLabels() labels.Set {
9196
if comp, ok := c.Annotations["app.kubernetes.io/component"]; ok {
9297
component = comp
9398
}
94-
99+
// version := ""
100+
// if _, ok := c.Labels["app.kubernetes.io/version"]; !ok {
101+
// version = c.GetMySQLVersion()
102+
// }
95103
labels := labels.Set{
96-
"mysql.radondb.com/cluster": c.Name,
97-
"app.kubernetes.io/name": "mysql",
98-
"app.kubernetes.io/instance": instance,
99-
"app.kubernetes.io/version": c.GetMySQLVersion(),
104+
"mysql.radondb.com/cluster": c.Name,
105+
"app.kubernetes.io/name": "mysql",
106+
"app.kubernetes.io/instance": instance,
107+
// Notice: if app.kubernetes.io/version changed, then statefulset update will failure, It is not need to do this.
108+
// So delete this label.
109+
//"app.kubernetes.io/version": version,
100110
"app.kubernetes.io/component": component,
101111
"app.kubernetes.io/managed-by": "mysql.radondb.com",
102112
}

mysqlcluster/mysqlcluster_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ func TestGetLabel(t *testing.T) {
7272
&testMysqlCluster,
7373
}
7474
want := labels.Set{
75-
"mysql.radondb.com/cluster": "sample",
76-
"app.kubernetes.io/name": "mysql",
77-
"app.kubernetes.io/instance": "instance",
78-
"app.kubernetes.io/version": "5.7.34",
75+
"mysql.radondb.com/cluster": "sample",
76+
"app.kubernetes.io/name": "mysql",
77+
"app.kubernetes.io/instance": "instance",
78+
//"app.kubernetes.io/version": "5.7.34",
7979
"app.kubernetes.io/component": "database",
8080
"app.kubernetes.io/managed-by": "mysql.radondb.com",
8181
}
@@ -91,10 +91,10 @@ func TestGetLabel(t *testing.T) {
9191
&testMysqlCluster,
9292
}
9393
want := labels.Set{
94-
"mysql.radondb.com/cluster": "sample",
95-
"app.kubernetes.io/name": "mysql",
96-
"app.kubernetes.io/instance": "sample",
97-
"app.kubernetes.io/version": "5.7.34",
94+
"mysql.radondb.com/cluster": "sample",
95+
"app.kubernetes.io/name": "mysql",
96+
"app.kubernetes.io/instance": "sample",
97+
//"app.kubernetes.io/version": "5.7.34",
9898
"app.kubernetes.io/component": "component",
9999
"app.kubernetes.io/managed-by": "mysql.radondb.com",
100100
}
@@ -110,10 +110,10 @@ func TestGetLabel(t *testing.T) {
110110
&testMysqlCluster,
111111
}
112112
want := labels.Set{
113-
"mysql.radondb.com/cluster": "sample",
114-
"app.kubernetes.io/name": "mysql",
115-
"app.kubernetes.io/instance": "sample",
116-
"app.kubernetes.io/version": "5.7.34",
113+
"mysql.radondb.com/cluster": "sample",
114+
"app.kubernetes.io/name": "mysql",
115+
"app.kubernetes.io/instance": "sample",
116+
//"app.kubernetes.io/version": "5.7.34",
117117
"app.kubernetes.io/component": "database",
118118
"app.kubernetes.io/managed-by": "mysql.radondb.com",
119119
"app.kubernetes.io/part-of": "part-of",
@@ -139,7 +139,7 @@ func TestGetMySQLVersion(t *testing.T) {
139139
testCase := MysqlCluster{
140140
&testMysqlCluster,
141141
}
142-
want := utils.InvalidMySQLVersion
142+
want := "8.0.25"
143143
assert.Equal(t, want, testCase.GetMySQLVersion())
144144
}
145145
// MySQLTagsToSemVer 5.7 -> 5.7.34

mysqlcluster/syncer/config_map.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,13 @@ func NewConfigMapSyncer(cli client.Client, c *mysqlcluster.MysqlCluster) syncer.
5151
return fmt.Errorf("failed to create mysql configs: %s", err)
5252
}
5353

54+
dataSpecial, err := buildMysqlSpecialConf(c)
55+
if err != nil {
56+
return fmt.Errorf("failed to create mysql special configs: %s", err)
57+
}
5458
cm.Data = map[string]string{
55-
"my.cnf": data,
59+
"my.cnf": data,
60+
utils.SpecialConfig: dataSpecial,
5661
}
5762

5863
return nil
@@ -65,7 +70,10 @@ func buildMysqlConf(c *mysqlcluster.MysqlCluster) (string, error) {
6570
sec := cfg.Section("mysqld")
6671

6772
c.EnsureMysqlConf()
68-
73+
if c.Spec.MysqlVersion == "8.0" {
74+
delete(mysqlCommonConfigs, "query_cache_size")
75+
delete(mysqlStaticConfigs, "query_cache_type")
76+
}
6977
addKVConfigsToSection(sec, mysqlSysConfigs, mysqlCommonConfigs, mysqlStaticConfigs, c.Spec.MysqlOpts.MysqlConf)
7078

7179
if c.Spec.MysqlOpts.InitTokuDB {
@@ -86,6 +94,20 @@ func buildMysqlConf(c *mysqlcluster.MysqlCluster) (string, error) {
8694
return data, nil
8795
}
8896

97+
// Build the Special Cnf file.
98+
func buildMysqlSpecialConf(c *mysqlcluster.MysqlCluster) (string, error) {
99+
cfg := ini.Empty(ini.LoadOptions{IgnoreInlineComment: true})
100+
sec := cfg.Section("mysqld")
101+
102+
addKVConfigsToSection(sec, mysql8Configs)
103+
data, err := writeConfigs(cfg)
104+
if err != nil {
105+
return "", err
106+
}
107+
108+
return data, nil
109+
}
110+
89111
// addKVConfigsToSection add a map[string]string to a ini.Section
90112
func addKVConfigsToSection(s *ini.Section, extraMysqld ...map[string]string) {
91113
for _, extra := range extraMysqld {

mysqlcluster/syncer/headless_service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func NewHeadlessSVCSyncer(cli client.Client, c *mysqlcluster.MysqlCluster) synce
5151
service.Spec.Selector = labels.Set{
5252
"app.kubernetes.io/name": "mysql",
5353
"app.kubernetes.io/managed-by": "mysql.radondb.com",
54+
"app.kubernetes.io/instance": c.Name,
5455
}
5556

5657
// Use `publishNotReadyAddresses` to be able to access pods even if the pod is not ready.

mysqlcluster/syncer/statefulset.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"fmt"
2323
"time"
2424

25+
"github.com/go-test/deep"
2526
"github.com/iancoleman/strcase"
2627
"github.com/imdario/mergo"
2728
"github.com/presslabs/controller-util/mergo/transformers"
@@ -271,6 +272,8 @@ func (s *StatefulSetSyncer) createOrUpdate(ctx context.Context) (controllerutil.
271272
if equality.Semantic.DeepEqual(existing, s.sfs) {
272273
return controllerutil.OperationResultNone, nil
273274
}
275+
log.Info("update statefulset", "name", s.Name, "diff", deep.Equal(existing, s.sfs))
276+
274277
// If changed, update statefulset.
275278
if err := s.cli.Update(ctx, s.sfs); err != nil {
276279
return controllerutil.OperationResultNone, err

0 commit comments

Comments
 (0)