Skip to content
This repository was archived by the owner on May 28, 2021. It is now read-only.

Commit aa5924e

Browse files
committed
Handle MySQL version < 8.0.12
Signed-off-by: Alan Tang <alantang888@gmail.com>
1 parent 293bad9 commit aa5924e

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

pkg/resources/statefulsets/statefulset.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import (
3333
operatoropts "github.com/oracle/mysql-operator/pkg/options/operator"
3434
"github.com/oracle/mysql-operator/pkg/resources/secrets"
3535
"github.com/oracle/mysql-operator/pkg/version"
36+
37+
goverion "github.com/hashicorp/go-version"
3638
)
3739

3840
const (
@@ -48,6 +50,8 @@ const (
4850
mySQLSSLVolumeName = "mysqlsslvolume"
4951

5052
replicationGroupPort = 13306
53+
54+
minMysqlVersionWithGroupExitStateArgs = "8.0.12"
5155
)
5256

5357
func volumeMounts(cluster *v1alpha1.Cluster) []v1.VolumeMount {
@@ -155,6 +159,24 @@ func getReplicationGroupSeeds(name string, members int) string {
155159
return strings.Join(seeds, ",")
156160
}
157161

162+
func checkSupportGroupExitStateArgs(deployingVersion string) bool {
163+
ver, err := goverion.NewVersion(deployingVersion)
164+
if err != nil {
165+
return false
166+
}
167+
168+
minVer, err := goverion.NewVersion(minMysqlVersionWithGroupExitStateArgs)
169+
if err != nil {
170+
return false
171+
}
172+
173+
if ver.GreaterThan(minVer) || ver.Equal(minVer) {
174+
return true
175+
}
176+
177+
return false
178+
}
179+
158180
// Builds the MySQL operator container for a cluster.
159181
// The 'mysqlImage' parameter is the image name of the mysql server to use with
160182
// no version information.. e.g. 'mysql/mysql-server'
@@ -172,7 +194,6 @@ func mysqlServerContainer(cluster *v1alpha1.Cluster, mysqlServerImage string, ro
172194
"--master-info-repository=TABLE",
173195
"--relay-log-info-repository=TABLE",
174196
"--transaction-write-set-extraction=XXHASH64",
175-
"--group-replication-exit-state-action=READ_ONLY",
176197
fmt.Sprintf("--relay-log=%s-${index}-relay-bin", cluster.Name),
177198
fmt.Sprintf("--report-host=\"%[1]s-${index}.%[1]s\"", cluster.Name),
178199
"--log-error-verbosity=3",
@@ -185,6 +206,10 @@ func mysqlServerContainer(cluster *v1alpha1.Cluster, mysqlServerImage string, ro
185206
"--ssl-key=/etc/ssl/mysql/tls.key")
186207
}
187208

209+
if checkSupportGroupExitStateArgs(cluster.Spec.Version) {
210+
args = append(args, "--group-replication-exit-state-action=READ_ONLY")
211+
}
212+
188213
entryPointArgs := strings.Join(args, " ")
189214

190215
cmd := fmt.Sprintf(`

pkg/resources/statefulsets/statefulset_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,37 @@ func TestClusterDefaultOverride(t *testing.T) {
323323

324324
assert.Equal(t, "OverrideDefaultImage:"+v1alpha1.DefaultVersion, si)
325325
}
326+
327+
func TestClusterSetGroupExitStateArgs(t *testing.T) {
328+
cluster := &v1alpha1.Cluster{}
329+
cluster.EnsureDefaults()
330+
cluster.Spec.Version = "8.0.12"
331+
332+
statefulSet := NewForCluster(cluster, mockOperatorConfig().Images, "mycluster")
333+
334+
cmd := statefulSet.Spec.Template.Spec.Containers[0].Command[2]
335+
336+
assert.Contains(t, cmd, "--group-replication-exit-state-action=READ_ONLY")
337+
338+
cluster2 := &v1alpha1.Cluster{}
339+
cluster2.EnsureDefaults()
340+
cluster2.Spec.Version = "8.0.13"
341+
342+
statefulSet2 := NewForCluster(cluster2, mockOperatorConfig().Images, "mycluster")
343+
344+
cmd2 := statefulSet2.Spec.Template.Spec.Containers[0].Command[2]
345+
346+
assert.Contains(t, cmd2, "--group-replication-exit-state-action=READ_ONLY")
347+
}
348+
349+
func TestClusterNotSetGroupExitStateArgs(t *testing.T) {
350+
cluster := &v1alpha1.Cluster{}
351+
cluster.EnsureDefaults()
352+
cluster.Spec.Version = "8.0.11"
353+
354+
statefulSet := NewForCluster(cluster, mockOperatorConfig().Images, "mycluster")
355+
356+
cmd := statefulSet.Spec.Template.Spec.Containers[0].Command[2]
357+
358+
assert.NotContains(t, cmd, "--group-replication-exit-state-action=READ_ONLY")
359+
}

0 commit comments

Comments
 (0)