Skip to content

Commit

Permalink
K8SPXC-1071 - ProxySQL - Make percona-scheduler-admin optional
Browse files Browse the repository at this point in the history
  • Loading branch information
tplavcic committed Aug 23, 2022
1 parent c6db4f0 commit 6e52b74
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 48 deletions.
68 changes: 46 additions & 22 deletions proxysql/dockerdir/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@
set -o xtrace

PROXY_CFG=/etc/proxysql/proxysql.cnf
PROXY_SCHEDULER_CFG=/etc/config.toml
temp_proxy_scheduler_cfg=$(mktemp)
if [ "${SCHEDULER}" == "percona" ]; then
PROXY_SCHEDULER_CFG=/etc/config.toml
temp_proxy_scheduler_cfg=$(mktemp)
else
PROXY_SCHEDULER_CFG=/etc/proxysql-admin.cnf
fi

if [ -n ${PROXYSQL_SERVICE} ]; then
MYSQL_INTERFACES='0.0.0.0:3306;0.0.0.0:33062'
CLUSTER_PORT='33062'
sed "s/^writerIsAlsoReader.*=.*$/writerIsAlsoReader = 1/" ${PROXY_SCHEDULER_CFG} | \
sed "s/^clustered.*=.*false$/clustered = true/" > ${temp_proxy_scheduler_cfg}
cp ${temp_proxy_scheduler_cfg} ${PROXY_SCHEDULER_CFG}
if [ "${SCHEDULER}" == "percona" ]; then
sed "s/^writerIsAlsoReader.*=.*$/writerIsAlsoReader = 1/" ${PROXY_SCHEDULER_CFG} | \
sed "s/^clustered.*=.*false$/clustered = true/" > ${temp_proxy_scheduler_cfg}
cp ${temp_proxy_scheduler_cfg} ${PROXY_SCHEDULER_CFG}
else
sed "s/#export WRITERS_ARE_READERS=.*$/export WRITERS_ARE_READERS='yes'/g" ${PROXY_SCHEDULER_CFG} 1<> ${PROXY_SCHEDULER_CFG}
fi
fi

sed "s/interfaces=\"0.0.0.0:3306\"/interfaces=\"${MYSQL_INTERFACES:-0.0.0.0:3306}\"/g" ${PROXY_CFG} 1<> ${PROXY_CFG}
Expand All @@ -28,14 +36,24 @@ sed "s/cluster_username=\"admin\"/cluster_username=\"${PROXY_ADMIN_USER:-admin}\
sed "s/cluster_password=\"admin\"/cluster_password=\"${PROXY_ADMIN_PASSWORD:-admin}\"/g" ${PROXY_CFG} 1<> ${PROXY_CFG}
sed "s/monitor_password=\"monitor\"/monitor_password=\"${MONITOR_PASSWORD:-monitor}\"/g" ${PROXY_CFG} 1<> ${PROXY_CFG}

sed "s/^user.*=.*\"$/user = '${PROXY_ADMIN_USER:-admin}'/" ${PROXY_SCHEDULER_CFG} | \
sed "s/^password.*=.*\"$/password = '${PROXY_ADMIN_PASSWORD_ESCAPED:-admin}'/" | \
sed "s/^clusterUserPassword.*=.*\"$/clusterUserPassword='${OPERATOR_PASSWORD_ESCAPED:-operator}'/" | \
sed "s/^clusterUser.*=.*\"$/clusterUser = 'operator'/" | \
sed "s/^clusterPort.*=.*\"$/clusterPort='${CLUSTER_PORT:-3306}'/" | \
sed "s/^monitorUserPassword.*=.*\"$/monitorUserPassword='${MONITOR_PASSWORD_ESCAPED:-monitor}'/" | \
sed "s/^monitorUser.*=.*\"$/monitorUser='monitor'/" > ${temp_proxy_scheduler_cfg}
cp ${temp_proxy_scheduler_cfg} ${PROXY_SCHEDULER_CFG}
if [ "${SCHEDULER}" == "percona" ]; then
sed "s/^user.*=.*\"$/user = '${PROXY_ADMIN_USER:-admin}'/" ${PROXY_SCHEDULER_CFG} | \
sed "s/^password.*=.*\"$/password = '${PROXY_ADMIN_PASSWORD_ESCAPED:-admin}'/" | \
sed "s/^clusterUserPassword.*=.*\"$/clusterUserPassword='${OPERATOR_PASSWORD_ESCAPED:-operator}'/" | \
sed "s/^clusterUser.*=.*\"$/clusterUser = 'operator'/" | \
sed "s/^clusterPort.*=.*\"$/clusterPort='${CLUSTER_PORT:-3306}'/" | \
sed "s/^monitorUserPassword.*=.*\"$/monitorUserPassword='${MONITOR_PASSWORD_ESCAPED:-monitor}'/" | \
sed "s/^monitorUser.*=.*\"$/monitorUser='monitor'/" > ${temp_proxy_scheduler_cfg}
cp ${temp_proxy_scheduler_cfg} ${PROXY_SCHEDULER_CFG}
else
sed "s/PROXYSQL_USERNAME='admin'/PROXYSQL_USERNAME='${PROXY_ADMIN_USER:-admin}'/g" ${PROXY_SCHEDULER_CFG} 1<> ${PROXY_SCHEDULER_CFG}
sed "s/PROXYSQL_PASSWORD='admin'/PROXYSQL_PASSWORD='${PROXY_ADMIN_PASSWORD_ESCAPED:-admin}'/g" ${PROXY_SCHEDULER_CFG} 1<> ${PROXY_SCHEDULER_CFG}
sed "s/CLUSTER_USERNAME='admin'/CLUSTER_USERNAME='operator'/g" ${PROXY_SCHEDULER_CFG} 1<> ${PROXY_SCHEDULER_CFG}
sed "s/CLUSTER_PASSWORD='admin'/CLUSTER_PASSWORD='${OPERATOR_PASSWORD_ESCAPED:-operator}'/g" ${PROXY_SCHEDULER_CFG} 1<> ${PROXY_SCHEDULER_CFG}
sed "s/CLUSTER_PORT='3306'/CLUSTER_PORT='${CLUSTER_PORT:-3306}'/g" ${PROXY_SCHEDULER_CFG} 1<> ${PROXY_SCHEDULER_CFG}
sed "s/MONITOR_USERNAME='monitor'/MONITOR_USERNAME='monitor'/g" ${PROXY_SCHEDULER_CFG} 1<> ${PROXY_SCHEDULER_CFG}
sed "s/MONITOR_PASSWORD='monitor'/MONITOR_PASSWORD='${MONITOR_PASSWORD_ESCAPED:-monitor}'/g" ${PROXY_SCHEDULER_CFG} 1<> ${PROXY_SCHEDULER_CFG}
fi

