diff --git a/bin/wild-cluster-config-generate b/bin/wild-cluster-config-generate index 9bc0c7f..1640b7f 100755 --- a/bin/wild-cluster-config-generate +++ b/bin/wild-cluster-config-generate @@ -3,54 +3,11 @@ set -e set -o pipefail -# Get WC_ROOT (where this script and templates live) -WC_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.."; pwd)" -export WC_ROOT +# Source common utilities +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh" -# Set up cloud directory (WC_HOME is where user's cloud will be) -WC_HOME="$(pwd)" -export WC_HOME - -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -BLUE='\033[0;34m' -NC='\033[0m' # No Color - -# Helper functions -print_header() { - echo -e "\n${BLUE}=== $1 ===${NC}\n" -} - -print_info() { - echo -e "${BLUE}INFO:${NC} $1" -} - -print_warning() { - echo -e "${YELLOW}WARNING:${NC} $1" -} - -print_success() { - echo -e "${GREEN}SUCCESS:${NC} $1" -} - -print_error() { - echo -e "${RED}ERROR:${NC} $1" -} - -# Function to get current config value safely -get_current_config() { - local key="$1" - if [ -f "${WC_HOME}/config.yaml" ]; then - set +e - result=$(wild-config "${key}" 2>/dev/null) - set -e - echo "${result}" - else - echo "" - fi -} +# Initialize Wild-Cloud environment +init_wild_env # Usage function usage() { diff --git a/bin/wild-cluster-node-image-create b/bin/wild-cluster-node-image-create index dffdf24..b820366 100755 --- a/bin/wild-cluster-node-image-create +++ b/bin/wild-cluster-node-image-create @@ -1,100 +1,13 @@ -#!/bin/bash +#\!/bin/bash set -e set -o pipefail -# Get WC_ROOT (where this script and templates live) -WC_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -export WC_ROOT +# Source common utilities +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh" -# Set up cloud directory (WC_HOME is where user's cloud will be) -WC_HOME="$(pwd)" -export WC_HOME - -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -BLUE='\033[0;34m' -NC='\033[0m' # No Color - -# Helper functions -print_header() { - echo -e "\n${BLUE}=== $1 ===${NC}\n" -} - -print_info() { - echo -e "${BLUE}INFO:${NC} $1" -} - -print_warning() { - echo -e "${YELLOW}WARNING:${NC} $1" -} - -print_success() { - echo -e "${GREEN}SUCCESS:${NC} $1" -} - -print_error() { - echo -e "${RED}ERROR:${NC} $1" -} - -# Function to prompt for input with default value -prompt_with_default() { - local prompt="$1" - 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 - if [ -z "${result}" ]; then - result="${current_value}" - fi - elif [ -n "${default}" ]; then - printf "%s [default: %s]: " "${prompt}" "${default}" >&2 - read -r result - if [ -z "${result}" ]; then - result="${default}" - fi - else - printf "%s: " "${prompt}" >&2 - read -r result - while [ -z "${result}" ]; do - printf "This value is required. Please enter a value: " >&2 - read -r result - done - fi - - echo "${result}" -} - -# Function to get current config value safely -get_current_config() { - local key="$1" - if [ -f "${WC_HOME}/config.yaml" ]; then - set +e - result=$(wild-config "${key}" 2>/dev/null) - set -e - echo "${result}" - else - echo "" - fi -} - -# Function to get current secret value safely -get_current_secret() { - local key="$1" - if [ -f "${WC_HOME}/secrets.yaml" ]; then - set +e - result=$(wild-secret "${key}" 2>/dev/null) - set -e - echo "${result}" - else - echo "" - fi -} +# Initialize Wild-Cloud environment +init_wild_env # Usage function usage() { @@ -187,7 +100,7 @@ if [ -z "$(get_current_config "cluster.nodes.talos.version")" ] || [ -z "$(get_c print_header "Kubernetes Cluster Configuration" current_talos_version=$(get_current_config "cluster.nodes.talos.version") - talos_version=$(prompt_with_default "Talos version" "v1.6.1" "${current_talos_version}") + talos_version=$(prompt_with_default "Talos version" "v1.10.4" "${current_talos_version}") wild-config-set "cluster.nodes.talos.version" "${talos_version}" # Talos schematic ID diff --git a/bin/wild-cluster-node-machine-config-generate b/bin/wild-cluster-node-machine-config-generate index 959064d..5b11fb6 100755 --- a/bin/wild-cluster-node-machine-config-generate +++ b/bin/wild-cluster-node-machine-config-generate @@ -1,56 +1,13 @@ -#!/bin/bash +#\!/bin/bash set -e set -o pipefail -# Get WC_ROOT (where this script and templates live) -WC_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.."; pwd)" -export WC_ROOT +# Source common utilities +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh" -# Set up cloud directory (WC_HOME is where user's cloud will be) -WC_HOME="$(pwd)" -export WC_HOME - -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -BLUE='\033[0;34m' -NC='\033[0m' # No Color - -# Helper functions -print_header() { - echo -e "\n${BLUE}=== $1 ===${NC}\n" -} - -print_info() { - echo -e "${BLUE}INFO:${NC} $1" -} - -print_warning() { - echo -e "${YELLOW}WARNING:${NC} $1" -} - -print_success() { - echo -e "${GREEN}SUCCESS:${NC} $1" -} - -print_error() { - echo -e "${RED}ERROR:${NC} $1" -} - -# Function to get current config value safely -get_current_config() { - local key="$1" - if [ -f "${WC_HOME}/config.yaml" ]; then - set +e - result=$(wild-config "${key}" 2>/dev/null) - set -e - echo "${result}" - else - echo "" - fi -} +# Initialize Wild-Cloud environment +init_wild_env # Usage function usage() { diff --git a/bin/wild-cluster-node-up b/bin/wild-cluster-node-up index 7e51d25..1bca18b 100755 --- a/bin/wild-cluster-node-up +++ b/bin/wild-cluster-node-up @@ -3,54 +3,11 @@ set -e set -o pipefail -# Get WC_ROOT (where this script and templates live) -WC_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -export WC_ROOT +# Source common utilities +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh" -# Set up cloud directory (WC_HOME is where user's cloud will be) -WC_HOME="$(pwd)" -export WC_HOME - -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -BLUE='\033[0;34m' -NC='\033[0m' # No Color - -# Helper functions -print_header() { - echo -e "\n${BLUE}=== $1 ===${NC}\n" -} - -print_info() { - echo -e "${BLUE}INFO:${NC} $1" -} - -print_warning() { - echo -e "${YELLOW}WARNING:${NC} $1" -} - -print_success() { - echo -e "${GREEN}SUCCESS:${NC} $1" -} - -print_error() { - echo -e "${RED}ERROR:${NC} $1" -} - -# Function to get current config value safely -get_current_config() { - local key="$1" - if [ -f "${WC_HOME}/config.yaml" ]; then - set +e - result=$(wild-config "${key}" 2>/dev/null) - set -e - echo "${result}" - else - echo "" - fi -} +# Initialize Wild-Cloud environment +init_wild_env # Usage function usage() { @@ -128,13 +85,9 @@ if [ -z "$NODE_IP" ]; then fi # Check if we're in a wild-cloud directory -if [ ! -d ".wildcloud" ]; then - print_error "You must run this script from a wild-cloud directory" - print_info "Run 'wild-setup' or 'wild-init' first to initialize a wild-cloud project" - exit 1 -fi +check_wild_directory -# Check required configuration +# Check required configuration if [ -z "$(get_current_config "cluster.name")" ]; then print_error "Basic cluster configuration is missing" print_info "Run 'wild-setup' or 'wild-init' first to configure your cluster" @@ -147,6 +100,7 @@ print_header "Talos Node Configuration Application" NODE_INTERFACE=$(yq eval ".cluster.nodes.active.\"${NODE_IP}\".interface" "${WC_HOME}/config.yaml" 2>/dev/null) NODE_DISK=$(yq eval ".cluster.nodes.active.\"${NODE_IP}\".disk" "${WC_HOME}/config.yaml" 2>/dev/null) IS_CONTROL=$(yq eval ".cluster.nodes.active.\"${NODE_IP}\".control" "${WC_HOME}/config.yaml" 2>/dev/null) +MAINTENANCE_IP=$(yq eval ".cluster.nodes.active.\"${NODE_IP}\".maintenanceIp" "${WC_HOME}/config.yaml" 2>/dev/null) if [ -z "$NODE_INTERFACE" ] || [ "$NODE_INTERFACE" = "null" ]; then print_error "Node $NODE_IP is not registered in config.yaml" @@ -163,11 +117,27 @@ else NODE_TYPE="worker" fi -print_info "Applying configuration to $NODE_TYPE node: $NODE_IP" +# Determine the target IP for applying configuration +if [ -n "$MAINTENANCE_IP" ] && [ "$MAINTENANCE_IP" != "null" ]; then + TARGET_IP="$MAINTENANCE_IP" + print_info "Applying configuration to $NODE_TYPE node: $NODE_IP (via maintenance IP: $MAINTENANCE_IP)" + # Auto-enable insecure mode when using maintenance IP (unless explicitly overridden) + if [ "$INSECURE_MODE" = false ]; then + INSECURE_MODE=true + print_info "Auto-enabling insecure mode for maintenance IP" + fi +else + TARGET_IP="$NODE_IP" + print_info "Applying configuration to $NODE_TYPE node: $NODE_IP" +fi + print_info "Node details:" print_info " - Interface: $NODE_INTERFACE" print_info " - Disk: $NODE_DISK" print_info " - Type: $NODE_TYPE" +if [ -n "$MAINTENANCE_IP" ] && [ "$MAINTENANCE_IP" != "null" ]; then + print_info " - Maintenance IP: $MAINTENANCE_IP" +fi # Check if machine config exists NODE_SETUP_DIR="${WC_HOME}/setup/cluster-nodes" @@ -190,7 +160,7 @@ if [ "$INSECURE_MODE" = true ]; then print_info "Using insecure mode (for maintenance mode nodes)" fi -TALOSCTL_CMD="$TALOSCTL_CMD --nodes $NODE_IP --file $CONFIG_FILE" +TALOSCTL_CMD="$TALOSCTL_CMD --nodes $TARGET_IP --file $CONFIG_FILE" # Show the command echo "" @@ -235,7 +205,11 @@ else print_error "Failed to apply machine configuration" echo "" print_info "Troubleshooting tips:" - echo " - Ensure the node is accessible at $NODE_IP" + if [ -n "$MAINTENANCE_IP" ] && [ "$MAINTENANCE_IP" != "null" ]; then + echo " - Ensure the node is accessible at maintenance IP $MAINTENANCE_IP" + else + echo " - Ensure the node is accessible at $NODE_IP" + fi echo " - For nodes in maintenance mode, use --insecure flag" echo " - Check network connectivity and firewall settings" echo " - Verify the machine configuration file is valid" diff --git a/bin/wild-cluster-services-generate b/bin/wild-cluster-services-generate index cb8a09f..24c66a3 100755 --- a/bin/wild-cluster-services-generate +++ b/bin/wild-cluster-services-generate @@ -1,43 +1,14 @@ -#!/bin/bash +#\!/bin/bash set -e set -o pipefail -# Get WC_ROOT (where this script and templates live) -WC_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.."; pwd)" -export WC_ROOT +# Source common utilities +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh" -# Set up cloud directory (WC_HOME is where user's cloud will be) -WC_HOME="$(pwd)" -export WC_HOME +# Initialize Wild-Cloud environment +init_wild_env -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -BLUE='\033[0;34m' -NC='\033[0m' # No Color - -# Helper functions -print_header() { - echo -e "\n${BLUE}=== $1 ===${NC}\n" -} - -print_info() { - echo -e "${BLUE}INFO:${NC} $1" -} - -print_warning() { - echo -e "${YELLOW}WARNING:${NC} $1" -} - -print_success() { - echo -e "${GREEN}SUCCESS:${NC} $1" -} - -print_error() { - echo -e "${RED}ERROR:${NC} $1" -} # Usage function usage() { diff --git a/bin/wild-cluster-services-up b/bin/wild-cluster-services-up index c87e985..c51e5d8 100755 --- a/bin/wild-cluster-services-up +++ b/bin/wild-cluster-services-up @@ -1,43 +1,14 @@ -#!/bin/bash +#\!/bin/bash set -e set -o pipefail -# Get WC_ROOT (where this script and templates live) -WC_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.."; pwd)" -export WC_ROOT +# Source common utilities +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh" -# Set up cloud directory (WC_HOME is where user's cloud will be) -WC_HOME="$(pwd)" -export WC_HOME +# Initialize Wild-Cloud environment +init_wild_env -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -BLUE='\033[0;34m' -NC='\033[0m' # No Color - -# Helper functions -print_header() { - echo -e "\n${BLUE}=== $1 ===${NC}\n" -} - -print_info() { - echo -e "${BLUE}INFO:${NC} $1" -} - -print_warning() { - echo -e "${YELLOW}WARNING:${NC} $1" -} - -print_success() { - echo -e "${GREEN}SUCCESS:${NC} $1" -} - -print_error() { - echo -e "${RED}ERROR:${NC} $1" -} # Usage function usage() { diff --git a/bin/wild-common.sh b/bin/wild-common.sh new file mode 100644 index 0000000..cfee2d8 --- /dev/null +++ b/bin/wild-common.sh @@ -0,0 +1,227 @@ +#!/bin/bash + +# wild-common.sh +# Common utility functions for Wild-Cloud shell scripts +# Source this file at the beginning of scripts to access shared functionality +# +# USAGE PATTERN: +# Replace the common function definitions in your script with: +# +# #!/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: get_current_config, get_current_secret, prompt_with_default +# - Validation: check_wild_directory, check_basic_config +# - Utilities: command_exists, file_readable, dir_writable, generate_random_string + +# ============================================================================= +# COLOR VARIABLES +# ============================================================================= + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# ============================================================================= +# PRINT FUNCTIONS +# ============================================================================= + +# Print functions for consistent output formatting +print_header() { + echo -e "\n${BLUE}=== $1 ===${NC}\n" +} + +print_info() { + echo -e "${BLUE}INFO:${NC} $1" +} + +print_warning() { + echo -e "${YELLOW}WARNING:${NC} $1" +} + +print_success() { + echo -e "${GREEN}SUCCESS:${NC} $1" +} + +print_error() { + echo -e "${RED}ERROR:${NC} $1" +} + +# ============================================================================= +# CONFIGURATION UTILITIES +# ============================================================================= + +# Function to get current config value safely +get_current_config() { + local key="$1" + if [ -f "${WC_HOME}/config.yaml" ]; then + set +e + result=$(wild-config "${key}" 2>/dev/null) + set -e + echo "${result}" + else + echo "" + fi +} + +# Function to get current secret value safely +get_current_secret() { + local key="$1" + if [ -f "${WC_HOME}/secrets.yaml" ]; then + set +e + result=$(wild-secret "${key}" 2>/dev/null) + set -e + echo "${result}" + else + echo "" + fi +} + +# Function to prompt for input with default value +prompt_with_default() { + local prompt="$1" + 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 + if [ -z "${result}" ]; then + result="${current_value}" + fi + elif [ -n "${default}" ]; then + printf "%s [default: %s]: " "${prompt}" "${default}" >&2 + read -r result + if [ -z "${result}" ]; then + result="${default}" + fi + else + printf "%s: " "${prompt}" >&2 + read -r result + while [ -z "${result}" ]; do + printf "This value is required. Please enter a value: " >&2 + read -r result + done + fi + + echo "${result}" +} + +# ============================================================================= +# ENVIRONMENT SETUP +# ============================================================================= + +# Find the wild-cloud project home directory by searching for .wildcloud +# 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" + return 0 + fi + current_dir="$(dirname "$current_dir")" + done + + # Not found + return 1 +} + +# Initialize common Wild-Cloud environment variables +# Call this function at the beginning of scripts +init_wild_env() { + # Get WC_ROOT (where this script and templates live) + if [ -z "${WC_ROOT}" ]; then + WC_ROOT="$(cd "$(dirname "${BASH_SOURCE[1]}")/.." && pwd)" + export WC_ROOT + fi + + # Set up cloud directory (WC_HOME is where user's cloud is) + # Look for .wildcloud directory in current path or ancestors + if [ -z "${WC_HOME}" ]; then + local found_home + if found_home="$(find_wc_home)"; then + WC_HOME="$found_home" + export WC_HOME + else + # If no .wildcloud directory found, default to current directory + WC_HOME="$(pwd)" + export WC_HOME + fi + fi +} + +# ============================================================================= +# VALIDATION FUNCTIONS +# ============================================================================= + +# Check if we're in a wild-cloud directory +check_wild_directory() { + local found_home + if found_home="$(find_wc_home)"; then + # Update WC_HOME if it's not set correctly + if [ -z "${WC_HOME}" ] || [ "${WC_HOME}" != "$found_home" ]; then + WC_HOME="$found_home" + export WC_HOME + fi + else + print_error "No wild-cloud project found in current directory or ancestors" + print_info "Run 'wild-setup-scaffold' first to initialize a wild-cloud project" + print_info "Current working directory: $(pwd)" + local search_path="$(pwd)" + while [ "$search_path" != "/" ]; do + print_info " Searched: $search_path" + search_path="$(dirname "$search_path")" + done + exit 1 + fi +} + +# Check if basic configuration exists +check_basic_config() { + if [ -z "$(get_current_config "operator.email")" ]; then + print_error "Basic configuration is missing" + print_info "Run 'wild-setup-scaffold' first to configure basic settings" + exit 1 + fi +} + +# ============================================================================= +# UTILITY FUNCTIONS +# ============================================================================= + +# Check if a command exists +command_exists() { + command -v "$1" >/dev/null 2>&1 +} + +# Check if a file exists and is readable +file_readable() { + [ -f "$1" ] && [ -r "$1" ] +} + +# Check if a directory exists and is writable +dir_writable() { + [ -d "$1" ] && [ -w "$1" ] +} + +# Generate a random string of specified length +generate_random_string() { + local length="${1:-32}" + openssl rand -hex "$((length / 2))" 2>/dev/null || \ + head -c "$length" /dev/urandom | base64 | tr -d '=+/' | cut -c1-"$length" +} \ No newline at end of file diff --git a/bin/wild-setup b/bin/wild-setup index 31affc6..31ed8b7 100755 --- a/bin/wild-setup +++ b/bin/wild-setup @@ -3,41 +3,11 @@ set -e set -o pipefail -# Get WC_ROOT (where this script and templates live) -WC_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -export WC_ROOT +# Source common utilities +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh" -# ============================================================================= -# HELPER FUNCTIONS -# ============================================================================= - -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -BLUE='\033[0;34m' -NC='\033[0m' # No Color - -# Helper functions -print_header() { - echo -e "\n${BLUE}=== $1 ===${NC}\n" -} - -print_info() { - echo -e "${BLUE}INFO:${NC} $1" -} - -print_warning() { - echo -e "${YELLOW}WARNING:${NC} $1" -} - -print_success() { - echo -e "${GREEN}SUCCESS:${NC} $1" -} - -print_error() { - echo -e "${RED}ERROR:${NC} $1" -} +# Initialize Wild-Cloud environment +init_wild_env # Phase tracking variables SKIP_SCAFFOLD=false diff --git a/bin/wild-setup-cluster b/bin/wild-setup-cluster index 1d5d27f..d4795f7 100755 --- a/bin/wild-setup-cluster +++ b/bin/wild-setup-cluster @@ -3,102 +3,11 @@ set -e set -o pipefail -# Get WC_ROOT (where this script and templates live) -WC_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -export WC_ROOT +# Source common utilities +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh" -# Set up cloud directory (WC_HOME is where user's cloud will be) -WC_HOME="$(pwd)" -export WC_HOME - -# ============================================================================= -# HELPER FUNCTIONS -# ============================================================================= - -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -BLUE='\033[0;34m' -NC='\033[0m' # No Color - -# Helper functions -print_header() { - echo -e "\n${BLUE}=== $1 ===${NC}\n" -} - -print_info() { - echo -e "${BLUE}INFO:${NC} $1" -} - -print_warning() { - echo -e "${YELLOW}WARNING:${NC} $1" -} - -print_success() { - echo -e "${GREEN}SUCCESS:${NC} $1" -} - -print_error() { - echo -e "${RED}ERROR:${NC} $1" -} - -# Function to prompt for input with default value -prompt_with_default() { - local prompt="$1" - 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 - if [ -z "${result}" ]; then - result="${current_value}" - fi - elif [ -n "${default}" ]; then - printf "%s [default: %s]: " "${prompt}" "${default}" >&2 - read -r result - if [ -z "${result}" ]; then - result="${default}" - fi - else - printf "%s: " "${prompt}" >&2 - read -r result - while [ -z "${result}" ]; do - printf "This value is required. Please enter a value: " >&2 - read -r result - done - fi - - echo "${result}" -} - -# Function to get current config value safely -get_current_config() { - local key="$1" - if [ -f "${WC_HOME}/config.yaml" ]; then - set +e - result=$(wild-config "${key}" 2>/dev/null) - set -e - echo "${result}" - else - echo "" - fi -} - -# Function to get current secret value safely -get_current_secret() { - local key="$1" - if [ -f "${WC_HOME}/secrets.yaml" ]; then - set +e - result=$(wild-secret "${key}" 2>/dev/null) - set -e - echo "${result}" - else - echo "" - fi -} +# Initialize Wild-Cloud environment +init_wild_env # Phase tracking variables SKIP_INSTALLER=false @@ -125,17 +34,12 @@ while [[ $# -gt 0 ]]; do echo "" echo "Set up Kubernetes cluster infrastructure (Phases 1-3)." echo "" - echo "Phase Control Options:" - echo " --skip-installer Skip Phase 1 (Installer image generation)" - echo " --skip-hardware Skip Phase 2 (Node hardware detection)" - echo " --skip-configs Skip Phase 3 (Machine config generation)" + echo "Control Options:" + echo " --skip-installer Skip Installer image generation" + echo " --skip-hardware Skip Node hardware detection" + echo " --skip-configs Skip Machine config generation" echo " -h, --help Show this help message" echo "" - echo "Phases:" - echo " 1. Installer image - Generate custom Talos installer URLs" - echo " 2. Hardware detection - Discover node interfaces and disks" - echo " 3. Machine configs - Generate Talos machine configurations" - echo "" echo "Prerequisites:" echo " - Run 'wild-setup-scaffold' first to initialize the cloud" echo "" @@ -159,45 +63,37 @@ while [[ $# -gt 0 ]]; do done # Check if we're in a wild-cloud directory -if [ ! -d ".wildcloud" ]; then - print_error "You must run this script from a wild-cloud directory" - print_info "Run 'wild-setup-scaffold' first to initialize a wild-cloud project" - exit 1 -fi +check_wild_directory # Check basic configuration -if [ -z "$(get_current_config "operator.email")" ]; then - print_error "Basic configuration is missing" - print_info "Run 'wild-setup-scaffold' first to configure basic settings" - exit 1 -fi +check_basic_config print_header "Wild-Cloud Cluster Setup" -print_info "Setting up Kubernetes cluster infrastructure (Phases 1-3)" +print_info "Setting up cluster infrastructure" echo "" # ============================================================================= -# PHASE 1: Talos asset download +# Talos asset download # ============================================================================= if [ "${SKIP_INSTALLER}" = false ]; then - print_header "Phase 1: Installer Image Generation" + print_header "Installer Image Generation" print_info "Running wild-cluster-node-image-create..." wild-cluster-node-image-create - print_success "Phase 1 completed: Installer image generated" + print_success "Installer image generated" echo "" else - print_info "Skipping Phase 1: Installer Image Generation" + print_info "Skipping: Installer Image Generation" fi # ============================================================================= -# PHASE 2: Node Hardware Detection +# Node Hardware Detection # ============================================================================= if [ "${SKIP_HARDWARE}" = false ]; then - print_header "Phase 2: Node Hardware Detection" + print_header "Node Hardware Detection" # Configure network settings if [ -z "$(get_current_config "cloud.router.ip")" ]; then @@ -335,10 +231,10 @@ if [ "${SKIP_HARDWARE}" = false ]; then echo "" fi - # Generate initial cluster configuration - print_header "Cluster Configuration Generation" - print_info "Generating base cluster configuration with talosctl gen config..." - wild-cluster-config-generate + # # Generate initial cluster configuration + # print_header "Cluster Configuration Generation" + # print_info "Generating base cluster configuration with talosctl gen config..." + # wild-cluster-config-generate # Detect and register control plane nodes print_header "Control Plane Node Registration" @@ -366,7 +262,7 @@ if [ "${SKIP_HARDWARE}" = false ]; then print_info " - Interface: $existing_interface" print_info " - Disk: $(get_current_config "cluster.nodes.active.\"${TARGET_IP}\".disk")" - # Still generate machine config if it doesn't exist + # Generate machine config for this node if necessary. NODE_SETUP_DIR="${WC_HOME}/setup/cluster-nodes" CONFIG_FILE="${NODE_SETUP_DIR}/final/${TARGET_IP}.yaml" if [ ! -f "$CONFIG_FILE" ]; then @@ -388,7 +284,8 @@ if [ "${SKIP_HARDWARE}" = false ]; then continue fi - # First try to detect at target IP + # Register node in config.yaml. + # First try to detect at target IP. print_info "Attempting detection at target IP $TARGET_IP..." DETECTION_IP="$TARGET_IP" NODE_INFO="" @@ -446,7 +343,7 @@ if [ "${SKIP_HARDWARE}" = false ]; then print_info "Selected disk: $SELECTED_DISK" fi - # Update config.yaml with hardware info + # Update config.yaml with hardware info. print_info "Updating configuration for $TARGET_IP..." wild-config-set "cluster.nodes.active.\"${TARGET_IP}\".interface" "$INTERFACE" wild-config-set "cluster.nodes.active.\"${TARGET_IP}\".disk" "$SELECTED_DISK" @@ -454,7 +351,7 @@ if [ "${SKIP_HARDWARE}" = false ]; then print_success "Node $TARGET_IP registered successfully" - # Generate machine config immediately + # Generate machine config. print_info "Generating machine configuration for $TARGET_IP..." if wild-cluster-node-machine-config-generate "$TARGET_IP"; then print_success "Machine configuration generated for $TARGET_IP" @@ -581,98 +478,10 @@ if [ "${SKIP_HARDWARE}" = false ]; then fi done - print_success "Phase 2 completed: Node hardware detection" + print_success "Completed Node hardware detection" echo "" else - print_info "Skipping Phase 2: Node Hardware Detection" -fi - -# ============================================================================= -# PHASE 3: Machine Config Summary and Verification -# ============================================================================= - -if [ "${SKIP_CONFIGS}" = false ]; then - print_header "Phase 3: Machine Config Summary and Verification" - - # Get all registered nodes from cluster.nodes.active - REGISTERED_NODES=() - CONTROL_NODES=() - WORKER_NODES=() - - if yq eval '.cluster.nodes.active // {}' "${WC_HOME}/config.yaml" | grep -q "interface"; then - ALL_NODE_IPS=$(yq eval '.cluster.nodes.active | keys | .[]' "${WC_HOME}/config.yaml" 2>/dev/null || echo "") - - for NODE_IP in $ALL_NODE_IPS; do - # Remove quotes from yq output - NODE_IP=$(echo "$NODE_IP" | tr -d '"') - REGISTERED_NODES+=("$NODE_IP") - - # Check if it's a control node - IS_CONTROL=$(yq eval ".cluster.nodes.active.\"${NODE_IP}\".control" "${WC_HOME}/config.yaml" 2>/dev/null) - if [ "$IS_CONTROL" = "true" ]; then - CONTROL_NODES+=("$NODE_IP") - else - WORKER_NODES+=("$NODE_IP") - fi - done - fi - - if [ ${#REGISTERED_NODES[@]} -eq 0 ]; then - print_warning "No nodes have been registered yet." - print_info "Run Phase 2 (Hardware Detection) first to register nodes" - else - print_success "Machine configuration summary:" - echo "" - print_info "Registered nodes: ${#REGISTERED_NODES[@]}" - print_info " Control plane nodes: ${#CONTROL_NODES[@]}" - print_info " Worker nodes: ${#WORKER_NODES[@]}" - echo "" - - # Check for any nodes that might need machine config generation - MISSING_CONFIGS=() - NODE_SETUP_DIR="${WC_HOME}/setup/cluster-nodes" - - if [ -d "$NODE_SETUP_DIR/final" ]; then - for NODE_IP in "${REGISTERED_NODES[@]}"; do - CONFIG_FILE="$NODE_SETUP_DIR/final/${NODE_IP}.yaml" - - if [ ! -f "$CONFIG_FILE" ]; then - MISSING_CONFIGS+=("$NODE_IP") - fi - done - else - MISSING_CONFIGS=("${REGISTERED_NODES[@]}") - fi - - if [ ${#MISSING_CONFIGS[@]} -gt 0 ]; then - print_warning "Some nodes are missing machine configurations:" - for NODE_IP in "${MISSING_CONFIGS[@]}"; do - print_info "Generating missing config for $NODE_IP..." - wild-cluster-node-machine-config-generate "$NODE_IP" - done - else - print_success "All registered nodes have machine configurations" - fi - - echo "" - print_info "Machine configuration files:" - for NODE_IP in "${REGISTERED_NODES[@]}"; do - CONFIG_FILE="$NODE_SETUP_DIR/final/${NODE_IP}.yaml" - if [ -f "$CONFIG_FILE" ]; then - NODE_TYPE=$(yq eval ".cluster.nodes.active.\"${NODE_IP}\".control" "${WC_HOME}/config.yaml" 2>/dev/null) - if [ "$NODE_TYPE" = "true" ]; then - print_success " ✓ $CONFIG_FILE (control plane)" - else - print_success " ✓ $CONFIG_FILE (worker)" - fi - fi - done - fi - - print_success "Phase 3 completed: Machine config summary and verification" - echo "" -else - print_info "Skipping Phase 3: Machine Config Summary and Verification" + print_info "Skipping Node Hardware Detection" fi # ============================================================================= @@ -683,46 +492,3 @@ print_header "Wild-Cloud Cluster Setup Complete!" print_success "Cluster infrastructure setup completed!" echo "" - -print_info "What was accomplished:" -if [ "${SKIP_INSTALLER}" = false ]; then - print_info "✅ Phase 1: Installer image generated" -else - print_info "⏸️ Phase 1: Installer image generation (skipped)" -fi - -if [ "${SKIP_HARDWARE}" = false ]; then - print_info "✅ Phase 2: Node hardware detection completed" -else - print_info "⏸️ Phase 2: Node hardware detection (skipped)" -fi - -if [ "${SKIP_CONFIGS}" = false ]; then - print_info "✅ Phase 3: Machine configs generated" -else - print_info "⏸️ Phase 3: Machine config generation (skipped)" -fi - -echo "" -print_info "Configuration files:" -echo " - ${WC_HOME}/config.yaml" -echo " - ${WC_HOME}/secrets.yaml" - -if [ -d "${WC_HOME}/setup/cluster-nodes/final" ] && [ "$(ls -A ${WC_HOME}/setup/cluster-nodes/final 2>/dev/null)" ]; then - echo "" - print_info "Machine configurations:" - for config_file in "${WC_HOME}/setup/cluster-nodes/final"/*.yaml; do - if [ -f "$config_file" ]; then - echo " - $config_file" - fi - done -fi - -echo "" -print_info "Next steps:" -echo " 1. Apply machine configurations to your nodes" -echo " 2. Bootstrap your cluster and verify it's running" -echo " 3. Install cluster services:" -echo " wild-setup-services" - -print_success "Ready for cluster services installation!" \ No newline at end of file diff --git a/bin/wild-setup-scaffold b/bin/wild-setup-scaffold index e705578..12aaa9d 100755 --- a/bin/wild-setup-scaffold +++ b/bin/wild-setup-scaffold @@ -3,98 +3,11 @@ set -e set -o pipefail -# Get WC_ROOT (where this script and templates live) -WC_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -export WC_ROOT +# Source common utilities +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh" -# ============================================================================= -# HELPER FUNCTIONS -# ============================================================================= - -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -BLUE='\033[0;34m' -NC='\033[0m' # No Color - -# Helper functions -print_header() { - echo -e "\n${BLUE}=== $1 ===${NC}\n" -} - -print_info() { - echo -e "${BLUE}INFO:${NC} $1" -} - -print_warning() { - echo -e "${YELLOW}WARNING:${NC} $1" -} - -print_success() { - echo -e "${GREEN}SUCCESS:${NC} $1" -} - -print_error() { - echo -e "${RED}ERROR:${NC} $1" -} - -# Function to prompt for input with default value -prompt_with_default() { - local prompt="$1" - 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 - if [ -z "${result}" ]; then - result="${current_value}" - fi - elif [ -n "${default}" ]; then - printf "%s [default: %s]: " "${prompt}" "${default}" >&2 - read -r result - if [ -z "${result}" ]; then - result="${default}" - fi - else - printf "%s: " "${prompt}" >&2 - read -r result - while [ -z "${result}" ]; do - printf "This value is required. Please enter a value: " >&2 - read -r result - done - fi - - echo "${result}" -} - -# Function to get current config value safely -get_current_config() { - local key="$1" - if [ -f "${WC_HOME}/config.yaml" ]; then - set +e - result=$(wild-config "${key}" 2>/dev/null) - set -e - echo "${result}" - else - echo "" - fi -} - -# Function to get current secret value safely -get_current_secret() { - local key="$1" - if [ -f "${WC_HOME}/secrets.yaml" ]; then - set +e - result=$(wild-secret "${key}" 2>/dev/null) - set -e - echo "${result}" - else - echo "" - fi -} +# Initialize Wild-Cloud environment +init_wild_env UPDATE=false diff --git a/bin/wild-setup-services b/bin/wild-setup-services index 92c4753..15376c6 100755 --- a/bin/wild-setup-services +++ b/bin/wild-setup-services @@ -3,102 +3,11 @@ set -e set -o pipefail -# Get WC_ROOT (where this script and templates live) -WC_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -export WC_ROOT +# Source common utilities +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh" -# Set up cloud directory (WC_HOME is where user's cloud will be) -WC_HOME="$(pwd)" -export WC_HOME - -# ============================================================================= -# HELPER FUNCTIONS -# ============================================================================= - -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -BLUE='\033[0;34m' -NC='\033[0m' # No Color - -# Helper functions -print_header() { - echo -e "\n${BLUE}=== $1 ===${NC}\n" -} - -print_info() { - echo -e "${BLUE}INFO:${NC} $1" -} - -print_warning() { - echo -e "${YELLOW}WARNING:${NC} $1" -} - -print_success() { - echo -e "${GREEN}SUCCESS:${NC} $1" -} - -print_error() { - echo -e "${RED}ERROR:${NC} $1" -} - -# Function to prompt for input with default value -prompt_with_default() { - local prompt="$1" - 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 - if [ -z "${result}" ]; then - result="${current_value}" - fi - elif [ -n "${default}" ]; then - printf "%s [default: %s]: " "${prompt}" "${default}" >&2 - read -r result - if [ -z "${result}" ]; then - result="${default}" - fi - else - printf "%s: " "${prompt}" >&2 - read -r result - while [ -z "${result}" ]; do - printf "This value is required. Please enter a value: " >&2 - read -r result - done - fi - - echo "${result}" -} - -# Function to get current config value safely -get_current_config() { - local key="$1" - if [ -f "${WC_HOME}/config.yaml" ]; then - set +e - result=$(wild-config "${key}" 2>/dev/null) - set -e - echo "${result}" - else - echo "" - fi -} - -# Function to get current secret value safely -get_current_secret() { - local key="$1" - if [ -f "${WC_HOME}/secrets.yaml" ]; then - set +e - result=$(wild-secret "${key}" 2>/dev/null) - set -e - echo "${result}" - else - echo "" - fi -} +# Initialize Wild-Cloud environment +init_wild_env # Parse arguments SKIP_INSTALL=false @@ -146,18 +55,10 @@ while [[ $# -gt 0 ]]; do done # Check if we're in a wild-cloud directory -if [ ! -d ".wildcloud" ]; then - print_error "You must run this script from a wild-cloud directory" - print_info "Run 'wild-setup-scaffold' first to initialize a wild-cloud project" - exit 1 -fi +check_wild_directory # Check basic configuration -if [ -z "$(get_current_config "operator.email")" ]; then - print_error "Basic configuration is missing" - print_info "Run 'wild-setup-scaffold' first to configure basic settings" - exit 1 -fi +check_basic_config # Check cluster configuration if [ -z "$(get_current_config "cluster.name")" ]; then