Skip to content

Commit fe56ddd

Browse files
authored
Merge pull request #37 from Yolean/retire-not
... long live this repo
2 parents 7136118 + cdc1ff5 commit fe56ddd

26 files changed

+222
-252
lines changed

10conf-d.yml

Lines changed: 0 additions & 158 deletions
This file was deleted.

base-defaultconfig/datadir.cnf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[mysqld]
2+
datadir=/data/db

base-defaultconfig/galera.cnf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#
2+
# * Galera-related settings
3+
#
4+
# https://mariadb.com/kb/en/mariadb/galera-cluster-system-variables/
5+
#
6+
[galera]
7+
# Mandatory settings
8+
wsrep_on=ON
9+
wsrep_provider="/usr/lib/galera/libgalera_smm.so"
10+
#init-new-cluster#wsrep_new_cluster=TRUE
11+
#init-recover#wsrep_recover=TRUE
12+
binlog_format=ROW
13+
default_storage_engine=InnoDB
14+
innodb_autoinc_lock_mode=2
15+
#init-wsrep#wsrep_cluster_address="gcomm://mariadb"
16+
wsrep-sst-method=rsync
17+
18+
#
19+
# Allow server to accept connections on all interfaces.
20+
#
21+
bind-address=0.0.0.0
22+
#
23+
# Optional setting
24+
#wsrep_slave_threads=1
25+
#innodb_flush_log_at_trx_commit=0

