diff --git a/pkg/operator/mysql/mysql.go b/pkg/operator/mysql/mysql.go index 1928d5ba..4a4ca1f9 100644 --- a/pkg/operator/mysql/mysql.go +++ b/pkg/operator/mysql/mysql.go @@ -23,12 +23,21 @@ import ( "strconv" "strings" + "planetscale.dev/vitess-operator/pkg/operator/vitess" "vitess.io/vitess/go/vt/sqlparser" ) var imageVersionRegExp = regexp.MustCompile(`^(\d+)\.(\d+)\.(\d+)`) -func DockerImageGetVersionToString(currentVersionImage string) (string, error) { +func UpdateMySQLServerVersion(flags vitess.Flags, mysqldImage string) { + value, err := dockerImageGetVersionToString(mysqldImage) + if err != nil { + return + } + flags["mysql_server_version"] = value +} + +func dockerImageGetVersionToString(currentVersionImage string) (string, error) { currentVersionSlice := strings.SplitN(currentVersionImage, ":", 2) if len(currentVersionSlice) != 2 { return "", fmt.Errorf("could not parse the image name and image label, got: %s, but expected xx:xx", currentVersionImage) diff --git a/pkg/operator/vtgate/deployment.go b/pkg/operator/vtgate/deployment.go index 8bdf1ae9..a2882881 100644 --- a/pkg/operator/vtgate/deployment.go +++ b/pkg/operator/vtgate/deployment.go @@ -224,7 +224,7 @@ func UpdateDeployment(obj *appsv1.Deployment, spec *Spec, mysqldImage string) { flags := spec.baseFlags() // Update the Pod template, container, and flags for various optional things. - updateMySQLServerVersion(flags, mysqldImage) + mysql.UpdateMySQLServerVersion(flags, mysqldImage) updateAuth(spec, flags, vtgateContainer, &obj.Spec.Template.Spec) updateTransport(spec, flags, vtgateContainer, &obj.Spec.Template.Spec) update.Volumes(&obj.Spec.Template.Spec.Volumes, spec.ExtraVolumes) @@ -288,14 +288,6 @@ func (spec *Spec) baseFlags() vitess.Flags { } } -func updateMySQLServerVersion(flags vitess.Flags, mysqldImage string) { - value, err := mysql.DockerImageGetVersionToString(mysqldImage) - if err != nil { - return - } - flags["mysql_server_version"] = value -} - func updateAuth(spec *Spec, flags vitess.Flags, container *corev1.Container, podSpec *corev1.PodSpec) { if spec.Authentication.Static != nil && spec.Authentication.Static.Secret != nil { staticAuthFile := secrets.Mount(spec.Authentication.Static.Secret, staticAuthDirName) diff --git a/pkg/operator/vttablet/pod.go b/pkg/operator/vttablet/pod.go index 392ea282..5e8bdfbe 100644 --- a/pkg/operator/vttablet/pod.go +++ b/pkg/operator/vttablet/pod.go @@ -25,6 +25,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/utils/pointer" + "planetscale.dev/vitess-operator/pkg/operator/mysql" "sigs.k8s.io/controller-runtime/pkg/client" topodatapb "vitess.io/vitess/go/vt/proto/topodata" "vitess.io/vitess/go/vt/topo/topoproto" @@ -86,6 +87,7 @@ func UpdatePod(obj *corev1.Pod, spec *Spec) { key = strings.TrimLeft(key, "-") vttabletAllFlags[key] = value } + mysql.UpdateMySQLServerVersion(vttabletAllFlags, spec.Images.Mysqld.Image()) // Compute all operator-generated env vars first. env := tabletEnvVars.Get(spec)