Skip to content

Commit

Permalink
Allow user to specify versions map for mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
AMecea committed Jul 8, 2019
1 parent 90bb86c commit ffb0a22
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 5 additions & 2 deletions pkg/apis/mysql/v1alpha1/mysqlcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ type MysqlClusterSpec struct {
// +kubebuilder:validation:MaxLength=63
SecretName string `json:"secretName"`

// Represents the percona image tag.
// Represents the MySQL version that will be run. The available version can be found here:
// https://github.com/presslabs/mysql-operator/blob/0fd4641ce4f756a0aab9d31c8b1f1c44ee10fcb2/pkg/util/constants/constants.go#L87
// This field should be set even if the Image is set to let the operator know which mysql version is running.
// Based on this version the operator can take decisions which features can be used.
// Defaults to 5.7
// +optional
MysqlVersion string `json:"mysqlVersion,omitempty"`

// To specify the image that will be used for mysql server container.
// If this is specified then the mysqlVersion is ignored.
// If this is specified then the mysqlVersion is used as source for MySQL server version.
// +optional
Image string `json:"image,omitempty"`

Expand Down
9 changes: 8 additions & 1 deletion pkg/internal/mysqlcluster/mysqlcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package mysqlcluster

import (
"fmt"
"github.com/presslabs/mysql-operator/pkg/options"
"strings"

"github.com/blang/semver"
Expand Down Expand Up @@ -190,6 +191,12 @@ func (c *MysqlCluster) GetMysqlImage() string {
return c.Spec.Image
}

// check if the user set some overrides
opt := options.GetOptions()
if img, ok := opt.MySQLVersionImageOverride[c.GetMySQLSemVer().String()]; ok {
return img
}

if img, ok := constants.MysqlImageVersions[c.GetMySQLSemVer().String()]; ok {
return img
}
Expand All @@ -212,5 +219,5 @@ func (c *MysqlCluster) UpdateSpec() {
func (c *MysqlCluster) ShouldHaveInitContainerForMysql() bool {
expectedRange := semver.MustParseRange(">=5.7.26 <8.0.0 || >=8.0.15")

return strings.HasPrefix(c.GetMysqlImage(), "percona") && expectedRange(c.GetMySQLSemVer())
return strings.Contains(c.GetMysqlImage(), "percona") && expectedRange(c.GetMySQLSemVer())
}
9 changes: 8 additions & 1 deletion pkg/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ type Options struct {

// Namespace where to look after objects. This will limit the operator action range.
Namespace string

// MySQLVersionImageOverride define a map between MySQL version and image.
// This overrides the default versions and has priority.
MySQLVersionImageOverride map[string]string
}

type pullpolicy corev1.PullPolicy
Expand All @@ -89,7 +93,7 @@ func newPullPolicyValue(defaultValue corev1.PullPolicy, v *corev1.PullPolicy) *p
}

const (
defaultExporterImage = "prom/mysqld-exporter:latest"
defaultExporterImage = "prom/mysqld-exporter:v0.11.0"

defaultImagePullPolicy = corev1.PullIfNotPresent
defaultImagePullSecretName = ""
Expand Down Expand Up @@ -134,6 +138,9 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {

fs.StringVar(&o.Namespace, "namespace", defaultNamespace,
"The namespace to restrict the client to watch objects.")

fs.StringToStringVar(&o.MySQLVersionImageOverride, "mysql-versions-to-image", map[string]string{},
"A map to override default image for different mysql versions.")
}

var instance *Options
Expand Down

0 comments on commit ffb0a22

Please sign in to comment.