From 6c82972f675fc5cbe6a2f17eed2c1a9ab42bf697 Mon Sep 17 00:00:00 2001 From: BlueBird <112836850+cbluebird@users.noreply.github.com> Date: Thu, 15 Aug 2024 11:39:23 +0800 Subject: [PATCH] fix: check control plane count of master IPs (#4972) --- scripts/cloud/install.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scripts/cloud/install.sh b/scripts/cloud/install.sh index 8499915b4c8..3edce161f61 100644 --- a/scripts/cloud/install.sh +++ b/scripts/cloud/install.sh @@ -516,6 +516,22 @@ wait_cluster_ready() { done } +check_control_plane_count() { + # Check if master_ips is empty + if [[ -z "$master_ips" ]]; then + return 0 + fi + + IFS=',' read -r -a master_ips_array <<< "$master_ips" + num_ips=${#master_ips_array[@]} + + # If the number is even, output an error message and exit + if (( num_ips % 2 == 0 )); then + echo "Error: The number of master IPs is even. Please provide an odd number of master IPs." + exit 1 + fi +} + loading_animation() { local message="$1" local duration="${2:-0.5}" @@ -659,6 +675,7 @@ done [[ $HELP == "" ]] || get_prompt "usage" [[ $HELP == "" ]] || exit 0 +check_control_plane_count set_language init collect_input