Skip to content

Commit 70068ed

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

File tree

10 files changed

+267
-103
lines changed

10 files changed

+267
-103
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

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+
data_special, err := buildSpecialMysqlConf(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+
"special.cnf": data_special,
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 buildSpecialMysqlConf(c *mysqlcluster.MysqlCluster) (string, error) {
99+
cfg := ini.Empty(ini.LoadOptions{IgnoreInlineComment: true})
100+
sec := cfg.Section("mysqld")
101+
102+
addKVConfigsToSection(sec, mysqlSpecialConfig)
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/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

mysqlcluster/syncer/variables.go

Lines changed: 62 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -17,86 +17,92 @@ limitations under the License.
1717
package syncer
1818

1919
import (
20-
logf "sigs.k8s.io/controller-runtime/pkg/log"
21-
2220
"github.com/radondb/radondb-mysql-kubernetes/utils"
21+
logf "sigs.k8s.io/controller-runtime/pkg/log"
2322
)
2423

2524
// log is for logging in this package.
2625
var log = logf.Log.WithName("mysqlcluster.syncer")
2726

2827
// mysqlSysConfigs is the map of mysql system configs.
2928
var mysqlSysConfigs = map[string]string{
30-
"default-time-zone": "+08:00",
31-
"slow_query_log_file": "/var/log/mysql/mysql-slow.log",
32-
"read_only": "ON",
33-
"binlog_format": "row",
29+
"default-time-zone": "+08:00",
30+
"slow_query_log_file": "/var/log/mysql/mysql-slow.log",
31+
"read_only": "ON",
32+
"binlog_format": "row",
33+
"log-bin": "/var/lib/mysql/mysql-bin",
34+
"log-timestamps": "SYSTEM",
35+
"innodb_open_files": "655360",
36+
"open_files_limit": "655360",
37+
38+
"gtid-mode": "ON",
39+
"enforce-gtid-consistency": "ON",
40+
"slave_parallel_type": "LOGICAL_CLOCK",
41+
"relay_log": "/var/lib/mysql/mysql-relay-bin",
42+
"relay_log_index": "/var/lib/mysql/mysql-relay-bin.index",
43+
"master_info_repository": "TABLE",
44+
"relay_log_info_repository": "TABLE",
45+
"slow_query_log": "1",
46+
"tmp_table_size": "32M",
47+
"tmpdir": "/var/lib/mysql",
48+
}
49+
50+
var mysqlSpecialConfig = map[string]string{
3451
"plugin-load": "\"semisync_master.so;semisync_slave.so;audit_log.so;connection_control.so\"",
35-
"log-bin": "/var/lib/mysql/mysql-bin",
36-
"log-timestamps": "SYSTEM",
37-
"innodb_open_files": "655360",
38-
"open_files_limit": "655360",
52+
"audit_log_file": "/var/log/mysql/mysql-audit.log",
53+
"audit_log_exclude_accounts": "\"root@localhost,root@127.0.0.1," + utils.ReplicationUser + "@%," + utils.MetricsUser + "@%\"",
54+
"audit_log_buffer_size": "16M",
3955
"rpl_semi_sync_master_enabled": "OFF",
4056
"rpl_semi_sync_slave_enabled": "ON",
4157
"rpl_semi_sync_master_wait_no_slave": "ON",
4258
"rpl_semi_sync_master_timeout": "1000000000000000000",
43-
"gtid-mode": "ON",
44-
"enforce-gtid-consistency": "ON",
45-
"slave_parallel_type": "LOGICAL_CLOCK",
46-
"relay_log": "/var/lib/mysql/mysql-relay-bin",
47-
"relay_log_index": "/var/lib/mysql/mysql-relay-bin.index",
48-
"master_info_repository": "TABLE",
49-
"relay_log_info_repository": "TABLE",
50-
"relay_log_recovery": "ON",
51-
"slow_query_log": "1",
52-
"tmp_table_size": "32M",
53-
"tmpdir": "/var/lib/mysql",
54-
"audit_log_file": "/var/log/mysql/mysql-audit.log",
55-
"audit_log_exclude_accounts": "\"root@localhost,root@127.0.0.1," + utils.ReplicationUser + "@%," + utils.MetricsUser + "@%\"",
56-
"audit_log_buffer_size": "16M",
57-
}
58-
59-
// mysqlCommonConfigs is the map of the mysql common configs.
60-
var mysqlCommonConfigs = map[string]string{
61-
"character_set_server": "utf8mb4",
62-
"interactive_timeout": "3600",
63-
"default-time-zone": "+08:00",
64-
"expire_logs_days": "7",
65-
"key_buffer_size": "33554432",
66-
"log_bin_trust_function_creators": "1",
67-
"long_query_time": "3",
68-
"binlog_cache_size": "32768",
69-
"binlog_stmt_cache_size": "32768",
70-
"max_connections": "1024",
71-
"max_connect_errors": "655360",
72-
"query_cache_size": "0",
73-
"sync_master_info": "1000",
74-
"sync_relay_log": "1000",
75-
"sync_relay_log_info": "1000",
76-
"table_open_cache": "2000",
77-
"thread_cache_size": "128",
78-
"wait_timeout": "3600",
79-
"group_concat_max_len": "1024",
80-
"slave_rows_search_algorithms": "INDEX_SCAN,HASH_SCAN",
81-
"max_allowed_packet": "1073741824",
82-
"event_scheduler": "OFF",
83-
"innodb_print_all_deadlocks": "0",
84-
"autocommit": "1",
85-
"transaction-isolation": "READ-COMMITTED",
59+
//"audit-log": "ON",
8660
"audit_log_policy": "NONE",
8761
"audit_log_rotate_on_size": "104857600",
8862
"audit_log_rotations": "6",
63+
"audit_log_format": "OLD",
8964
"connection_control_failed_connections_threshold": "3",
9065
"connection_control_min_connection_delay": "1000",
9166
"connection_control_max_connection_delay": "2147483647",
92-
"explicit_defaults_for_timestamp": "0",
93-
"innodb_adaptive_hash_index": "0",
67+
"default-authentication-plugin": "mysql_native_password",
68+
}
69+
70+
// mysqlCommonConfigs is the map of the mysql common configs.
71+
var mysqlCommonConfigs = map[string]string{
72+
"character_set_server": "utf8mb4",
73+
"interactive_timeout": "3600",
74+
"default-time-zone": "+08:00",
75+
"expire_logs_days": "7",
76+
"key_buffer_size": "33554432",
77+
"log_bin_trust_function_creators": "1",
78+
"long_query_time": "3",
79+
"binlog_cache_size": "32768",
80+
"binlog_stmt_cache_size": "32768",
81+
"max_connections": "1024",
82+
"max_connect_errors": "655360",
83+
"query_cache_size": "0",
84+
"sync_master_info": "1000",
85+
"sync_relay_log": "1000",
86+
"sync_relay_log_info": "1000",
87+
"table_open_cache": "2000",
88+
"thread_cache_size": "128",
89+
"wait_timeout": "3600",
90+
"group_concat_max_len": "1024",
91+
"slave_rows_search_algorithms": "INDEX_SCAN,HASH_SCAN",
92+
"max_allowed_packet": "1073741824",
93+
"event_scheduler": "OFF",
94+
"innodb_print_all_deadlocks": "0",
95+
"autocommit": "1",
96+
"transaction-isolation": "READ-COMMITTED",
97+
98+
"explicit_defaults_for_timestamp": "0",
99+
"innodb_adaptive_hash_index": "0",
94100
}
95101

96102
// mysqlStaticConfigs is the map of the mysql static configs.
97103
// The mysql need restart, if modify the config.
98104
var mysqlStaticConfigs = map[string]string{
99-
"audit_log_format": "OLD",
105+
100106
"default-storage-engine": "InnoDB",
101107
"back_log": "2048",
102108
"ft_min_word_len": "4",

0 commit comments

Comments
 (0)