Skip to content

Commit

Permalink
Merge pull request radondb#444 from radondb/v2.2.0
Browse files Browse the repository at this point in the history
Support MySQL 8.0
  • Loading branch information
andyli029 authored Apr 11, 2022
2 parents 7f499c2 + c74345d commit 6d01f2f
Show file tree
Hide file tree
Showing 23 changed files with 435 additions and 199 deletions.
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
2 changes: 1 addition & 1 deletion api/v1alpha1/backup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type BackupSpec struct {

// To specify the image that will be used for sidecar container.
// +optional
// +kubebuilder:default:="radondb/mysql-sidecar:latest"
// +kubebuilder:default:="radondb/mysql57-sidecar:v2.2.0"
Image string `json:"image"`

// HostName represents the host for which to take backup
Expand Down
6 changes: 3 additions & 3 deletions api/v1alpha1/mysqlcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type MysqlClusterSpec struct {

// PodPolicy defines the policy to extra specification.
// +optional
// +kubebuilder:default:={imagePullPolicy: "IfNotPresent", extraResources: {requests: {cpu: "10m", memory: "32Mi"}}, sidecarImage: "radondb/mysql-sidecar:latest", busyboxImage: "busybox:1.32"}
// +kubebuilder:default:={imagePullPolicy: "IfNotPresent", extraResources: {requests: {cpu: "10m", memory: "32Mi"}}, sidecarImage: "radondb/mysql57-sidecar:v2.2.0", busyboxImage: "busybox:1.32"}
PodPolicy PodPolicy `json:"podPolicy,omitempty"`

// PVC extra specifiaction.
Expand Down Expand Up @@ -120,7 +120,7 @@ type MysqlOpts struct {

// InitTokuDB represents if install tokudb engine.
// +optional
// +kubebuilder:default:=true
// +kubebuilder:default:=false
InitTokuDB bool `json:"initTokuDB,omitempty"`

// A map[string]string that will be passed to my.cnf file.
Expand Down Expand Up @@ -199,7 +199,7 @@ type PodPolicy struct {

// To specify the image that will be used for sidecar container.
// +optional
// +kubebuilder:default:="radondb/mysql-sidecar:latest"
// +kubebuilder:default:="radondb/mysql57-sidecar:v2.2.0"
SidecarImage string `json:"sidecarImage,omitempty"`

// The busybox image.
Expand Down
2 changes: 1 addition & 1 deletion charts/mysql-operator/crds/mysql.radondb.com_backups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ spec:
description: HostName represents the host for which to take backup
type: string
image:
default: radondb/mysql-sidecar:latest
default: radondb/mysql57-sidecar:v2.2.0
description: To specify the image that will be used for sidecar container.
type: string
required:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ spec:
description: Name for new database to create.
type: string
initTokuDB:
default: true
default: false
description: InitTokuDB represents if install tokudb engine.
type: boolean
mysqlConf:
Expand Down Expand Up @@ -252,7 +252,7 @@ spec:
cpu: 10m
memory: 32Mi
imagePullPolicy: IfNotPresent
sidecarImage: radondb/mysql-sidecar:latest
sidecarImage: radondb/mysql57-sidecar:v2.2.0
description: PodPolicy defines the policy to extra specification.
properties:
affinity:
Expand Down Expand Up @@ -1182,7 +1182,7 @@ spec:
schedulerName:
type: string
sidecarImage:
default: radondb/mysql-sidecar:latest
default: radondb/mysql57-sidecar:v2.2.0
description: To specify the image that will be used for sidecar
container.
type: string
Expand Down
2 changes: 1 addition & 1 deletion charts/mysql-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tolerationSeconds: 30

manager:
image: radondb/mysql-operator
tag: latest
tag: v2.2.0
resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/mysql.radondb.com_backups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ spec:
description: HostName represents the host for which to take backup
type: string
image:
default: radondb/mysql-sidecar:latest
default: radondb/mysql57-sidecar:v2.2.0
description: To specify the image that will be used for sidecar container.
type: string
required:
Expand Down
6 changes: 3 additions & 3 deletions config/crd/bases/mysql.radondb.com_mysqlclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ spec:
description: Name for new database to create.
type: string
initTokuDB:
default: true
default: false
description: InitTokuDB represents if install tokudb engine.
type: boolean
mysqlConf:
Expand Down Expand Up @@ -252,7 +252,7 @@ spec:
cpu: 10m
memory: 32Mi
imagePullPolicy: IfNotPresent
sidecarImage: radondb/mysql-sidecar:latest
sidecarImage: radondb/mysql57-sidecar:v2.2.0
description: PodPolicy defines the policy to extra specification.
properties:
affinity:
Expand Down Expand Up @@ -1182,7 +1182,7 @@ spec:
schedulerName:
type: string
sidecarImage:
default: radondb/mysql-sidecar:latest
default: radondb/mysql57-sidecar:v2.2.0
description: To specify the image that will be used for sidecar
container.
type: string
Expand Down
2 changes: 1 addition & 1 deletion config/samples/mysql_v1alpha1_mysqlcluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ spec:

podPolicy:
imagePullPolicy: IfNotPresent
sidecarImage: radondb/mysql-sidecar:latest
sidecarImage: radondb/mysql57-sidecar:v2.2.0
busyboxImage: busybox:1.32

slowLogTail: false
Expand Down
89 changes: 89 additions & 0 deletions config/samples/mysql_v1alpha1_mysqlcluster_mysql8.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
apiVersion: mysql.radondb.com/v1alpha1
kind: MysqlCluster
metadata:
name: 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:

mysqlOpts:
rootPassword: "RadonDB@123"
rootHost: localhost
user: radondb_usr
password: RadonDB@123
database: radondb
## tokudb is not supported in mysql8.
# initTokuDB: false

# 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: IfNotPresent
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
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ spec:

podPolicy:
imagePullPolicy: IfNotPresent
sidecarImage: radondb/mysql-sidecar:latest
sidecarImage: radondb/mysql57-sidecar:v2.2.0
busyboxImage: busybox:1.32

slowLogTail: false
Expand Down
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
Loading

0 comments on commit 6d01f2f

Please sign in to comment.