Skip to content

Commit 053fc09

Browse files
wei-bo.chenAMecea
authored andcommitted
Refactor to utility function
1 parent 315887a commit 053fc09

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

pkg/internal/mysqlcluster/defaults.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package mysqlcluster
1919
import (
2020
"fmt"
2121
"math"
22-
"regexp"
2322

2423
core "k8s.io/api/core/v1"
2524
"k8s.io/apimachinery/pkg/api/resource"
@@ -106,7 +105,7 @@ func (cluster *MysqlCluster) SetDefaults(opt *options.Options) {
106105
maxBinlogSize = min(binlogSpaceLimit/3, 1*gb)
107106
}
108107

109-
if matched, err := regexp.MatchString("([a-z.]+/)*percona(:.+)?", cluster.Spec.Image); err != nil && matched {
108+
if cluster.IsPerconaImage() {
110109
// binlog-space-limit = totalSpace / 2
111110
setConfigIfNotSet(cluster.Spec.MysqlConf, "binlog-space-limit", humanizeSize(binlogSpaceLimit))
112111
}

pkg/internal/mysqlcluster/mysqlcluster.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,16 @@ func (c *MysqlCluster) UpdateSpec() {
220220
}
221221
}
222222

223+
// IsPerconaImage checks the MySQL image is percona or not
224+
func (c *MysqlCluster) IsPerconaImage() bool {
225+
return strings.Contains(c.GetMysqlImage(), "percona")
226+
}
227+
223228
// ShouldHaveInitContainerForMysql checks the MySQL version and returns true or false if the docker image supports or not init only
224229
func (c *MysqlCluster) ShouldHaveInitContainerForMysql() bool {
225230
expectedRange := semver.MustParseRange(">=5.7.26 <8.0.0 || >=8.0.15")
226231

227-
return strings.Contains(c.GetMysqlImage(), "percona") && expectedRange(c.GetMySQLSemVer())
232+
return c.IsPerconaImage() && expectedRange(c.GetMySQLSemVer())
228233
}
229234

230235
// String returns the cluster name and namespace

0 commit comments

Comments
 (0)