From 6e52b74e39c32af970d283a4d11fe5e78acbb688 Mon Sep 17 00:00:00 2001 From: Tomislav Plavcic Date: Tue, 23 Aug 2022 20:23:33 +0200 Subject: [PATCH] K8SPXC-1071 - ProxySQL - Make percona-scheduler-admin optional --- proxysql/dockerdir/entrypoint.sh | 68 ++++++++++------ .../dockerdir/usr/bin/add_proxysql_nodes.sh | 7 +- proxysql/dockerdir/usr/bin/add_pxc_nodes.sh | 78 +++++++++++++------ 3 files changed, 105 insertions(+), 48 deletions(-) diff --git a/proxysql/dockerdir/entrypoint.sh b/proxysql/dockerdir/entrypoint.sh index c05fb6ae5..1758cf777 100755 --- a/proxysql/dockerdir/entrypoint.sh +++ b/proxysql/dockerdir/entrypoint.sh @@ -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} @@ -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 @@ -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 @@ -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 diff --git a/proxysql/dockerdir/usr/bin/add_proxysql_nodes.sh b/proxysql/dockerdir/usr/bin/add_proxysql_nodes.sh index e48268ba2..b5658d991 100755 --- a/proxysql/dockerdir/usr/bin/add_proxysql_nodes.sh +++ b/proxysql/dockerdir/usr/bin/add_proxysql_nodes.sh @@ -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 diff --git a/proxysql/dockerdir/usr/bin/add_pxc_nodes.sh b/proxysql/dockerdir/usr/bin/add_pxc_nodes.sh index 205abca75..1ad1334b6 100755 --- a/proxysql/dockerdir/usr/bin/add_pxc_nodes.sh +++ b/proxysql/dockerdir/usr/bin/add_pxc_nodes.sh @@ -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!" }