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

Commit 3e15e5a

Browse files
committed
Implement minimum MySQL version validation
Resolves: #163
1 parent 20ff3b1 commit 3e15e5a

File tree

16 files changed

+1137
-25
lines changed

16 files changed

+1137
-25
lines changed

Gopkg.lock

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ required = [
7373
branch = "master"
7474
name = "github.com/heptiolabs/healthcheck"
7575

76+
[[constraint]]
77+
name = "github.com/coreos/go-semver"
78+
revision = "e214231b295a8ea9479f11b70b35d5acf3556d9b"
79+
7680
# gengo needs to be manually pinned to the version listed in code-generators
7781
# Gopkg.toml, because the k8s project does not produce Gopkg.toml files & dep
7882
# does not parse the Godeps.json file to determine revisions to use.

pkg/apis/mysql/v1alpha1/cluster_test.go

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,51 @@
1515
package v1alpha1
1616

1717
import (
18+
"fmt"
1819
"testing"
1920

2021
"github.com/stretchr/testify/assert"
2122
corev1 "k8s.io/api/core/v1"
2223
"k8s.io/apimachinery/pkg/util/validation/field"
2324
)
2425

25-
func TestValidVersion(t *testing.T) {
26-
for _, version := range validVersions {
27-
errList := validateVersion(version, field.NewPath("spec", "version"))
28-
if len(errList) > 0 {
29-
t.Fail()
30-
}
26+
func TestValidateVersion(t *testing.T) {
27+
fldPath := field.NewPath("spec", "version")
28+
testCases := map[string]struct {
29+
name string
30+
version string
31+
expected field.ErrorList
32+
}{
33+
"minimum_version_valid": {
34+
version: MinimumMySQLVersion,
35+
expected: field.ErrorList{},
36+
},
37+
"next_patch_version_valid": {
38+
version: "8.0.12",
39+
expected: field.ErrorList{},
40+
},
41+
"next_minor_version_valid": {
42+
version: "8.1.0",
43+
expected: field.ErrorList{},
44+
},
45+
"previous_version_invalid": {
46+
version: "8.0.4",
47+
expected: field.ErrorList{
48+
field.Invalid(fldPath, "8.0.4", fmt.Sprintf("minimum supported MySQL version is %s", MinimumMySQLVersion)),
49+
},
50+
},
51+
"5.7_version_invalid": {
52+
version: "5.7.20-1.1.2",
53+
expected: field.ErrorList{
54+
field.Invalid(fldPath, "5.7.20-1.1.2", fmt.Sprintf("minimum supported MySQL version is %s", MinimumMySQLVersion)),
55+
},
56+
},
3157
}
32-
}
33-
34-
func TestInvalidVersion(t *testing.T) {
35-
err := validateVersion("1.2.3", field.NewPath("spec", "version"))
36-
if err == nil {
37-
t.Fail()
58+
for name, tc := range testCases {
59+
t.Run(name, func(t *testing.T) {
60+
errs := validateVersion(tc.version, fldPath)
61+
assert.EqualValues(t, errs, tc.expected)
62+
})
3863
}
3964
}
4065

pkg/apis/mysql/v1alpha1/helpers.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,6 @@ const (
4040
ClusterNameMaxLen = 28
4141
)
4242

43-
// TODO (owain) we need to remove this because it's not reasonable for us to maintain a list
44-
// of all the potential MySQL versions that can be used and in reality, it shouldn't matter
45-
// too much. The burden of this is not worth the benfit to a user
46-
var validVersions = []string{
47-
defaultVersion,
48-
}
49-
5043
// setOperatorVersionLabel sets the specified operator version label on the label map.
5144
func setOperatorVersionLabel(labelMap map[string]string, label string) {
5245
labelMap[constants.MySQLOperatorVersionLabel] = label

pkg/apis/mysql/v1alpha1/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import (
1919
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2020
)
2121

22+
// MinimumMySQLVersion is the minimum version of MySQL server supported by the
23+
// MySQL Operator.
24+
const MinimumMySQLVersion = "8.0.11"
25+
2226
// ClusterSpec defines the attributes a user can specify when creating a cluster
2327
type ClusterSpec struct {
2428
// Version defines the MySQL Docker image version.

pkg/apis/mysql/v1alpha1/validation.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ import (
1818
"fmt"
1919
"strconv"
2020

21-
"github.com/oracle/mysql-operator/pkg/constants"
21+
"github.com/coreos/go-semver/semver"
22+
2223
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324
"k8s.io/apimachinery/pkg/util/validation/field"
25+
26+
"github.com/oracle/mysql-operator/pkg/constants"
2427
)
2528

2629
func validateCluster(c *Cluster) field.ErrorList {
@@ -67,12 +70,23 @@ func validateClusterStatus(s ClusterStatus, fldPath *field.Path) field.ErrorList
6770

6871
func validateVersion(version string, fldPath *field.Path) field.ErrorList {
6972
allErrs := field.ErrorList{}
70-
for _, validVersion := range validVersions {
71-
if version == validVersion {
72-
return allErrs
73+
min, err := semver.NewVersion(MinimumMySQLVersion)
74+
if err != nil {
75+
allErrs = append(allErrs, field.InternalError(fldPath, fmt.Errorf("unable to parse minimum MySQL version: %v", err)))
76+
}
77+
78+
given, err := semver.NewVersion(version)
79+
if err != nil {
80+
allErrs = append(allErrs, field.Invalid(fldPath, version, fmt.Sprintf("unable to parse MySQL version: %v", err)))
81+
}
82+
83+
if len(allErrs) == 0 {
84+
if given.Compare(*min) == -1 {
85+
allErrs = append(allErrs, field.Invalid(fldPath, version, fmt.Sprintf("minimum supported MySQL version is %s", MinimumMySQLVersion)))
7386
}
7487
}
75-
return append(allErrs, field.Invalid(fldPath, version, "invalid version specified"))
88+
89+
return allErrs
7690
}
7791

7892
func validateBaseServerID(baseServerID uint32, fldPath *field.Path) field.ErrorList {

vendor/github.com/coreos/go-semver/.travis.yml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/coreos/go-semver/DCO

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)