Skip to content
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

K8SPXC-1222: Remove state check from readiness probe #1909

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ RUN GOOS=$GOOS GOARCH=${TARGETARCH} CGO_ENABLED=$CGO_ENABLED GO_LDFLAGS=$GO_LDFL
&& cp -r build/_output/bin/pitr /usr/local/bin/pitr

RUN GOOS=$GOOS GOARCH=${TARGETARCH} CGO_ENABLED=$CGO_ENABLED GO_LDFLAGS=$GO_LDFLAGS \
go build -o build/_output/bin/mysql-state-monitor \
cmd/mysql-state-monitor/main.go \
go build -ldflags "-w -s -X main.GitCommit=$GIT_COMMIT -X main.GitBranch=$GIT_BRANCH -X main.BuildTime=$BUILD_TIME" \
-o build/_output/bin/mysql-state-monitor cmd/mysql-state-monitor/main.go \
&& cp -r build/_output/bin/mysql-state-monitor /usr/local/bin/mysql-state-monitor

# Looking for all possible License/Notice files and copying them to the image
Expand Down
9 changes: 1 addition & 8 deletions build/readiness-check.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shfmt] reported by reviewdog 🐶

WSREP_STATUS=($(MYSQL_PWD="${MYSQL_PASSWORD}" $MYSQL_CMDLINE --init-command="SET SESSION wsrep_sync_wait=0;" -e "SHOW GLOBAL STATUS LIKE 'wsrep_%';" |
grep -A 1 -E 'wsrep_local_state$|wsrep_cluster_status$' |
sed -n -e '2p' -e '5p' | tr '\n' ' '))

Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@
DEFAULTS_EXTRA_FILE=${DEFAULTS_EXTRA_FILE:-/etc/my.cnf}
AVAILABLE_WHEN_DONOR=${AVAILABLE_WHEN_DONOR:-1}
NODE_IP=$(hostname -I | awk ' { print $1 } ')
MYSQL_STATE=ready
MYSQL_VERSION=$(mysqld -V | awk '{print $3}' | awk -F'.' '{print $1"."$2}')
if [[ ${MYSQL_VERSION} =~ ^(8\.0|8\.4)$ && -f ${MYSQL_STATE_FILE} ]]; then
MYSQL_STATE=$(tr -d '\0' < ${MYSQL_STATE_FILE})
fi

#Timeout exists for instances where mysqld may be hung
TIMEOUT=$((${READINESS_CHECK_TIMEOUT:-10} - 1))

Expand All @@ -36,13 +30,12 @@
MYSQL_CMDLINE="/usr/bin/timeout $TIMEOUT mysql -nNE --connect-timeout=$TIMEOUT ${EXTRA_ARGS}"
fi

WSREP_STATUS=($(MYSQL_PWD="${MYSQL_PASSWORD}" $MYSQL_CMDLINE --init-command="SET SESSION wsrep_sync_wait=0;" -e "SHOW GLOBAL STATUS LIKE 'wsrep_%';" |

Check warning on line 33 in build/readiness-check.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/readiness-check.sh#L33 <ShellCheck.SC2207>

Prefer mapfile or read -a to split command output (or quote to avoid splitting).
Raw output
./build/readiness-check.sh:33:15: warning: Prefer mapfile or read -a to split command output (or quote to avoid splitting). (ShellCheck.SC2207)
grep -A 1 -E 'wsrep_local_state$|wsrep_cluster_status$' |
sed -n -e '2p' -e '5p' | tr '\n' ' '))
set -x

if [[ "${MYSQL_STATE}" == "ready" && ${WSREP_STATUS[1]} == 'Primary' &&
(${WSREP_STATUS[0]} -eq 4 || (${WSREP_STATUS[0]} -eq 2 && $AVAILABLE_WHEN_DONOR -eq 1)) ]]; then
if [[ ${WSREP_STATUS[1]} == 'Primary' && (${WSREP_STATUS[0]} -eq 4 || (${WSREP_STATUS[0]} -eq 2 && $AVAILABLE_WHEN_DONOR -eq 1)) ]]; then
exit 0
else
exit 1
Expand Down
10 changes: 9 additions & 1 deletion cmd/mysql-state-monitor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import (
"strings"
)

var (
GitCommit string
GitBranch string
BuildTime string
)

type MySQLState string

const (
Expand Down Expand Up @@ -56,6 +62,7 @@ func parseDatum(datum string) MySQLState {
"Components initialization in progress",
"Components initialization successful",
"Connection shutdown complete",
"Execution of SQL Commands from Init-file in progress",
"Execution of SQL Commands from Init-file successful",
"Initialization of dynamic plugins in progress",
"Initialization of dynamic plugins successful",
Expand Down Expand Up @@ -91,7 +98,8 @@ func parseDatum(datum string) MySQLState {
}

func main() {
log.Println("Starting mysql-state-monitor")
log.Println("Starting mysql-state-monitor...")
log.Printf("GitCommit=%s GitBranch=%s BuildTime=%s", GitCommit, GitBranch, BuildTime)

socketPath, ok := os.LookupEnv("NOTIFY_SOCKET")
if !ok {
Expand Down
Loading