Extracts common library from wild scripts.

This commit is contained in:
2025-06-28 08:18:11 -07:00
parent 0399bd54cf
commit bcccb150e3
11 changed files with 324 additions and 804 deletions

View File

@@ -3,54 +3,11 @@
set -e set -e
set -o pipefail set -o pipefail
# Get WC_ROOT (where this script and templates live) # Source common utilities
WC_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.."; pwd)" source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh"
export WC_ROOT
# Set up cloud directory (WC_HOME is where user's cloud will be) # Initialize Wild-Cloud environment
WC_HOME="$(pwd)" init_wild_env
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
}
# Usage function # Usage function
usage() { usage() {

View File

@@ -1,100 +1,13 @@
#!/bin/bash #\!/bin/bash
set -e set -e
set -o pipefail set -o pipefail
# Get WC_ROOT (where this script and templates live) # Source common utilities
WC_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh"
export WC_ROOT
# Set up cloud directory (WC_HOME is where user's cloud will be) # Initialize Wild-Cloud environment
WC_HOME="$(pwd)" init_wild_env
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
}
# Usage function # Usage function
usage() { usage() {
@@ -187,7 +100,7 @@ if [ -z "$(get_current_config "cluster.nodes.talos.version")" ] || [ -z "$(get_c
print_header "Kubernetes Cluster Configuration" print_header "Kubernetes Cluster Configuration"
current_talos_version=$(get_current_config "cluster.nodes.talos.version") 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}" wild-config-set "cluster.nodes.talos.version" "${talos_version}"
# Talos schematic ID # Talos schematic ID

View File

@@ -1,56 +1,13 @@
#!/bin/bash #\!/bin/bash
set -e set -e
set -o pipefail set -o pipefail
# Get WC_ROOT (where this script and templates live) # Source common utilities
WC_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.."; pwd)" source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh"
export WC_ROOT
# Set up cloud directory (WC_HOME is where user's cloud will be) # Initialize Wild-Cloud environment
WC_HOME="$(pwd)" init_wild_env
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
}
# Usage function # Usage function
usage() { usage() {

View File

@@ -3,54 +3,11 @@
set -e set -e
set -o pipefail set -o pipefail
# Get WC_ROOT (where this script and templates live) # Source common utilities
WC_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh"
export WC_ROOT
# Set up cloud directory (WC_HOME is where user's cloud will be) # Initialize Wild-Cloud environment
WC_HOME="$(pwd)" init_wild_env
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
}
# Usage function # Usage function
usage() { usage() {
@@ -128,13 +85,9 @@ if [ -z "$NODE_IP" ]; then
fi fi
# Check if we're in a wild-cloud directory # Check if we're in a wild-cloud directory
if [ ! -d ".wildcloud" ]; then check_wild_directory
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 required configuration # Check required configuration
if [ -z "$(get_current_config "cluster.name")" ]; then if [ -z "$(get_current_config "cluster.name")" ]; then
print_error "Basic cluster configuration is missing" print_error "Basic cluster configuration is missing"
print_info "Run 'wild-setup' or 'wild-init' first to configure your cluster" 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_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) 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) 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 if [ -z "$NODE_INTERFACE" ] || [ "$NODE_INTERFACE" = "null" ]; then
print_error "Node $NODE_IP is not registered in config.yaml" print_error "Node $NODE_IP is not registered in config.yaml"
@@ -163,11 +117,27 @@ else
NODE_TYPE="worker" NODE_TYPE="worker"
fi 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 "Node details:"
print_info " - Interface: $NODE_INTERFACE" print_info " - Interface: $NODE_INTERFACE"
print_info " - Disk: $NODE_DISK" print_info " - Disk: $NODE_DISK"
print_info " - Type: $NODE_TYPE" 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 # Check if machine config exists
NODE_SETUP_DIR="${WC_HOME}/setup/cluster-nodes" 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)" print_info "Using insecure mode (for maintenance mode nodes)"
fi fi
TALOSCTL_CMD="$TALOSCTL_CMD --nodes $NODE_IP --file $CONFIG_FILE" TALOSCTL_CMD="$TALOSCTL_CMD --nodes $TARGET_IP --file $CONFIG_FILE"
# Show the command # Show the command
echo "" echo ""
@@ -235,7 +205,11 @@ else
print_error "Failed to apply machine configuration" print_error "Failed to apply machine configuration"
echo "" echo ""
print_info "Troubleshooting tips:" 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 " - For nodes in maintenance mode, use --insecure flag"
echo " - Check network connectivity and firewall settings" echo " - Check network connectivity and firewall settings"
echo " - Verify the machine configuration file is valid" echo " - Verify the machine configuration file is valid"

View File

@@ -1,43 +1,14 @@
#!/bin/bash #\!/bin/bash
set -e set -e
set -o pipefail set -o pipefail
# Get WC_ROOT (where this script and templates live) # Source common utilities
WC_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.."; pwd)" source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh"
export WC_ROOT
# Set up cloud directory (WC_HOME is where user's cloud will be) # Initialize Wild-Cloud environment
WC_HOME="$(pwd)" init_wild_env
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"
}
# Usage function # Usage function
usage() { usage() {

View File

@@ -1,43 +1,14 @@
#!/bin/bash #\!/bin/bash
set -e set -e
set -o pipefail set -o pipefail
# Get WC_ROOT (where this script and templates live) # Source common utilities
WC_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.."; pwd)" source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh"
export WC_ROOT
# Set up cloud directory (WC_HOME is where user's cloud will be) # Initialize Wild-Cloud environment
WC_HOME="$(pwd)" init_wild_env
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"
}
# Usage function # Usage function
usage() { usage() {

227
bin/wild-common.sh Normal file
View File

@@ -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"
}

View File

@@ -3,41 +3,11 @@
set -e set -e
set -o pipefail set -o pipefail
# Get WC_ROOT (where this script and templates live) # Source common utilities
WC_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh"
export WC_ROOT
# ============================================================================= # Initialize Wild-Cloud environment
# HELPER FUNCTIONS 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"
}
# Phase tracking variables # Phase tracking variables
SKIP_SCAFFOLD=false SKIP_SCAFFOLD=false

View File

@@ -3,102 +3,11 @@
set -e set -e
set -o pipefail set -o pipefail
# Get WC_ROOT (where this script and templates live) # Source common utilities
WC_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh"
export WC_ROOT
# Set up cloud directory (WC_HOME is where user's cloud will be) # Initialize Wild-Cloud environment
WC_HOME="$(pwd)" init_wild_env
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
}
# Phase tracking variables # Phase tracking variables
SKIP_INSTALLER=false SKIP_INSTALLER=false
@@ -125,17 +34,12 @@ while [[ $# -gt 0 ]]; do
echo "" echo ""
echo "Set up Kubernetes cluster infrastructure (Phases 1-3)." echo "Set up Kubernetes cluster infrastructure (Phases 1-3)."
echo "" echo ""
echo "Phase Control Options:" echo "Control Options:"
echo " --skip-installer Skip Phase 1 (Installer image generation)" echo " --skip-installer Skip Installer image generation"
echo " --skip-hardware Skip Phase 2 (Node hardware detection)" echo " --skip-hardware Skip Node hardware detection"
echo " --skip-configs Skip Phase 3 (Machine config generation)" echo " --skip-configs Skip Machine config generation"
echo " -h, --help Show this help message" echo " -h, --help Show this help message"
echo "" 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 "Prerequisites:"
echo " - Run 'wild-setup-scaffold' first to initialize the cloud" echo " - Run 'wild-setup-scaffold' first to initialize the cloud"
echo "" echo ""
@@ -159,45 +63,37 @@ while [[ $# -gt 0 ]]; do
done done
# Check if we're in a wild-cloud directory # Check if we're in a wild-cloud directory
if [ ! -d ".wildcloud" ]; then check_wild_directory
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 basic configuration # Check basic configuration
if [ -z "$(get_current_config "operator.email")" ]; then check_basic_config
print_error "Basic configuration is missing"
print_info "Run 'wild-setup-scaffold' first to configure basic settings"
exit 1
fi
print_header "Wild-Cloud Cluster Setup" print_header "Wild-Cloud Cluster Setup"
print_info "Setting up Kubernetes cluster infrastructure (Phases 1-3)" print_info "Setting up cluster infrastructure"
echo "" echo ""
# ============================================================================= # =============================================================================
# PHASE 1: Talos asset download # Talos asset download
# ============================================================================= # =============================================================================
if [ "${SKIP_INSTALLER}" = false ]; then 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..." print_info "Running wild-cluster-node-image-create..."
wild-cluster-node-image-create wild-cluster-node-image-create
print_success "Phase 1 completed: Installer image generated" print_success "Installer image generated"
echo "" echo ""
else else
print_info "Skipping Phase 1: Installer Image Generation" print_info "Skipping: Installer Image Generation"
fi fi
# ============================================================================= # =============================================================================
# PHASE 2: Node Hardware Detection # Node Hardware Detection
# ============================================================================= # =============================================================================
if [ "${SKIP_HARDWARE}" = false ]; then if [ "${SKIP_HARDWARE}" = false ]; then
print_header "Phase 2: Node Hardware Detection" print_header "Node Hardware Detection"
# Configure network settings # Configure network settings
if [ -z "$(get_current_config "cloud.router.ip")" ]; then if [ -z "$(get_current_config "cloud.router.ip")" ]; then
@@ -335,10 +231,10 @@ if [ "${SKIP_HARDWARE}" = false ]; then
echo "" echo ""
fi fi
# Generate initial cluster configuration # # Generate initial cluster configuration
print_header "Cluster Configuration Generation" # print_header "Cluster Configuration Generation"
print_info "Generating base cluster configuration with talosctl gen config..." # print_info "Generating base cluster configuration with talosctl gen config..."
wild-cluster-config-generate # wild-cluster-config-generate
# Detect and register control plane nodes # Detect and register control plane nodes
print_header "Control Plane Node Registration" print_header "Control Plane Node Registration"
@@ -366,7 +262,7 @@ if [ "${SKIP_HARDWARE}" = false ]; then
print_info " - Interface: $existing_interface" print_info " - Interface: $existing_interface"
print_info " - Disk: $(get_current_config "cluster.nodes.active.\"${TARGET_IP}\".disk")" 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" NODE_SETUP_DIR="${WC_HOME}/setup/cluster-nodes"
CONFIG_FILE="${NODE_SETUP_DIR}/final/${TARGET_IP}.yaml" CONFIG_FILE="${NODE_SETUP_DIR}/final/${TARGET_IP}.yaml"
if [ ! -f "$CONFIG_FILE" ]; then if [ ! -f "$CONFIG_FILE" ]; then
@@ -388,7 +284,8 @@ if [ "${SKIP_HARDWARE}" = false ]; then
continue continue
fi 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..." print_info "Attempting detection at target IP $TARGET_IP..."
DETECTION_IP="$TARGET_IP" DETECTION_IP="$TARGET_IP"
NODE_INFO="" NODE_INFO=""
@@ -446,7 +343,7 @@ if [ "${SKIP_HARDWARE}" = false ]; then
print_info "Selected disk: $SELECTED_DISK" print_info "Selected disk: $SELECTED_DISK"
fi fi
# Update config.yaml with hardware info # Update config.yaml with hardware info.
print_info "Updating configuration for $TARGET_IP..." 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}\".interface" "$INTERFACE"
wild-config-set "cluster.nodes.active.\"${TARGET_IP}\".disk" "$SELECTED_DISK" 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" print_success "Node $TARGET_IP registered successfully"
# Generate machine config immediately # Generate machine config.
print_info "Generating machine configuration for $TARGET_IP..." print_info "Generating machine configuration for $TARGET_IP..."
if wild-cluster-node-machine-config-generate "$TARGET_IP"; then if wild-cluster-node-machine-config-generate "$TARGET_IP"; then
print_success "Machine configuration generated for $TARGET_IP" print_success "Machine configuration generated for $TARGET_IP"
@@ -581,98 +478,10 @@ if [ "${SKIP_HARDWARE}" = false ]; then
fi fi
done done
print_success "Phase 2 completed: Node hardware detection" print_success "Completed Node hardware detection"
echo "" echo ""
else else
print_info "Skipping Phase 2: Node Hardware Detection" print_info "Skipping 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"
fi fi
# ============================================================================= # =============================================================================
@@ -683,46 +492,3 @@ print_header "Wild-Cloud Cluster Setup Complete!"
print_success "Cluster infrastructure setup completed!" print_success "Cluster infrastructure setup completed!"
echo "" 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!"

View File

@@ -3,98 +3,11 @@
set -e set -e
set -o pipefail set -o pipefail
# Get WC_ROOT (where this script and templates live) # Source common utilities
WC_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh"
export WC_ROOT
# ============================================================================= # Initialize Wild-Cloud environment
# HELPER FUNCTIONS 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"
}
# 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
}
UPDATE=false UPDATE=false

View File

@@ -3,102 +3,11 @@
set -e set -e
set -o pipefail set -o pipefail
# Get WC_ROOT (where this script and templates live) # Source common utilities
WC_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh"
export WC_ROOT
# Set up cloud directory (WC_HOME is where user's cloud will be) # Initialize Wild-Cloud environment
WC_HOME="$(pwd)" init_wild_env
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
}
# Parse arguments # Parse arguments
SKIP_INSTALL=false SKIP_INSTALL=false
@@ -146,18 +55,10 @@ while [[ $# -gt 0 ]]; do
done done
# Check if we're in a wild-cloud directory # Check if we're in a wild-cloud directory
if [ ! -d ".wildcloud" ]; then check_wild_directory
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 basic configuration # Check basic configuration
if [ -z "$(get_current_config "operator.email")" ]; then check_basic_config
print_error "Basic configuration is missing"
print_info "Run 'wild-setup-scaffold' first to configure basic settings"
exit 1
fi
# Check cluster configuration # Check cluster configuration
if [ -z "$(get_current_config "cluster.name")" ]; then if [ -z "$(get_current_config "cluster.name")" ]; then