Extracts common library from wild scripts.
This commit is contained in:
@@ -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"
|
||||
|
Reference in New Issue
Block a user