From a1e67dc5d41467c76ae7d19c0c3559674b64b5a7 Mon Sep 17 00:00:00 2001 From: Tim Mirecki Date: Fri, 12 Apr 2019 11:33:14 -0400 Subject: [PATCH 1/2] Add command_remove to allow a pod to exit the cluster gracefully. Refs #37. --- docker/files/cli/commands/cluster.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/docker/files/cli/commands/cluster.sh b/docker/files/cli/commands/cluster.sh index a23b99f..db9fd74 100644 --- a/docker/files/cli/commands/cluster.sh +++ b/docker/files/cli/commands/cluster.sh @@ -53,11 +53,20 @@ command_query:rules() { proxysql_execute_query_hr "SELECT * FROM mysql_query_rules" } -commands_add "query:nodes" "Show al the nodes of the cluster" +commands_add "query:nodes" "Show all the nodes of the cluster" command_query:nodes() { proxysql_execute_query_hr "SELECT * FROM proxysql_servers;" } +commands_add "remove" "Remove this node from the cluster" +command_remove() { + proxysql_execute_query_hr " + DELETE FROM proxysql_servers + WHERE hostname = '${IP}'; + LOAD PROXYSQL SERVERS TO RUN; + " ${PROXYSQL_SERVICE} +} + commands_add "sync" "Synchronize from backends" command_sync() { local joinExistingCluster=${1}; From 064b1d27f3e4153ff8757db53832f0d4bd7220a0 Mon Sep 17 00:00:00 2001 From: Tim Mirecki Date: Fri, 12 Apr 2019 11:40:20 -0400 Subject: [PATCH 2/2] Add preStop pod lifecycle hook to remove node from cluster proxysql_servers before termination. --- deploy/charts/proxysql-cluster/templates/statefulset.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/deploy/charts/proxysql-cluster/templates/statefulset.yaml b/deploy/charts/proxysql-cluster/templates/statefulset.yaml index d2c9ed6..f66c0c1 100644 --- a/deploy/charts/proxysql-cluster/templates/statefulset.yaml +++ b/deploy/charts/proxysql-cluster/templates/statefulset.yaml @@ -53,6 +53,13 @@ spec: - mountPath: /etc/proxysql.cnf name: proxysql subPath: proxysql.cnf + lifecycle: + preStop: + exec: + command: + - /bin/bash + - -c + - "/usr/bin/proxysql-cli remove" {{ if .Values.resources }} resources: {{ .Values.resources | indent 12 }}