Skip to content
Draft
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
23 changes: 18 additions & 5 deletions addons/mysql/scripts/orc-member-leave.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,34 @@ mysql_error() {
exit 1
}

# memberLeave contract: KubeBlocks injects the LEAVING member's identity as
# KB_LEAVE_MEMBER_POD_NAME; the action may execute on a different pod, so
# KB_AGENT_POD_NAME (the execution pod) is only a fallback for older runtimes.
leave_member="${KB_LEAVE_MEMBER_POD_NAME:-${KB_AGENT_POD_NAME}}"
if [ -z "$leave_member" ]; then
mysql_error "Neither KB_LEAVE_MEMBER_POD_NAME nor KB_AGENT_POD_NAME is set"
fi

# Forget instance from Orchestrator
if /kubeblocks/orchestrator-client -c forget -i "${KB_AGENT_POD_NAME}" 2>&1; then
if /kubeblocks/orchestrator-client -c forget -i "${leave_member}" 2>&1; then
mysql_note "Forget command executed"
else
mysql_note "Forget command failed, continuing anyway"
fi

sleep 3

# Verify instance was forgotten
# Verify instance was forgotten. "Instance not found" and "Orchestrator is
# down" both yield an empty query result, so prove Orchestrator is reachable
# first - otherwise an outage would be reported as a successful removal.
mysql_note "Verifying instance was forgotten..."
instance_info=$(/kubeblocks/orchestrator-client -c instance -i "${KB_AGENT_POD_NAME}" 2>/dev/null || echo "")
if ! /kubeblocks/orchestrator-client -c clusters >/dev/null 2>&1; then
mysql_error "Orchestrator unreachable; cannot verify removal of ${leave_member}"
fi
instance_info=$(/kubeblocks/orchestrator-client -c instance -i "${leave_member}" 2>/dev/null || true)

if [ -z "$instance_info" ]; then
mysql_note "Instance ${KB_AGENT_POD_NAME} successfully removed from Orchestrator"
mysql_note "Instance ${leave_member} successfully removed from Orchestrator"
exit 0
fi
mysql_error "Instance ${KB_AGENT_POD_NAME} still exists in Orchestrator"
mysql_error "Instance ${leave_member} still exists in Orchestrator"
Loading