Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ endif
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

VERSION ?= 26.6.0-bandwidth.5
VERSION ?= 26.6.0-bandwidth.6

# mariadb-operator
IMG_NAME ?= ghcr.io/mariadb-operator/mariadb-operator
Expand Down
2 changes: 1 addition & 1 deletion docs/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</tr>
<tr>
<td>MariaDB Operator</td>
<td><code>ghcr.io/mariadb-operator/mariadb-operator:26.6.0-bandwidth.5</code></td>
<td><code>ghcr.io/mariadb-operator/mariadb-operator:26.6.0-bandwidth.6</code></td>
<td><code>amd64</code> <code>arm64</code></td>
</tr>
</tbody>
Expand Down
4 changes: 2 additions & 2 deletions examples/manifests/mariadb_replication.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ spec:
# syncBinlog: 1
# Init container that cooperates with mariadb-operator.
# initContainer:
# image: ghcr.io/mariadb-operator/mariadb-operator:26.6.0-bandwidth.5
# image: ghcr.io/mariadb-operator/mariadb-operator:26.6.0-bandwidth.6
# Agent sidecar that cooperates with mariadb-operator.
# agent:
# image: ghcr.io/mariadb-operator/mariadb-operator:26.6.0-bandwidth.5
# image: ghcr.io/mariadb-operator/mariadb-operator:26.6.0-bandwidth.6

service:
type: LoadBalancer
Expand Down
21 changes: 20 additions & 1 deletion internal/controller/mariadb_controller_external_repl_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,26 @@ func getBinlogExpireLogsDuration(emdb *mariadbv1alpha1.ExternalMariaDB, ctx cont
var binlogExpireLogsSecondsStr string
var binlogExpireLogsSeconds int

if semver.Compare("v"+emdb.Status.Version, "v10.6.1") >= 0 {
isRDS := false

// Check if it is an RDS instance
if user_exist, err := external_client.UserExists(ctx, "rdsadmin", "localhost"); err != nil && user_exist {
if table_exists, err := external_client.TableExists(ctx, "mysql", "rds_configuration"); err != nil && table_exists {
logger.Info("RDS config found")
isRDS = true
}
logger.Info("AWS user detected")
}

if isRDS {
logger.Info("Using 'binlog retention hours' in mysql.rds_configuration", "version", emdb.Status.Version)
binlogExpireLogsHourStr, err := external_client.RDSConfiguration(ctx, "binlog retention hours")
if err != nil {
return time.Duration(0), fmt.Errorf("unable to get 'binlog retention hours' from RDS instance: %v", err)
}
binlogExpireLogsHour, _ := strconv.Atoi(binlogExpireLogsHourStr)
binlogExpireLogsSeconds = binlogExpireLogsHour * 3600
} else if semver.Compare("v"+emdb.Status.Version, "v10.6.1") >= 0 {
logger.Info("Using binlog_expire_logs_seconds", "version", emdb.Status.Version)
binlogExpireLogsSecondsStr, err = external_client.SystemVariable(ctx, "binlog_expire_logs_seconds")
if err != nil {
Expand Down
27 changes: 27 additions & 0 deletions pkg/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,22 @@ func (c *Client) UserExists(ctx context.Context, username, host string) (bool, e
return count > 0, nil
}

func (c *Client) TableExists(ctx context.Context, schema string, table string) (bool, error) {

row := c.db.QueryRowContext(ctx, `
SELECT COUNT(*) AS table_exists
FROM information_schema.tables
WHERE
table_schema = ?
AND table_name = ?;
`, schema, table)
var count int
if err := row.Scan(&count); err != nil {
return false, err
}
return count > 0, nil
}

func (c *Client) GrantExists(ctx context.Context,
privileges []string,
database string,
Expand Down Expand Up @@ -778,6 +794,17 @@ func (c *Client) SystemVariable(ctx context.Context, variable string) (string, e
return val, nil
}

func (c *Client) RDSConfiguration(ctx context.Context, config string) (string, error) {
sql := fmt.Sprintf("SELECT value FROM mysql.rds_configuration WHERE name = '%s';", config)
row := c.db.QueryRowContext(ctx, sql)

var val string
if err := row.Scan(&val); err != nil {
return "", nil
}
return val, nil
}

func (c *Client) IsSystemVariableEnabled(ctx context.Context, variable string) (bool, error) {
val, err := c.SystemVariable(ctx, variable)
if err != nil {
Expand Down
Loading