Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

galera: support mariabackup SST method #144

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
7 changes: 7 additions & 0 deletions api/bases/mariadb.openstack.org_galeras.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ spec:
secret:
description: Name of the secret to look for password keys
type: string
sst:
default: rsync
description: Snapshot State Transfer method to use for full node synchronization
enum:
- rsync
- mariabackup
type: string
storageClass:
description: Storage class to host the mariadb databases
type: string
Expand Down
13 changes: 13 additions & 0 deletions api/v1beta1/galera_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,21 @@ type GaleraSpecCore struct {
// +kubebuilder:validation:Optional
// Log Galera pod's output to disk
LogToDisk bool `json:"logToDisk"`
// +kubebuilder:validation:Optional
// +kubebuilder:default=rsync
// +kubebuilder:validation:Enum=rsync;mariabackup
// Snapshot State Transfer method to use for full node synchronization
SST GaleraSST `json:"sst"`
}

// Supported SST type
type GaleraSST string

const (
RSync GaleraSST = "rsync"
MariaBackup GaleraSST = "mariabackup"
)

// GaleraAttributes holds startup information for a Galera host
type GaleraAttributes struct {
// Last recorded replication sequence number in the DB
Expand Down
7 changes: 7 additions & 0 deletions config/crd/bases/mariadb.openstack.org_galeras.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ spec:
secret:
description: Name of the secret to look for password keys
type: string
sst:
default: rsync
description: Snapshot State Transfer method to use for full node synchronization
enum:
- rsync
- mariabackup
type: string
storageClass:
description: Storage class to host the mariadb databases
type: string
Expand Down
10 changes: 10 additions & 0 deletions config/samples/mariadb_v1beta1_galera_sst.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: mariadb.openstack.org/v1beta1
kind: Galera
metadata:
name: openstack
spec:
secret: osp-secret
storageClass: local-storage
storageRequest: 500M
replicas: 3
sst: mariabackup
7 changes: 7 additions & 0 deletions pkg/mariadb/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ func getGaleraVolumes(g *mariadbv1.Galera) []corev1.Volume {
}
}

if g.Spec.SST == mariadbv1.MariaBackup {
configTemplates = append(configTemplates, corev1.KeyToPath{
Key: "galera_sst_mariabackup.cnf.in",
Path: "galera_sst_mariabackup.cnf.in",
})
}

volumes := []corev1.Volume{
{
Name: "secrets",
Expand Down
37 changes: 26 additions & 11 deletions templates/galera/bin/mysql_bootstrap.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/bash
set +eux
set +eu

init_error() {
echo "Container initialization failed at $(caller)." >&2
}
trap init_error ERR

if [ -e /var/lib/mysql/mysql ]; then
echo -e "Database already exists. Reuse it."
Expand Down Expand Up @@ -27,24 +32,34 @@ if [ "$(sysctl -n crypto.fips_enabled)" == "1" ]; then
else
SSL_CIPHER='AES128-SHA256'
fi
export SSL_CIPHER

PODNAME=$(hostname -f | cut -d. -f1,2)
PODIPV4=$(grep "${PODNAME}" /etc/hosts | grep -v ':' | cut -d$'\t' -f1)
PODIPV6=$(grep "${PODNAME}" /etc/hosts | grep ':' | cut -d$'\t' -f1)
if [[ "" = "${PODIPV6}" ]]; then
PODIP="${PODIPV4}"
IPSTACK="IPV4"
else
PODIP="[::]"
IPSTACK="IPV6"
fi
export PODNAME PODIP

# mariabackup: default credentials if no configuration was provided
: ${MARIABACKUP_USER=root}
: ${MARIABACKUP_PASSWORD=$DB_ROOT_PASSWORD}
export MARIABACKUP_USER MARIABACKUP_PASSWORD

cd /var/lib/config-data/default
for cfg in *.cnf.in; do
if [ -s "${cfg}" ]; then

if [[ "" = "${PODIPV6}" ]]; then
PODIP="${PODIPV4}"
IPSTACK="IPV4"
else
PODIP="[::]"
IPSTACK="IPV6"
fi

echo "Generating config file from template ${cfg}, will use ${IPSTACK} listen address of ${PODIP}"
sed -e "s/{ PODNAME }/${PODNAME}/" -e "s/{ PODIP }/${PODIP}/" -e "s/{ SSL_CIPHER }/${SSL_CIPHER}/" "/var/lib/config-data/default/${cfg}" > "/var/lib/config-data/generated/${cfg%.in}"
# replace all occurrences of "{ xxx }" with their value from environment
awk '{
patsplit($0,markers,/{ (PODNAME|PODIP|SSL_CIPHER|MARIABACKUP_USER|MARIABACKUP_PASSWORD) }/);
for(i in markers){ m=markers[i]; gsub(/\W/,"",m); gsub(markers[i], ENVIRON[m])};
print $0
}' "/var/lib/config-data/default/${cfg}" > "/var/lib/config-data/generated/${cfg%.in}"
fi
done
2 changes: 1 addition & 1 deletion templates/galera/bin/mysql_probe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -u

# This secret is mounted by k8s and always up to date
read -s -u 3 3< /var/lib/secrets/dbpassword MYSQL_PWD || true
read -s -u 3 3< <(cat /var/lib/secrets/dbpassword; echo) MYSQL_PWD
export MYSQL_PWD

PROBE_USER=root
Expand Down
7 changes: 7 additions & 0 deletions templates/galera/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
"perm": "0644",
"optional": true
},
{
"source": "/var/lib/config-data/generated/galera_sst_mariabackup.cnf",
"dest": "/etc/my.cnf.d/galera_mariabackup.cnf",
"owner": "root",
"perm": "0644",
"optional": true
},
{
"source": "/var/lib/operator-scripts",
"dest": "/usr/local/bin",
Expand Down
3 changes: 3 additions & 0 deletions templates/galera/config/galera_sst_mariabackup.cnf.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[mysqld]
wsrep_sst_method = mariabackup
wsrep_sst_auth = root:{ MARIABACKUP_PASSWORD }
10 changes: 10 additions & 0 deletions templates/galera/config/init_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"command": "/usr/bin/true",
"permissions": [
{
"path": "/var/lib/mysql",
"owner": "mysql:mysql",
"recurse": "true"
}
]
}
4 changes: 4 additions & 0 deletions templates/galera/config/my.cnf.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[client]
user=root
host=localhost
password={ DB_ROOT_PASSWORD }
Loading