base-defaultconfig/init.sh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/bash
2+
set -x
3+
[ "$(pwd)" != "/etc/mysql/conf.d" ] && cp * /etc/mysql/conf.d/
4+
5+
HOST_ID=${HOSTNAME##*-}
6+
7+
STATEFULSET_SERVICE=$(dnsdomainname -d)
8+
POD_FQDN=$(dnsdomainname -A)
9+
10+
echo "This is pod $HOST_ID ($POD_FQDN) for statefulset $STATEFULSET_SERVICE"
11+
12+
[ -z "$WSREP_CLUSTER_ADDRESS" ] && echo "Missing WSREP_CLUSTER_ADDRESS env" && exit 1
13+
sed -i "s|^#init-wsrep#.*|wsrep_cluster_address=$WSREP_CLUSTER_ADDRESS|" /etc/mysql/conf.d/galera.cnf
14+
15+
[ -z "$DATADIR" ] && exit "Missing DATADIR variable" && exit 1
16+
17+
SUGGEST_EXEC_COMMAND="kubectl --namespace=$POD_NAMESPACE exec -c init-config $POD_NAME --"
18+
19+
function wsrepNewCluster {
20+
sed -i 's|^#init-new-cluster#||' /etc/mysql/conf.d/galera.cnf
21+
}
22+
23+
function wsrepRecover {
24+
sed -i 's|^#init-recover#||' /etc/mysql/conf.d/galera.cnf
25+
}
26+
27+
function wsrepForceBootstrap {
28+
sed -i 's|safe_to_bootstrap: 0|safe_to_bootstrap: 1|' /data/db/grastate.dat
29+
}
30+
31+
[[ $STATEFULSET_SERVICE = mariadb.* ]] || echo "WARNING: unexpected service name $STATEFULSET_SERVICE, Peer detection below may fail falsely."
32+
33+
if [ $HOST_ID -eq 0 ]; then
34+
echo "This is the 1st statefulset pod. Checking if the statefulset is down ..."
35+
getent hosts mariadb-ready
36+
[ $? -eq 2 ] && {
37+
# https://github.com/docker-library/mariadb/commit/f76084f0f9dc13f29cce48c727440eb79b4e92fa#diff-b0fa4b30392406b32de6b8ffe36e290dR80
38+
if [ ! -d "$DATADIR/mysql" ]; then
39+
echo "No database in $DATADIR; configuring $POD_NAME for initial start"
40+
wsrepNewCluster
41+
else
42+
set +x
43+
echo "----- ACTION REQUIRED -----"
44+
echo "No peers found, but data exists. To start in wsrep_new_cluster mode, run:"
45+
echo " $SUGGEST_EXEC_COMMAND touch /tmp/confirm-new-cluster"
46+
echo "Or to start in recovery mode, to see replication state, run:"
47+
echo " $SUGGEST_EXEC_COMMAND touch /tmp/confirm-recover"
48+
echo "Or to force bootstrap on this node, potentially losing writes, run:"
49+
echo " $SUGGEST_EXEC_COMMAND touch /tmp/confirm-force-bootstrap"
50+
#echo " NOTE This bypasses the following warning from new cluster mode:"
51+
#echo " It may not be safe to bootstrap the cluster from this node. It was not the last one to leave the cluster and may not contain all the updates. To force cluster bootstrap with this node, edit the grastate.dat file manually and set safe_to_bootstrap to 1 ."
52+
echo "Or to try a regular start (for example after recovery + manual intervention), run:"
53+
echo " $SUGGEST_EXEC_COMMAND touch /tmp/confirm-resume"
54+
if [ ! -z "$AUTO_RECOVERY_MODE" ]; then
55+
echo "The AUTO_RECOVERY_MODE env was set to $AUTO_RECOVERY_MODE, will trigger that choice"
56+
touch /tmp/$AUTO_RECOVERY_MODE
57+
else
58+
echo "Waiting for response ..."
59+
fi
60+
while [ ! -f /tmp/confirm-resume ]; do
61+
if [ "$AUTO_NEW_CLUSTER" = "true" ]; then
62+
echo "The AUTO_NEW_CLUSTER env was set to $AUTO_NEW_CLUSTER, will proceed without confirmation"
63+
echo "NOTE this env is deprecated, use AUTO_RECOVERY_MODE instead"
64+
wsrepNewCluster
65+
touch /tmp/confirm-resume
66+
elif [ -f /tmp/confirm-new-cluster ]; then
67+
echo "Confirmation received. Resuming new cluster start ..."
68+
wsrepNewCluster
69+
touch /tmp/confirm-resume
70+
elif [ -f /tmp/confirm-force-bootstrap ]; then
71+
echo "Forcing bootstrap on this node ..."
72+
wsrepForceBootstrap
73+
touch /tmp/confirm-new-cluster
74+
elif [ -f /tmp/confirm-recover ]; then
75+
echo "Confirmation received. Resuming in recovery mode."
76+
echo "Note: to start the other pods you need to edit OrderedReady and add a command: --wsrep-recover"
77+
wsrepRecover
78+
touch /tmp/confirm-resume
79+
fi
80+
sleep 1
81+
done
82+
rm /tmp/confirm-*
83+
set -x
84+
fi
85+
}
86+
else
87+
getent hosts mariadb-ready
88+
[ $? -eq 2 ] && {
89+
echo "This is NOT the 1st statefulset pod. Must not go up as primary."
90+
echo "Found no ready pods. Will exit to trigger a crash loop back off."
91+
exit 1
92+
}
93+
fi
94+
95+
# https://github.com/docker-library/mariadb/blob/master/10.2/docker-entrypoint.sh#L62
96+
mysqld --verbose --help --log-bin-index="$(mktemp -u)" | tee /tmp/mariadb-start-config | grep -e ^version -e ^datadir -e ^wsrep -e ^binlog -e ^character-set -e ^collation

base-defaultconfig/kustomization.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
resources:
5+
- ../base
6+
7+
configMapGenerator:
8+
- name: conf-d
9+
files:
10+
- init.sh
11+
- datadir.cnf
12+
- galera.cnf
13+
- utf8.cnf

base-defaultconfig/utf8.cnf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[client-server]
2+
3+
# This will be passed to all mysql clients
4+
[client]
5+
default-character-set = utf8mb4
6+
7+
# The MySQL server
8+
[mysqld]
9+
character-set-server = utf8mb4
10+
collation-server = utf8mb4_unicode_ci
11+
init-connect='SET NAMES utf8mb4'
12+
13+
[mysql]
14+
default-character-set = utf8mb4
15+
16+
[mysqldump]
17+
18+
# This group is only read by MariaDB servers, not by MySQL.
19+
# If you use the same .cnf file for MySQL and MariaDB,
20+
# you can put MariaDB-only options here
21+
[mariadb]
22+
23+
[mariadb-10.1]
24+
25+
[mariadb-10.2]

base/kustomization.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
resources:
5+
- mariadb-service.yaml
6+
- mariadb-ready-service.yaml
7+
- mysql-service.yaml
8+
- mariadb-statefulset.yaml

21mariadb-ready-service.yml renamed to base/mariadb-ready-service.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ apiVersion: v1
44
kind: Service
55
metadata:
66
name: mariadb-ready
7-
namespace: mysql
87
annotations:
98
service.alpha.kubernetes.io/tolerate-unready-endpoints: "false"
109
spec:

20mariadb-service.yml renamed to base/mariadb-service.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ apiVersion: v1
44
kind: Service
55
metadata:
66
name: mariadb
7-
namespace: mysql
87
annotations:
98
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
109
spec:

0 commit comments

Comments
 (0)