-
Notifications
You must be signed in to change notification settings - Fork 43
Add support of the official MySQL Docker image #1198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
8b3d095
6590dd5
5e33a23
086ef01
4abb190
c49b502
87d2655
0d64f3b
7d98904
f0c6e8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -703,6 +703,25 @@ get_storage_alias() { | |||||
| echo "$storage" | ||||||
| } | ||||||
|
|
||||||
| # When MYSQL_UPSTREAM is set, add security settings required by the official mysql image (non-root uid/gid + fsGroup). | ||||||
| # spec.mysql is enough: backup/restore Jobs inherit these contexts unless a storage entry overrides them. | ||||||
| # Upstream mysql image lacks mysqlbinlog; PITR restore Job uses spec.backup.pitr.image (Percona Server main-psmysql* by default). | ||||||
| apply_mysql_upstream_cr_patch() { | ||||||
| if [[ -z ${MYSQL_UPSTREAM-} ]]; then | ||||||
| cat | ||||||
| return | ||||||
| fi | ||||||
| local cr_tmp | ||||||
| cr_tmp=$(mktemp) | ||||||
| cat >"${cr_tmp}" | ||||||
| IMAGE_PITR_RESTORE="${IMAGE_PITR_RESTORE}" yq eval ' | ||||||
| .spec.mysql.containerSecurityContext = {"runAsUser": 1001, "runAsGroup": 1001} | | ||||||
| .spec.mysql.podSecurityContext = {"fsGroup": 1001} | | ||||||
| .spec.backup.pitr.image = strenv(IMAGE_PITR_RESTORE) | ||||||
| ' "${cr_tmp}" | ||||||
| rm -f "${cr_tmp}" | ||||||
| } | ||||||
|
|
||||||
| get_test_cr() { | ||||||
| local cr_name=${1:-$test_name} | ||||||
| local platform=${2:-$(detect_k8s_platform)} | ||||||
|
|
@@ -768,13 +787,30 @@ get_cr() { | |||||
| | yq eval '.spec.proxy.haproxy.resources.requests.cpu = "300m"' - | ||||||
| else | ||||||
| cat | ||||||
| fi | ||||||
| fi \ | ||||||
| | apply_mysql_upstream_cr_patch | ||||||
| } | ||||||
|
|
||||||
| get_client_pod() { | ||||||
| kubectl -n "${NAMESPACE}" get pods \ | ||||||
| --selector=name=mysql-client \ | ||||||
| -o 'jsonpath={.items[].metadata.name}' | ||||||
| # Use {.items[*].metadata.name}: {.items[].…} errors with "array index out of bounds" | ||||||
| # when there are zero pods (recent kubectl). Retry briefly so deploy_client can finish. | ||||||
| local pod="" | ||||||
| local retry=0 | ||||||
| while [[ $retry -lt 120 ]]; do | ||||||
| pod=$(kubectl -n "${NAMESPACE}" get pods \ | ||||||
| --selector=name=mysql-client \ | ||||||
| -o 'jsonpath={.items[*].metadata.name}' 2>/dev/null) || true | ||||||
| pod="${pod%% *}" | ||||||
| if [[ -n "$pod" ]]; then | ||||||
| echo "$pod" | ||||||
| return 0 | ||||||
| fi | ||||||
| sleep 1 | ||||||
| retry=$((retry + 1)) | ||||||
| done | ||||||
| echo "ERROR: mysql-client pod not found after 120s (namespace=${NAMESPACE}). Ensure deploy_client ran (e.g. 00-deploy-operator)." >&2 | ||||||
| kubectl -n "${NAMESPACE}" get pods -l name=mysql-client -o wide >&2 || true | ||||||
| return 1 | ||||||
| } | ||||||
|
|
||||||
| run_mysql() { | ||||||
|
|
@@ -786,8 +822,31 @@ run_mysql() { | |||||
| client_pod=$(get_client_pod) | ||||||
| wait_pod $client_pod 1>&2 | ||||||
|
|
||||||
| kubectl -n "${NAMESPACE}" exec "${pod:-mysql-client}" -- \ | ||||||
| bash -c "printf '%s\n' \"${command}\" | mysql -sN $host $user" 2>&1 \ | ||||||
| local target_pod="${pod:-mysql-client}" | ||||||
| local container_opt=() | ||||||
| if [[ "${target_pod}" != "mysql-client" ]]; then | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [shfmt] reported by reviewdog 🐶
Suggested change
|
||||||
| container_opt=(-c mysql) | ||||||
| fi | ||||||
|
|
||||||
| # 'user'@'localhost' requires a Unix socket; -h localhost uses the *client* default, which often | ||||||
| # does not match mysqld (e.g. /var/run/mysqld/mysqld.sock vs /var/lib/mysql/mysql.sock). | ||||||
| # Operator + ps-entrypoint always use ${DataMountPath}/mysql.sock (see pkg/mysql DataMountPath). | ||||||
| local conn_args="${host}" | ||||||
| if [[ "${target_pod}" != "mysql-client" && "${host}" == *"localhost"* ]]; then | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [shfmt] reported by reviewdog 🐶
Suggested change
|
||||||
| local root_pw socket operator_sock="/var/lib/mysql/mysql.sock" | ||||||
| root_pw=$(get_user_pass root) | ||||||
| # Root must use the same socket as the server; a bare mysql -uroot would repeat the client-default problem. | ||||||
| socket=$(kubectl -n "${NAMESPACE}" exec "${target_pod}" "${container_opt[@]}" -- \ | ||||||
| env MYSQL_PWD="${root_pw}" mysql -sN -uroot --socket="${operator_sock}" -e "SELECT @@socket" 2>/dev/null | tail -1) | ||||||
| socket=$(echo "${socket}" | tr -d '\r' | tr -d '[:space:]') | ||||||
| if [[ -z "${socket}" ]]; then | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [shfmt] reported by reviewdog 🐶
Suggested change
|
||||||
| socket="${operator_sock}" | ||||||
| fi | ||||||
| conn_args="--socket=${socket}" | ||||||
| fi | ||||||
|
|
||||||
| kubectl -n "${NAMESPACE}" exec "${target_pod}" "${container_opt[@]}" -- \ | ||||||
| bash -c "printf '%s\n' \"${command}\" | mysql -sN ${conn_args} ${user}" 2>&1 \ | ||||||
| | $sed -e 's/mysql: //' \ | ||||||
| | (grep -v 'Using a password on the command line interface can be insecure.' || :) | ||||||
| } | ||||||
|
|
@@ -797,12 +856,18 @@ run_mysqlsh() { | |||||
| local host="$2" | ||||||
| local user="${3:--uroot -p'$(get_user_pass)'}" | ||||||
| local pod="$4" | ||||||
| local sql_mode="--sql" | ||||||
|
|
||||||
| # Port 33060 is MySQL X Protocol; --sql uses classic protocol and fails on 8.4+ (ERROR 2007). | ||||||
| if [[ "$host" =~ -P[[:space:]]*33060 ]] || [[ "$host" =~ :33060 ]]; then | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [shfmt] reported by reviewdog 🐶
Suggested change
|
||||||
| sql_mode="--sqlx" | ||||||
| fi | ||||||
|
|
||||||
| client_pod=$(get_client_pod) | ||||||
| wait_pod $client_pod 1>&2 | ||||||
|
|
||||||
| kubectl -n "${NAMESPACE}" exec "${pod:-mysql-client}" -- \ | ||||||
| bash -c "printf '%s\n' \"${command}\" | mysqlsh --sql --quiet-start=2 $host $user" 2>/dev/null \ | ||||||
| bash -c "printf '%s\n' \"${command}\" | mysqlsh ${sql_mode} --quiet-start=2 $host $user" 2>/dev/null \ | ||||||
| | tail -n +2 | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[shfmt] reported by reviewdog 🐶