Skip to content

Commit 891cb63

Browse files
nmarukovichvalmiranogueira
authored andcommitted
K8SPS-265 fix heartbeat
1 parent 9e83919 commit 891cb63

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

build/heartbeat-entrypoint.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ for i in {1..5}; do
2929
sleep "$((TIMEOUT * i))"
3030
fi
3131
done
32+
ESCAPED_HEARTBEAT_PASSWORD="${HEARTBEAT_PASSWORD//,/\\,}"
3233

3334
HEARTBEAT_USER='heartbeat'
3435
echo "[INFO] pt-heartbeat --update --replace --fail-successive-errors 20 --check-read-only --create-table --database sys_operator \
@@ -43,5 +44,5 @@ pt-heartbeat \
4344
--database sys_operator \
4445
--table heartbeat \
4546
--user "${HEARTBEAT_USER}" \
46-
--password "${HEARTBEAT_PASSWORD}" \
47+
--password "${ESCAPED_HEARTBEAT_PASSWORD}" \
4748
--port "${MYSQL_ADMIN_PORT}"

build/ps-entrypoint.sh

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,26 @@ ensure_read_only() {
212212

213213
escape_special() {
214214
{ set +x; } 2>/dev/null
215-
echo "$1" \
216-
| sed 's/\\/\\\\/g' \
217-
| sed 's/'\''/'\\\\\''/g' \
218-
| sed 's/"/\\\"/g'
215+
216+
# $1 = input string
217+
# $2 = optional flag, e.g., "heartbeat" to enable comma escaping
218+
219+
result="$1"
220+
221+
# Escape backslashes
222+
result=$(echo "$result" | sed 's/\\/\\\\/g')
223+
# Escape single quotes
224+
result=$(echo "$result" | sed "s/'/\\\\'/g")
225+
# Escape double quotes
226+
result=$(echo "$result" | sed 's/"/\\\"/g')
227+
228+
# Escape comma ONLY if second argument is "heartbeat"
229+
# If password contains commas they must be escaped with a backslash: “exam,ple” according https://docs.percona.com/percona-toolkit/pt-heartbeat.html
230+
if [[ "$2" == "heartbeat" ]]; then
231+
result=$(echo "$result" | sed 's/,/\\,/g')
232+
fi
233+
234+
echo "$result"
219235
}
220236

221237
MYSQL_VERSION=$(mysqld -V | awk '{print $3}' | awk -F'.' '{print $1"."$2}')
@@ -358,7 +374,7 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
358374
GRANT SELECT ON sys_operator.* TO 'orchestrator'@'%';
359375
360376
CREATE DATABASE IF NOT EXISTS sys_operator;
361-
CREATE USER 'heartbeat'@'localhost' IDENTIFIED BY '$(escape_special "${HEARTBEAT_PASSWORD}")' PASSWORD EXPIRE NEVER;
377+
CREATE USER 'heartbeat'@'localhost' IDENTIFIED BY '$(escape_special "${HEARTBEAT_PASSWORD}" "heartbeat")' PASSWORD EXPIRE NEVER;
362378
GRANT SYSTEM_USER, REPLICATION CLIENT ON *.* TO 'heartbeat'@'localhost';
363379
GRANT SELECT, CREATE, DELETE, UPDATE, INSERT ON sys_operator.heartbeat TO 'heartbeat'@'localhost';
364380

0 commit comments

Comments
 (0)