set -o xtrace

Expand All @@ -47,14 +65,18 @@ fi
SSL_DIR=${SSL_DIR:-/etc/proxysql/ssl}
if [ -f "${SSL_DIR}/ca.crt" ]; then
CA=${SSL_DIR}/ca.crt
sed "s:^sslCertificatePath.*= .*\"$:sslCertificatePath = \"${SSL_DIR}\":" ${PROXY_SCHEDULER_CFG} > ${temp_proxy_scheduler_cfg}
cp ${temp_proxy_scheduler_cfg} ${PROXY_SCHEDULER_CFG}
if [ "${SCHEDULER}" == "percona" ]; then
sed "s:^sslCertificatePath.*= .*\"$:sslCertificatePath = \"${SSL_DIR}\":" ${PROXY_SCHEDULER_CFG} > ${temp_proxy_scheduler_cfg}
cp ${temp_proxy_scheduler_cfg} ${PROXY_SCHEDULER_CFG}
fi
fi
SSL_INTERNAL_DIR=${SSL_INTERNAL_DIR:-/etc/proxysql/ssl-internal}
if [ -f "${SSL_INTERNAL_DIR}/ca.crt" ]; then
CA=${SSL_INTERNAL_DIR}/ca.crt
sed "s:^sslCertificatePath.*= .*\"$:sslCertificatePath = \"${SSL_INTERNAL_DIR}\":" ${PROXY_SCHEDULER_CFG} > ${temp_proxy_scheduler_cfg}
cp ${temp_proxy_scheduler_cfg} ${PROXY_SCHEDULER_CFG}
if [ "${SCHEDULER}" == "percona" ]; then
sed "s:^sslCertificatePath.*= .*\"$:sslCertificatePath = \"${SSL_INTERNAL_DIR}\":" ${PROXY_SCHEDULER_CFG} > ${temp_proxy_scheduler_cfg}
cp ${temp_proxy_scheduler_cfg} ${PROXY_SCHEDULER_CFG}
fi
fi

KEY=${SSL_DIR}/tls.key
Expand All @@ -70,12 +92,14 @@ if [ -f "$CA" ] && [ -f "$KEY" ] && [ -f "$CERT" ] && [ -n "$PXC_SERVICE" ]; the
sed "s^ssl_p2s_ca=\"\"^ssl_p2s_ca=\"$CA\"^" ${PROXY_CFG} 1<> ${PROXY_CFG}
sed "s^ssl_p2s_key=\"\"^ssl_p2s_key=\"$KEY\"^" ${PROXY_CFG} 1<> ${PROXY_CFG}
sed "s^ssl_p2s_cert=\"\"^ssl_p2s_cert=\"$CERT\"^" ${PROXY_CFG} 1<> ${PROXY_CFG}
sed "s:^sslCa.*=.*\"$:sslCa = \"${CA##*/}\":" ${PROXY_SCHEDULER_CFG} | \
sed "s:^sslKey.*=.*\"$:sslKey = \"${KEY##*/}\":" | \
sed "s:^sslClient.*=.*\"$:sslClient = \"${CERT##*/}\":" > ${temp_proxy_scheduler_cfg}
cp ${temp_proxy_scheduler_cfg} ${PROXY_SCHEDULER_CFG}
if [ "${SCHEDULER}" == "percona" ]; then
sed "s:^sslCa.*=.*\"$:sslCa = \"${CA##*/}\":" ${PROXY_SCHEDULER_CFG} | \
sed "s:^sslKey.*=.*\"$:sslKey = \"${KEY##*/}\":" | \
sed "s:^sslClient.*=.*\"$:sslClient = \"${CERT##*/}\":" > ${temp_proxy_scheduler_cfg}
cp ${temp_proxy_scheduler_cfg} ${PROXY_SCHEDULER_CFG}
rm ${temp_proxy_scheduler_cfg}
fi
fi
rm ${temp_proxy_scheduler_cfg}

