diff --git a/bin/wild-node-detect b/bin/wild-node-detect index 9874fbe..75197dd 100755 --- a/bin/wild-node-detect +++ b/bin/wild-node-detect @@ -124,14 +124,14 @@ fi # Discover available disks echo "Discovering available disks..." >&2 if [ "$TALOS_MODE" = "insecure" ]; then - AVAILABLE_DISKS_RAW=$(talosctl -n "$NODE_IP" get disks --insecure -o json 2>/dev/null | \ - jq -s -r '.[] | select(.spec.size > 10000000000) | .metadata.id') + DISKS_JSON=$(talosctl -n "$NODE_IP" get disks --insecure -o json 2>/dev/null | \ + jq -s '[.[] | select(.spec.size > 10000000000) | {path: ("/dev/" + .metadata.id), size: .spec.size}]') else - AVAILABLE_DISKS_RAW=$(talosctl -n "$NODE_IP" get disks -o json 2>/dev/null | \ - jq -s -r '.[] | select(.spec.size > 10000000000) | .metadata.id') + DISKS_JSON=$(talosctl -n "$NODE_IP" get disks -o json 2>/dev/null | \ + jq -s '[.[] | select(.spec.size > 10000000000) | {path: ("/dev/" + .metadata.id), size: .spec.size}]') fi -if [ -z "$AVAILABLE_DISKS_RAW" ]; then +if [ "$(echo "$DISKS_JSON" | jq 'length')" -eq 0 ]; then echo "Error: No suitable disks found (must be >10GB)" >&2 echo "Available disks:" >&2 if [ "$TALOS_MODE" = "insecure" ]; then @@ -142,11 +142,11 @@ if [ -z "$AVAILABLE_DISKS_RAW" ]; then exit 1 fi -# Convert to JSON array -AVAILABLE_DISKS=$(echo "$AVAILABLE_DISKS_RAW" | jq -R -s 'split("\n") | map(select(length > 0)) | map("/dev/" + .)') +# Use the disks with size info directly +AVAILABLE_DISKS="$DISKS_JSON" -# Select the first disk as default (largest first) -SELECTED_DISK=$(echo "$AVAILABLE_DISKS" | jq -r '.[0]') +# Select the first disk as default +SELECTED_DISK=$(echo "$AVAILABLE_DISKS" | jq -r '.[0].path') echo "✅ Discovered $(echo "$AVAILABLE_DISKS" | jq -r 'length') suitable disks" >&2 echo "✅ Selected disk: $SELECTED_DISK" >&2 diff --git a/bin/wild-setup-cluster b/bin/wild-setup-cluster index b6abe2d..a8c7e54 100755 --- a/bin/wild-setup-cluster +++ b/bin/wild-setup-cluster @@ -260,7 +260,7 @@ if [ "${SKIP_HARDWARE}" = false ]; then # Parse JSON response INTERFACE=$(echo "$NODE_INFO" | jq -r '.interface') SELECTED_DISK=$(echo "$NODE_INFO" | jq -r '.selected_disk') - AVAILABLE_DISKS=$(echo "$NODE_INFO" | jq -r '.disks | join(", ")') + AVAILABLE_DISKS=$(echo "$NODE_INFO" | jq -r '.disks[] | "\(.path) (\((.size / 1000000000) | floor)GB)"' | paste -sd, -) print_success "Hardware detected:" print_info " - Interface: $INTERFACE" @@ -272,9 +272,9 @@ if [ "${SKIP_HARDWARE}" = false ]; then read -p "Use selected disk '$SELECTED_DISK'? (Y/n): " -r use_disk if [[ $use_disk =~ ^[Nn]$ ]]; then echo "Available disks:" - echo "$NODE_INFO" | jq -r '.disks[]' | nl -w2 -s') ' + echo "$NODE_INFO" | jq -r '.disks[] | "\(.path) (\((.size / 1000000000) | floor)GB)"' | nl -w2 -s') ' read -p "Enter disk number: " -r disk_num - SELECTED_DISK=$(echo "$NODE_INFO" | jq -r ".disks[$((disk_num-1))]") + SELECTED_DISK=$(echo "$NODE_INFO" | jq -r ".disks[$((disk_num-1))].path") if [ "$SELECTED_DISK" = "null" ] || [ -z "$SELECTED_DISK" ]; then print_error "Invalid disk selection" continue @@ -359,6 +359,11 @@ if [ "${SKIP_HARDWARE}" = false ]; then read -p "Do you want to register a worker node? (y/N): " -r register_worker if [[ $register_worker =~ ^[Yy]$ ]]; then + # Find first available worker number + while [ -n "$(wild-config "cluster.nodes.active.\"${HOSTNAME_PREFIX}worker-${WORKER_COUNT}\".role" 2>/dev/null)" ] && [ "$(wild-config "cluster.nodes.active.\"${HOSTNAME_PREFIX}worker-${WORKER_COUNT}\".role" 2>/dev/null)" != "null" ]; do + WORKER_COUNT=$((WORKER_COUNT + 1)) + done + NODE_NAME="${HOSTNAME_PREFIX}worker-${WORKER_COUNT}" read -p "Enter current IP for worker node $NODE_NAME: " -r WORKER_IP @@ -388,7 +393,7 @@ if [ "${SKIP_HARDWARE}" = false ]; then # Parse JSON response INTERFACE=$(echo "$WORKER_INFO" | jq -r '.interface') SELECTED_DISK=$(echo "$WORKER_INFO" | jq -r '.selected_disk') - AVAILABLE_DISKS=$(echo "$WORKER_INFO" | jq -r '.disks | join(", ")') + AVAILABLE_DISKS=$(echo "$WORKER_INFO" | jq -r '.disks[] | "\(.path) (\((.size / 1000000000) | floor)GB)"' | paste -sd, -) print_success "Hardware detected for worker node $NODE_NAME:" print_info " - Interface: $INTERFACE" @@ -400,9 +405,9 @@ if [ "${SKIP_HARDWARE}" = false ]; then read -p "Use selected disk '$SELECTED_DISK'? (Y/n): " -r use_disk if [[ $use_disk =~ ^[Nn]$ ]]; then echo "Available disks:" - echo "$WORKER_INFO" | jq -r '.disks[]' | nl -w2 -s') ' + echo "$WORKER_INFO" | jq -r '.disks[] | "\(.path) (\((.size / 1000000000) | floor)GB)"' | nl -w2 -s') ' read -p "Enter disk number: " -r disk_num - SELECTED_DISK=$(echo "$WORKER_INFO" | jq -r ".disks[$((disk_num-1))]") + SELECTED_DISK=$(echo "$WORKER_INFO" | jq -r ".disks[$((disk_num-1))].path") if [ "$SELECTED_DISK" = "null" ] || [ -z "$SELECTED_DISK" ]; then print_error "Invalid disk selection" continue diff --git a/scripts/common.sh b/scripts/common.sh index d2b1973..b4197eb 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -10,16 +10,16 @@ # #!/bin/bash # set -e # set -o pipefail -# +# # # Source common utilities # source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh" -# +# # # Initialize Wild Cloud environment # init_wild_env # # AVAILABLE FUNCTIONS: # - Print functions: print_header, print_info, print_warning, print_success, print_error -# - Config functions: prompt_with_default +# - Config functions: prompt_with_default # - Config helpers: prompt_if_unset_config, prompt_if_unset_secret # - Validation: check_wild_directory # - Utilities: command_exists, file_readable, dir_writable, generate_random_string @@ -72,7 +72,7 @@ prompt_with_default() { local default="$2" local current_value="$3" local result - + if [ -n "${current_value}" ] && [ "${current_value}" != "null" ]; then printf "%s [current: %s]: " "${prompt}" "${current_value}" >&2 read -r result @@ -99,7 +99,7 @@ prompt_with_default() { read -r result done fi - + echo "${result}" } @@ -108,10 +108,10 @@ prompt_if_unset_config() { local config_path="$1" local prompt="$2" local default="$3" - + local current_value current_value=$(wild-config "${config_path}") - + if [ -z "${current_value}" ] || [ "${current_value}" = "null" ]; then local new_value new_value=$(prompt_with_default "${prompt}" "${default}" "") @@ -127,10 +127,10 @@ prompt_if_unset_secret() { local secret_path="$1" local prompt="$2" local default="$3" - + local current_value current_value=$(wild-secret "${secret_path}") - + if [ -z "${current_value}" ] || [ "${current_value}" = "null" ]; then local new_value new_value=$(prompt_with_default "${prompt}" "${default}" "") @@ -149,7 +149,7 @@ prompt_if_unset_secret() { # Returns the path to the project root, or empty string if not found find_wc_home() { local current_dir="$(pwd)" - + while [ "$current_dir" != "/" ]; do if [ -d "$current_dir/.wildcloud" ]; then echo "$current_dir" @@ -157,7 +157,7 @@ find_wc_home() { fi current_dir="$(dirname "$current_dir")" done - + # Not found return 1 } @@ -169,7 +169,7 @@ init_wild_env() { echo "ERROR: WC_ROOT is not set." exit 1 else - + # Check if WC_ROOT is a valid directory if [ ! -d "${WC_ROOT}" ]; then echo "ERROR: WC_ROOT directory does not exist! Did you install the wild-cloud root?"