Skip to content

Commit c188eff

Browse files
committed
galera: support mariabackup SST method
Make the SST method configurable in the galera custom resource, and allow both rsync and mariabackup methods. Mariabackup requires a database user's credentials to operate, so reuse the root db user for the time being. Jira: OSPRH-10195
1 parent 3d6a890 commit c188eff

File tree

11 files changed

+95
-12
lines changed

11 files changed

+95
-12
lines changed

api/bases/mariadb.openstack.org_galeras.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ spec:
7878
secret:
7979
description: Name of the secret to look for password keys
8080
type: string
81+
sst:
82+
default: rsync
83+
description: Snapshot State Transfer method to use for full node synchronization
84+
enum:
85+
- rsync
86+
- mariabackup
87+
type: string
8188
storageClass:
8289
description: Storage class to host the mariadb databases
8390
type: string

api/v1beta1/galera_types.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,21 @@ type GaleraSpecCore struct {
8080
// +kubebuilder:validation:Optional
8181
// Log Galera pod's output to disk
8282
LogToDisk bool `json:"logToDisk"`
83+
// +kubebuilder:validation:Optional
84+
// +kubebuilder:default=rsync
85+
// +kubebuilder:validation:Enum=rsync;mariabackup
86+
// Snapshot State Transfer method to use for full node synchronization
87+
SST GaleraSST `json:"sst"`
8388
}
8489

90+
// Supported SST type
91+
type GaleraSST string
92+
93+
const (
94+
RSync GaleraSST = "rsync"
95+
MariaBackup GaleraSST = "mariabackup"
96+
)
97+
8598
// GaleraAttributes holds startup information for a Galera host
8699
type GaleraAttributes struct {
87100
// Last recorded replication sequence number in the DB

config/crd/bases/mariadb.openstack.org_galeras.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ spec:
7878
secret:
7979
description: Name of the secret to look for password keys
8080
type: string
81+
sst:
82+
default: rsync
83+
description: Snapshot State Transfer method to use for full node synchronization
84+
enum:
85+
- rsync
86+
- mariabackup
87+
type: string
8188
storageClass:
8289
description: Storage class to host the mariadb databases
8390
type: string
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: mariadb.openstack.org/v1beta1
2+
kind: Galera
3+
metadata:
4+
name: openstack
5+
spec:
6+
secret: osp-secret
7+
storageClass: local-storage
8+
storageRequest: 500M
9+
replicas: 3
10+
sst: mariabackup

pkg/mariadb/volumes.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ func getGaleraVolumes(g *mariadbv1.Galera) []corev1.Volume {
3737
}
3838
}
3939

40+
if g.Spec.SST == mariadbv1.MariaBackup {
41+
configTemplates = append(configTemplates, corev1.KeyToPath{
42+
Key: "galera_sst_mariabackup.cnf.in",
43+
Path: "galera_sst_mariabackup.cnf.in",
44+
})
45+
}
46+
4047
volumes := []corev1.Volume{
4148
{
4249
Name: "secrets",

templates/galera/bin/mysql_bootstrap.sh

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/bin/bash
2-
set +eux
2+
set +eu
3+
4+
init_error() {
5+
echo "Container initialization failed at $(caller)." >&2
6+
}
7+
trap init_error ERR
38

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

3137
PODNAME=$(hostname -f | cut -d. -f1,2)
3238
PODIPV4=$(grep "${PODNAME}" /etc/hosts | grep -v ':' | cut -d$'\t' -f1)
3339
PODIPV6=$(grep "${PODNAME}" /etc/hosts | grep ':' | cut -d$'\t' -f1)
40+
if [[ "" = "${PODIPV6}" ]]; then
41+
PODIP="${PODIPV4}"
42+
IPSTACK="IPV4"
43+
else
44+
PODIP="[::]"
45+
IPSTACK="IPV6"
46+
fi
47+
export PODNAME PODIP
48+
49+
# mariabackup: default credentials if no configuration was provided
50+
: ${MARIABACKUP_USER=root}
51+
: ${MARIABACKUP_PASSWORD=$DB_ROOT_PASSWORD}
52+
export MARIABACKUP_USER MARIABACKUP_PASSWORD
3453

3554
cd /var/lib/config-data/default
3655
for cfg in *.cnf.in; do
3756
if [ -s "${cfg}" ]; then
38-
39-
if [[ "" = "${PODIPV6}" ]]; then
40-
PODIP="${PODIPV4}"
41-
IPSTACK="IPV4"
42-
else
43-
PODIP="[::]"
44-
IPSTACK="IPV6"
45-
fi
46-
4757
echo "Generating config file from template ${cfg}, will use ${IPSTACK} listen address of ${PODIP}"
48-
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}"
58+
# replace all occurrences of "{ xxx }" with their value from environment
59+
awk '{
60+
patsplit($0,markers,/{ (PODNAME|PODIP|SSL_CIPHER|MARIABACKUP_USER|MARIABACKUP_PASSWORD) }/);
61+
for(i in markers){ m=markers[i]; gsub(/\W/,"",m); gsub(markers[i], ENVIRON[m])};
62+
print $0
63+
}' "/var/lib/config-data/default/${cfg}" > "/var/lib/config-data/generated/${cfg%.in}"
4964
fi
5065
done

templates/galera/bin/mysql_probe.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -u
33

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

88
PROBE_USER=root

templates/galera/config/config.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
"perm": "0644",
2929
"optional": true
3030
},
31+
{
32+
"source": "/var/lib/config-data/generated/galera_sst_mariabackup.cnf",
33+
"dest": "/etc/my.cnf.d/galera_mariabackup.cnf",
34+
"owner": "root",
35+
"perm": "0644",
36+
"optional": true
37+
},
3138
{
3239
"source": "/var/lib/operator-scripts",
3340
"dest": "/usr/local/bin",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[mysqld]
2+
wsrep_sst_method = mariabackup
3+
wsrep_sst_auth = root:{ MARIABACKUP_PASSWORD }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"command": "/usr/bin/true",
3+
"permissions": [
4+
{
5+
"path": "/var/lib/mysql",
6+
"owner": "mysql:mysql",
7+
"recurse": "true"
8+
}
9+
]
10+
}

0 commit comments

Comments
 (0)