Skip to content
Closed
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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ docker-build: test ## Build docker image with the manager.
docker build -t ${IMG} .
docker build -f Dockerfile.sidecar -t ${SIDECAR_IMG} .
docker build -f hack/xenon/Dockerfile -t ${XENON_IMG} hack/xenon

mysql8-sidecar:
docker build --build-arg XTRABACKUP_PKG=percona-xtrabackup-80 -f Dockerfile.sidecar -t ${SIDECAR_IMG} .
docker-push: ## Push docker image with the manager.
docker push ${IMG}
docker push ${SIDECAR_IMG}
Expand Down
76 changes: 76 additions & 0 deletions config/samples/mysql_v1alpha1_mysqlcluster_mysql8.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
apiVersion: mysql.radondb.com/v1alpha1
kind: MysqlCluster
metadata:
name: mysql8-sample
spec:
replicas: 3
mysqlVersion: "8.0"
# the backupSecretName specify the secret file name which store S3 information,
# if you want S3 backup or restore, please create backup_secret.yaml, uncomment below and fill secret name:
# backupSecretName:

# if you want create mysqlcluster from S3, uncomment and fill the directory in S3 bucket below:
# restoreFrom: "backup_2022324174848"
mysqlOpts:
rootPassword: "RadonDB@123"
rootHost: localhost
user: radondb_usr
password: RadonDB@123
database: radondb
# A simple map between string and string.
# Such as:
# mysqlConf:
# expire_logs_days: "7"
mysqlConf: {}
resources:
requests:
cpu: 100m
memory: 256Mi
limits:
cpu: 500m
memory: 1Gi
xenonOpts:
image: radondb/xenon:1.1.5-alpha
admitDefeatHearbeatCount: 5
electionTimeout: 10000
resources:
requests:
cpu: 50m
memory: 128Mi
limits:
cpu: 100m
memory: 256Mi
metricsOpts:
enabled: false
image: prom/mysqld-exporter:v0.12.1
resources:
requests:
cpu: 10m
memory: 32Mi
limits:
cpu: 100m
memory: 128Mi
podPolicy:
imagePullPolicy: Always
sidecarImage: radondb/mysql80-sidecar:v2.2.0
busyboxImage: busybox:1.32
slowLogTail: false
auditLogTail: false
labels: {}
annotations: {}
affinity: {}
priorityClassName: ""
tolerations: []
schedulerName: ""
# extraResources defines quotas for containers other than mysql or xenon.
extraResources:
requests:
cpu: 10m
memory: 32Mi
persistence:
enabled: true
accessModes:
- ReadWriteOnce
#storageClass: ""
size: 20Gi
backupSecretName: sample-backup-secret
10 changes: 10 additions & 0 deletions docs/en-us/deploy_radondb_mysql8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Deploy
use sample `config/samples/mysql_v1alpha1_mysqlcluster_mysql8.yaml` , modify the `spec.podPolicy.sidecarImage` to MySQL8 version sidecar image.
install step
[deploy reference](deploy_radondb-mysql_operator_on_kubesphere.md)
# How to build sidecar images?
After you had installed docker , use command:
```
make mysql8-sidecar
```
it will build mysql8 sidecar image.Then `docker push xxx` to push to docker hub.
3 changes: 2 additions & 1 deletion mysqlcluster/container/init_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func (c *initMysql) getImage() string {

// getCommand get the container command.
func (c *initMysql) getCommand() []string {
return nil
// Because initialize mysql contain error, so do it in commands.
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 "}
}

// getEnvVars get the container env.
Expand Down
2 changes: 1 addition & 1 deletion mysqlcluster/container/init_mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestGetInitMysqlImage(t *testing.T) {
}

func TestGetInitMysqlCommand(t *testing.T) {
assert.Nil(t, initMysqlCase.Command)
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 "})
}

func TestGetInitMysqlEnvVar(t *testing.T) {
Expand Down
22 changes: 16 additions & 6 deletions mysqlcluster/mysqlcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ func (c *MysqlCluster) Validate() error {
if utils.StringInArray(c.Spec.MysqlOpts.User, []string{"root", utils.ReplicationUser, utils.OperatorUser, utils.MetricsUser}) {
return fmt.Errorf("spec.mysqlOpts.user cannot be root|%s|%s|%s", utils.ReplicationUser, utils.OperatorUser, utils.MetricsUser)
}

// MySQL8 nerver support TokuDB
// https://www.percona.com/blog/2021/05/21/tokudb-support-changes-and-future-removal-from-percona-server-for-mysql-8-0/
if c.Spec.MysqlVersion == "8.0" && c.Spec.MysqlOpts.InitTokuDB {
log.Info("TokuDB is not supported in MySQL 8.0 any more, the value in Cluster.spec.mysqlOpts.initTokuDB should be set false")
return nil
}
// https://github.com/percona/percona-docker/blob/main/percona-server-5.7/ps-entry.sh#L159
// ERROR 1396 (HY000): Operation CREATE USER failed for 'root'@'127.0.0.1'.
if c.Spec.MysqlOpts.RootHost == "127.0.0.1" {
Expand All @@ -91,12 +96,17 @@ func (c *MysqlCluster) GetLabels() labels.Set {
if comp, ok := c.Annotations["app.kubernetes.io/component"]; ok {
component = comp
}

// version := ""
// if _, ok := c.Labels["app.kubernetes.io/version"]; !ok {
// version = c.GetMySQLVersion()
// }
labels := labels.Set{
"mysql.radondb.com/cluster": c.Name,
"app.kubernetes.io/name": "mysql",
"app.kubernetes.io/instance": instance,
"app.kubernetes.io/version": c.GetMySQLVersion(),
"mysql.radondb.com/cluster": c.Name,
"app.kubernetes.io/name": "mysql",
"app.kubernetes.io/instance": instance,
// Notice: if app.kubernetes.io/version changed, then statefulset update will failure, It is not need to do this.
// So delete this label.
//"app.kubernetes.io/version": version,
"app.kubernetes.io/component": component,
"app.kubernetes.io/managed-by": "mysql.radondb.com",
}
Expand Down
26 changes: 13 additions & 13 deletions mysqlcluster/mysqlcluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ func TestGetLabel(t *testing.T) {
&testMysqlCluster,
}
want := labels.Set{
"mysql.radondb.com/cluster": "sample",
"app.kubernetes.io/name": "mysql",
"app.kubernetes.io/instance": "instance",
"app.kubernetes.io/version": "5.7.34",
"mysql.radondb.com/cluster": "sample",
"app.kubernetes.io/name": "mysql",
"app.kubernetes.io/instance": "instance",
//"app.kubernetes.io/version": "5.7.34",
"app.kubernetes.io/component": "database",
"app.kubernetes.io/managed-by": "mysql.radondb.com",
}
Expand All @@ -91,10 +91,10 @@ func TestGetLabel(t *testing.T) {
&testMysqlCluster,
}
want := labels.Set{
"mysql.radondb.com/cluster": "sample",
"app.kubernetes.io/name": "mysql",
"app.kubernetes.io/instance": "sample",
"app.kubernetes.io/version": "5.7.34",
"mysql.radondb.com/cluster": "sample",
"app.kubernetes.io/name": "mysql",
"app.kubernetes.io/instance": "sample",
//"app.kubernetes.io/version": "5.7.34",
"app.kubernetes.io/component": "component",
"app.kubernetes.io/managed-by": "mysql.radondb.com",
}
Expand All @@ -110,10 +110,10 @@ func TestGetLabel(t *testing.T) {
&testMysqlCluster,
}
want := labels.Set{
"mysql.radondb.com/cluster": "sample",
"app.kubernetes.io/name": "mysql",
"app.kubernetes.io/instance": "sample",
"app.kubernetes.io/version": "5.7.34",
"mysql.radondb.com/cluster": "sample",
"app.kubernetes.io/name": "mysql",
"app.kubernetes.io/instance": "sample",
//"app.kubernetes.io/version": "5.7.34",
"app.kubernetes.io/component": "database",
"app.kubernetes.io/managed-by": "mysql.radondb.com",
"app.kubernetes.io/part-of": "part-of",
Expand All @@ -139,7 +139,7 @@ func TestGetMySQLVersion(t *testing.T) {
testCase := MysqlCluster{
&testMysqlCluster,
}
want := utils.InvalidMySQLVersion
want := "8.0.25"
assert.Equal(t, want, testCase.GetMySQLVersion())
}
// MySQLTagsToSemVer 5.7 -> 5.7.34
Expand Down
26 changes: 24 additions & 2 deletions mysqlcluster/syncer/config_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ func NewConfigMapSyncer(cli client.Client, c *mysqlcluster.MysqlCluster) syncer.
return fmt.Errorf("failed to create mysql configs: %s", err)
}

dataSpecial, err := buildMysqlSpecialConf(c)
if err != nil {
return fmt.Errorf("failed to create mysql special configs: %s", err)
}
cm.Data = map[string]string{
"my.cnf": data,
"my.cnf": data,
utils.SpecialConfig: dataSpecial,
}

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

c.EnsureMysqlConf()

if c.Spec.MysqlVersion == "8.0" {
delete(mysqlCommonConfigs, "query_cache_size")
delete(mysqlStaticConfigs, "query_cache_type")
}
addKVConfigsToSection(sec, mysqlSysConfigs, mysqlCommonConfigs, mysqlStaticConfigs, c.Spec.MysqlOpts.MysqlConf)

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

// Build the Special Cnf file.
func buildMysqlSpecialConf(c *mysqlcluster.MysqlCluster) (string, error) {
cfg := ini.Empty(ini.LoadOptions{IgnoreInlineComment: true})
sec := cfg.Section("mysqld")

addKVConfigsToSection(sec, specialConfigs)
data, err := writeConfigs(cfg)
if err != nil {
return "", err
}

return data, nil
}

// addKVConfigsToSection add a map[string]string to a ini.Section
func addKVConfigsToSection(s *ini.Section, extraMysqld ...map[string]string) {
for _, extra := range extraMysqld {
Expand Down
3 changes: 3 additions & 0 deletions mysqlcluster/syncer/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"time"

"github.com/go-test/deep"
"github.com/iancoleman/strcase"
"github.com/imdario/mergo"
"github.com/presslabs/controller-util/mergo/transformers"
Expand Down Expand Up @@ -271,6 +272,8 @@ func (s *StatefulSetSyncer) createOrUpdate(ctx context.Context) (controllerutil.
if equality.Semantic.DeepEqual(existing, s.sfs) {
return controllerutil.OperationResultNone, nil
}
log.Info("update statefulset", "name", s.Name, "diff", deep.Equal(existing, s.sfs))

// If changed, update statefulset.
if err := s.cli.Update(ctx, s.sfs); err != nil {
return controllerutil.OperationResultNone, err
Expand Down
Loading