Skip to content

Commit

Permalink
add mysql_server_version flag to vttablet
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <[email protected]>
  • Loading branch information
frouioui committed Jan 18, 2024
1 parent f1d094f commit 6a7482f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
11 changes: 10 additions & 1 deletion pkg/operator/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 1 addition & 9 deletions pkg/operator/vtgate/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions pkg/operator/vttablet/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6a7482f

Please sign in to comment.