From d2597301f1b6873dbf5a0d04b58eae632de3c7dc Mon Sep 17 00:00:00 2001 From: Matt Lord Date: Tue, 12 Mar 2024 11:37:58 -0400 Subject: [PATCH] Ensure that binary logs for PITR are restored to a shared location Signed-off-by: Matt Lord --- pkg/operator/vttablet/mysqlctld.go | 3 ++- pkg/operator/vttablet/pod.go | 5 +++++ pkg/operator/vttablet/vtbackup_pod.go | 9 +++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pkg/operator/vttablet/mysqlctld.go b/pkg/operator/vttablet/mysqlctld.go index 442aaf6d..4860aa20 100644 --- a/pkg/operator/vttablet/mysqlctld.go +++ b/pkg/operator/vttablet/mysqlctld.go @@ -29,6 +29,7 @@ const ( vtRootInitScript = `set -ex mkdir -p /mnt/vt/bin cp --no-clobber /vt/bin/mysqlctld /mnt/vt/bin/ +cp --no-clobber $(command -v mysqlbinlog) /mnt/vt/bin/ || true mkdir -p /mnt/vt/config if [[ -d /vt/config/mycnf ]]; then cp --no-clobber -R /vt/config/mycnf /mnt/vt/config/ @@ -68,7 +69,7 @@ func init() { securityContext := &corev1.SecurityContext{} if planetscalev2.DefaultVitessRunAsUser >= 0 { - securityContext.RunAsUser = pointer.Int64Ptr(planetscalev2.DefaultVitessRunAsUser) + securityContext.RunAsUser = pointer.Int64(planetscalev2.DefaultVitessRunAsUser) } // Use an init container to copy only the files we need from the Vitess image. diff --git a/pkg/operator/vttablet/pod.go b/pkg/operator/vttablet/pod.go index 9dcc25f1..37b5f555 100644 --- a/pkg/operator/vttablet/pod.go +++ b/pkg/operator/vttablet/pod.go @@ -168,6 +168,11 @@ func UpdatePod(obj *corev1.Pod, spec *Spec) { var mysqldExporterContainer *corev1.Container mysqlctldAllFlags := mysqlctldFlags.Get(spec) + // Ensure that binary logs are restored to/from a location that all containers + // in the pod can access if no location was explicitly provided. + if _, ok := mysqlctldAllFlags["builtinbackup-incremental-restore-path"]; !ok { + mysqlctldAllFlags["builtinbackup-incremental-restore-path"] = vtDataRootPath + } mysql.UpdateMySQLServerVersion(mysqlctldAllFlags, spec.Images.Mysqld.Image()) if spec.Mysqld != nil { diff --git a/pkg/operator/vttablet/vtbackup_pod.go b/pkg/operator/vttablet/vtbackup_pod.go index 5823cdb1..1f5a5ec9 100644 --- a/pkg/operator/vttablet/vtbackup_pod.go +++ b/pkg/operator/vttablet/vtbackup_pod.go @@ -122,11 +122,11 @@ func NewBackupPod(key client.ObjectKey, backupSpec *BackupSpec, mysqldImage stri podSecurityContext := &corev1.PodSecurityContext{} if planetscalev2.DefaultVitessFSGroup >= 0 { - podSecurityContext.FSGroup = pointer.Int64Ptr(planetscalev2.DefaultVitessFSGroup) + podSecurityContext.FSGroup = pointer.Int64(planetscalev2.DefaultVitessFSGroup) } securityContext := &corev1.SecurityContext{} if planetscalev2.DefaultVitessRunAsUser >= 0 { - securityContext.RunAsUser = pointer.Int64Ptr(planetscalev2.DefaultVitessRunAsUser) + securityContext.RunAsUser = pointer.Int64(planetscalev2.DefaultVitessRunAsUser) } var containerResources corev1.ResourceRequirements @@ -134,6 +134,11 @@ func NewBackupPod(key client.ObjectKey, backupSpec *BackupSpec, mysqldImage stri update.ResourceRequirements(&containerResources, &tabletSpec.Mysqld.Resources) vtbackupAllFlags := vtbackupFlags.Get(backupSpec) + // Ensure that binary logs are restored to/from a location that all containers + // in the pod can access if no location was explicitly provided. + if _, ok := vtbackupAllFlags["builtinbackup-incremental-restore-path"]; !ok { + vtbackupAllFlags["builtinbackup-incremental-restore-path"] = vtDataRootPath + } mysql.UpdateMySQLServerVersion(vtbackupAllFlags, mysqldImage) pod := &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{