if [ -f "${SSL_DIR}/tls.key" ] && [ -f "${SSL_DIR}/tls.crt" ]; then
cp "${SSL_DIR}/tls.key" /var/lib/proxysql/proxysql-key.pem
Expand Down
7 changes: 6 additions & 1 deletion proxysql/dockerdir/usr/bin/add_proxysql_nodes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ function proxysql_admin_exec() {
function wait_for_proxysql() {
local server="$1"
echo "Waiting for host $server to be online..."
while [ "$(proxysql_admin_exec "$server" 'SELECT MAX(active) FROM runtime_scheduler')" != "1" ]
if [ "${SCHEDULER}" == "percona" ]; then
PROXYSQL_TABLE="runtime_scheduler"
else
PROXYSQL_TABLE="runtime_mysql_galera_hostgroups"
fi
while [ "$(proxysql_admin_exec "$server" "SELECT MAX(active) FROM ${PROXYSQL_TABLE}")" != "1" ]
do
echo "ProxySQL is not up yet... sleeping ..."
sleep 1
Expand Down
78 changes: 53 additions & 25 deletions proxysql/dockerdir/usr/bin/add_pxc_nodes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,61 @@ function main() {
SSL_ARG=""
temp=$(mktemp)
if [ "$(proxysql_admin_exec "127.0.0.1" 'SELECT variable_value FROM global_variables WHERE variable_name="mysql-have_ssl"')" = "true" ]; then
sed "s/^useSSL.*=.*$/useSSL=1/" /etc/config.toml > ${temp} && cp ${temp} /etc/config.toml
if [ "${SCHEDULER}" == "percona" ]; then
sed "s/^useSSL.*=.*$/useSSL=1/" /etc/config.toml > ${temp} && cp ${temp} /etc/config.toml
else
SSL_ARG="--use-ssl=yes"
fi
fi

sed "s/^clusterHost.*=.*\"$/clusterHost=\"$first_host\"/" /etc/config.toml > ${temp} && cp ${temp} /etc/config.toml
rm ${temp}

percona-scheduler-admin \
--config-file=/etc/config.toml \
--write-node="$pod_zero.$service:3306" \
--enable \
--update-cluster \
--remove-all-servers \
--disable-updates \
--force \
$SSL_ARG

percona-scheduler-admin \
--config-file=/etc/config.toml \
--write-node="$pod_zero.$service:3306" \
--sync-multi-cluster-users \
--add-query-rule \
--disable-updates \
--force

percona-scheduler-admin \
--config-file=/etc/config.toml \
--update-mysql-version
if [ "${SCHEDULER}" == "percona" ]; then
sed "s/^clusterHost.*=.*\"$/clusterHost=\"$first_host\"/" /etc/config.toml > ${temp} && cp ${temp} /etc/config.toml
rm ${temp}

percona-scheduler-admin \
--config-file=/etc/config.toml \
--write-node="$pod_zero.$service:3306" \
--enable \
--update-cluster \
--remove-all-servers \
--disable-updates \
--force

percona-scheduler-admin \
--config-file=/etc/config.toml \
--write-node="$pod_zero.$service:3306" \
--sync-multi-cluster-users \
--add-query-rule \
--disable-updates \
--force

percona-scheduler-admin \
--config-file=/etc/config.toml \
--update-mysql-version
else
proxysql-admin \
--config-file=/etc/proxysql-admin.cnf \
--cluster-hostname="$first_host" \
--enable \
--update-cluster \
--force \
--remove-all-servers \
--disable-updates \
$SSL_ARG

proxysql-admin \
--config-file=/etc/proxysql-admin.cnf \
--cluster-hostname="$first_host" \
--sync-multi-cluster-users \
--add-query-rule \
--disable-updates \
--force

proxysql-admin \
--config-file=/etc/proxysql-admin.cnf \
--cluster-hostname="$first_host" \
--update-mysql-version
fi

echo "All done!"
}
Expand Down

0 comments on commit 6e52b74

Please sign in to comment.