Refactor installation scripts to use new configuration prompt helpers for improved user experience
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
# 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
|
||||
# - Config helpers: prompt_if_unset_config, prompt_if_unset_secret
|
||||
# - Validation: check_wild_directory, check_basic_config
|
||||
# - Utilities: command_exists, file_readable, dir_writable, generate_random_string
|
||||
|
||||
@@ -120,6 +121,44 @@ prompt_with_default() {
|
||||
echo "${result}"
|
||||
}
|
||||
|
||||
# Prompt for config value only if it's not already set
|
||||
prompt_if_unset_config() {
|
||||
local config_path="$1"
|
||||
local prompt="$2"
|
||||
local default="$3"
|
||||
|
||||
local current_value
|
||||
current_value=$(get_current_config "${config_path}")
|
||||
|
||||
if [ -z "${current_value}" ] || [ "${current_value}" = "null" ]; then
|
||||
local new_value
|
||||
new_value=$(prompt_with_default "${prompt}" "${default}" "")
|
||||
wild-config-set "${config_path}" "${new_value}"
|
||||
print_info "Set ${config_path} = ${new_value}"
|
||||
else
|
||||
print_info "Using existing ${config_path} = ${current_value}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Prompt for secret value only if it's not already set
|
||||
prompt_if_unset_secret() {
|
||||
local secret_path="$1"
|
||||
local prompt="$2"
|
||||
local default="$3"
|
||||
|
||||
local current_value
|
||||
current_value=$(get_current_secret "${secret_path}")
|
||||
|
||||
if [ -z "${current_value}" ] || [ "${current_value}" = "null" ]; then
|
||||
local new_value
|
||||
new_value=$(prompt_with_default "${prompt}" "${default}" "")
|
||||
wild-secret-set "${secret_path}" "${new_value}"
|
||||
print_info "Set secret ${secret_path}"
|
||||
else
|
||||
print_info "Using existing secret ${secret_path}"
|
||||
fi
|
||||
}
|
||||
|
||||
# =============================================================================
|
||||
# ENVIRONMENT SETUP
|
||||
# =============================================================================
|
||||
|
@@ -2,17 +2,13 @@
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
# Source common utilities
|
||||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../../bin/wild-common.sh"
|
||||
|
||||
# Initialize Wild-Cloud environment
|
||||
init_wild_env
|
||||
|
||||
if [ -z "${WC_HOME}" ]; then
|
||||
echo "Please source the wildcloud environment first. (e.g., \`source ./env.sh\`)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source "${WC_ROOT}/bin/wild-common.sh"
|
||||
|
||||
CLUSTER_SETUP_DIR="${WC_HOME}/setup/cluster"
|
||||
CERT_MANAGER_DIR="${CLUSTER_SETUP_DIR}/cert-manager"
|
||||
|
||||
@@ -21,42 +17,15 @@ print_header "Setting up cert-manager"
|
||||
# Collect required configuration variables
|
||||
print_info "Collecting cert-manager configuration..."
|
||||
|
||||
# Get current values
|
||||
current_domain=$(get_current_config "cloud.domain")
|
||||
current_internal_domain=$(get_current_config "cloud.internalDomain")
|
||||
current_email=$(get_current_config "operator.email")
|
||||
current_cf_domain=$(get_current_config "cluster.certManager.cloudflare.domain")
|
||||
current_cf_token=$(get_current_secret "cloudflare.token")
|
||||
# Prompt for configuration using helper functions
|
||||
prompt_if_unset_config "cloud.domain" "Enter main domain name" "example.com"
|
||||
|
||||
# Prompt for main domain
|
||||
domain=$(prompt_with_default "Enter main domain name" "example.com" "${current_domain}")
|
||||
wild-config-set "cloud.domain" "${domain}"
|
||||
|
||||
# Prompt for internal domain
|
||||
internal_domain=$(prompt_with_default "Enter internal domain name" "local.${domain}" "${current_internal_domain}")
|
||||
wild-config-set "cloud.internalDomain" "${internal_domain}"
|
||||
|
||||
# Prompt for operator email
|
||||
email=$(prompt_with_default "Enter operator email address (for Let's Encrypt)" "" "${current_email}")
|
||||
wild-config-set "operator.email" "${email}"
|
||||
|
||||
# Prompt for Cloudflare domain
|
||||
cf_domain=$(prompt_with_default "Enter Cloudflare domain (for DNS challenges)" "${domain}" "${current_cf_domain}")
|
||||
wild-config-set "cluster.certManager.cloudflare.domain" "${cf_domain}"
|
||||
|
||||
# Prompt for Cloudflare token
|
||||
if [ -z "${current_cf_token}" ] || [ "${current_cf_token}" = "null" ]; then
|
||||
cf_token=$(prompt_with_default "Enter Cloudflare API token (for DNS challenges)" "" "")
|
||||
else
|
||||
print_info "Cloudflare token already configured"
|
||||
read -p "Update Cloudflare API token? (y/N): " update_token
|
||||
if [[ "${update_token}" =~ ^[Yy]$ ]]; then
|
||||
cf_token=$(prompt_with_default "Enter new Cloudflare API token" "" "")
|
||||
else
|
||||
cf_token="${current_cf_token}"
|
||||
fi
|
||||
fi
|
||||
wild-secret-set "cloudflare.token" "${cf_token}"
|
||||
# Get the domain value to use as default for internal domain
|
||||
domain=$(wild-config "cloud.domain")
|
||||
prompt_if_unset_config "cloud.internalDomain" "Enter internal domain name" "local.${domain}"
|
||||
prompt_if_unset_config "operator.email" "Enter operator email address (for Let's Encrypt)" ""
|
||||
prompt_if_unset_config "cluster.certManager.cloudflare.domain" "Enter Cloudflare domain (for DNS challenges)" "${domain}"
|
||||
prompt_if_unset_secret "cloudflare.token" "Enter Cloudflare API token (for DNS challenges)" ""
|
||||
|
||||
print_success "Configuration collected successfully"
|
||||
|
||||
|
@@ -2,17 +2,13 @@
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
# Source common utilities
|
||||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../../bin/wild-common.sh"
|
||||
|
||||
# Initialize Wild-Cloud environment
|
||||
init_wild_env
|
||||
|
||||
if [ -z "${WC_HOME}" ]; then
|
||||
echo "Please source the wildcloud environment first. (e.g., \`source ./env.sh\`)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source "${WC_ROOT}/bin/wild-common.sh"
|
||||
|
||||
CLUSTER_SETUP_DIR="${WC_HOME}/setup/cluster"
|
||||
COREDNS_DIR="${CLUSTER_SETUP_DIR}/coredns"
|
||||
|
||||
@@ -21,22 +17,10 @@ print_header "Setting up CoreDNS for k3s"
|
||||
# Collect required configuration variables
|
||||
print_info "Collecting CoreDNS configuration..."
|
||||
|
||||
# Get current values
|
||||
current_internal_domain=$(get_current_config "cloud.internalDomain")
|
||||
current_lb_ip=$(get_current_config "cluster.loadBalancerIp")
|
||||
current_external_resolver=$(get_current_config "cloud.dns.externalResolver")
|
||||
|
||||
# Prompt for internal domain
|
||||
internal_domain=$(prompt_with_default "Enter internal domain name" "local.example.com" "${current_internal_domain}")
|
||||
wild-config-set "cloud.internalDomain" "${internal_domain}"
|
||||
|
||||
# Prompt for load balancer IP
|
||||
lb_ip=$(prompt_with_default "Enter load balancer IP address" "192.168.1.240" "${current_lb_ip}")
|
||||
wild-config-set "cluster.loadBalancerIp" "${lb_ip}"
|
||||
|
||||
# Prompt for external DNS resolver
|
||||
external_resolver=$(prompt_with_default "Enter external DNS resolver" "8.8.8.8" "${current_external_resolver}")
|
||||
wild-config-set "cloud.dns.externalResolver" "${external_resolver}"
|
||||
# Prompt for configuration using helper functions
|
||||
prompt_if_unset_config "cloud.internalDomain" "Enter internal domain name" "local.example.com"
|
||||
prompt_if_unset_config "cluster.loadBalancerIp" "Enter load balancer IP address" "192.168.1.240"
|
||||
prompt_if_unset_config "cloud.dns.externalResolver" "Enter external DNS resolver" "8.8.8.8"
|
||||
|
||||
print_success "Configuration collected successfully"
|
||||
|
||||
|
@@ -2,17 +2,13 @@
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
# Source common utilities
|
||||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../../bin/wild-common.sh"
|
||||
|
||||
# Initialize Wild-Cloud environment
|
||||
init_wild_env
|
||||
|
||||
if [ -z "${WC_HOME}" ]; then
|
||||
echo "Please source the wildcloud environment first. (e.g., \`source ./env.sh\`)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source "${WC_ROOT}/bin/wild-common.sh"
|
||||
|
||||
CLUSTER_SETUP_DIR="${WC_HOME}/setup/cluster"
|
||||
DOCKER_REGISTRY_DIR="${CLUSTER_SETUP_DIR}/docker-registry"
|
||||
|
||||
@@ -21,17 +17,9 @@ print_header "Setting up Docker Registry"
|
||||
# Collect required configuration variables
|
||||
print_info "Collecting Docker Registry configuration..."
|
||||
|
||||
# Get current values
|
||||
current_registry_host=$(get_current_config "cloud.dockerRegistryHost")
|
||||
current_storage=$(get_current_config "cluster.dockerRegistry.storage")
|
||||
|
||||
# Prompt for Docker Registry host
|
||||
registry_host=$(prompt_with_default "Enter Docker Registry hostname" "registry.local.example.com" "${current_registry_host}")
|
||||
wild-config-set "cloud.dockerRegistryHost" "${registry_host}"
|
||||
|
||||
# Prompt for storage size
|
||||
storage=$(prompt_with_default "Enter Docker Registry storage size" "100Gi" "${current_storage}")
|
||||
wild-config-set "cluster.dockerRegistry.storage" "${storage}"
|
||||
# Prompt for configuration using helper functions
|
||||
prompt_if_unset_config "cloud.dockerRegistryHost" "Enter Docker Registry hostname" "registry.local.example.com"
|
||||
prompt_if_unset_config "cluster.dockerRegistry.storage" "Enter Docker Registry storage size" "100Gi"
|
||||
|
||||
print_success "Configuration collected successfully"
|
||||
|
||||
|
@@ -2,17 +2,13 @@
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
# Source common utilities
|
||||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../../bin/wild-common.sh"
|
||||
|
||||
# Initialize Wild-Cloud environment
|
||||
init_wild_env
|
||||
|
||||
if [ -z "${WC_HOME}" ]; then
|
||||
echo "Please source the wildcloud environment first. (e.g., \`source ./env.sh\`)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source "${WC_ROOT}/bin/wild-common.sh"
|
||||
|
||||
CLUSTER_SETUP_DIR="${WC_HOME}/setup/cluster"
|
||||
EXTERNALDNS_DIR="${CLUSTER_SETUP_DIR}/externaldns"
|
||||
|
||||
@@ -21,12 +17,8 @@ print_header "Setting up ExternalDNS"
|
||||
# Collect required configuration variables
|
||||
print_info "Collecting ExternalDNS configuration..."
|
||||
|
||||
# Get current value
|
||||
current_owner_id=$(get_current_config "cluster.externalDns.ownerId")
|
||||
|
||||
# Prompt for ExternalDNS owner ID
|
||||
owner_id=$(prompt_with_default "Enter ExternalDNS owner ID (unique identifier for this cluster)" "wild-cloud-$(hostname -s)" "${current_owner_id}")
|
||||
wild-config-set "cluster.externalDns.ownerId" "${owner_id}"
|
||||
# Prompt for configuration using helper functions
|
||||
prompt_if_unset_config "cluster.externalDns.ownerId" "Enter ExternalDNS owner ID (unique identifier for this cluster)" "wild-cloud-$(hostname -s)"
|
||||
|
||||
print_success "Configuration collected successfully"
|
||||
|
||||
|
@@ -2,17 +2,13 @@
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
# Source common utilities
|
||||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../../bin/wild-common.sh"
|
||||
|
||||
# Initialize Wild-Cloud environment
|
||||
init_wild_env
|
||||
|
||||
if [ -z "${WC_HOME}" ]; then
|
||||
echo "Please source the wildcloud environment first. (e.g., \`source ./env.sh\`)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source "${WC_ROOT}/bin/wild-common.sh"
|
||||
|
||||
CLUSTER_SETUP_DIR="${WC_HOME}/setup/cluster"
|
||||
KUBERNETES_DASHBOARD_DIR="${CLUSTER_SETUP_DIR}/kubernetes-dashboard"
|
||||
|
||||
@@ -21,12 +17,8 @@ print_header "Setting up Kubernetes Dashboard"
|
||||
# Collect required configuration variables
|
||||
print_info "Collecting Kubernetes Dashboard configuration..."
|
||||
|
||||
# Get current value
|
||||
current_internal_domain=$(get_current_config "cloud.internalDomain")
|
||||
|
||||
# Prompt for internal domain
|
||||
internal_domain=$(prompt_with_default "Enter internal domain name (for dashboard URL)" "local.example.com" "${current_internal_domain}")
|
||||
wild-config-set "cloud.internalDomain" "${internal_domain}"
|
||||
# Prompt for configuration using helper functions
|
||||
prompt_if_unset_config "cloud.internalDomain" "Enter internal domain name (for dashboard URL)" "local.example.com"
|
||||
|
||||
print_success "Configuration collected successfully"
|
||||
|
||||
|
@@ -1,11 +1,14 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
if [ -z "${WC_HOME}" ]; then
|
||||
echo "Please source the wildcloud environment first. (e.g., \`source ./env.sh\`)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source "${WC_ROOT}/bin/wild-common.sh"
|
||||
|
||||
CLUSTER_SETUP_DIR="${WC_HOME}/setup/cluster"
|
||||
LONGHORN_DIR="${CLUSTER_SETUP_DIR}/longhorn"
|
||||
|
||||
|
@@ -2,17 +2,13 @@
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
# Source common utilities
|
||||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../../bin/wild-common.sh"
|
||||
|
||||
# Initialize Wild-Cloud environment
|
||||
init_wild_env
|
||||
|
||||
if [ -z "${WC_HOME}" ]; then
|
||||
echo "Please source the wildcloud environment first. (e.g., \`source ./env.sh\`)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source "${WC_ROOT}/bin/wild-common.sh"
|
||||
|
||||
CLUSTER_SETUP_DIR="${WC_HOME}/setup/cluster"
|
||||
METALLB_DIR="${CLUSTER_SETUP_DIR}/metallb"
|
||||
|
||||
@@ -21,17 +17,9 @@ print_header "Setting up MetalLB"
|
||||
# Collect required configuration variables
|
||||
print_info "Collecting MetalLB configuration..."
|
||||
|
||||
# Get current values
|
||||
current_ip_pool=$(get_current_config "cluster.ipAddressPool")
|
||||
current_lb_ip=$(get_current_config "cluster.loadBalancerIp")
|
||||
|
||||
# Prompt for IP address pool
|
||||
ip_pool=$(prompt_with_default "Enter IP address pool for MetalLB (CIDR format, e.g., 192.168.1.240-192.168.1.250)" "192.168.1.240-192.168.1.250" "${current_ip_pool}")
|
||||
wild-config-set "cluster.ipAddressPool" "${ip_pool}"
|
||||
|
||||
# Prompt for load balancer IP
|
||||
lb_ip=$(prompt_with_default "Enter load balancer IP address" "192.168.1.240" "${current_lb_ip}")
|
||||
wild-config-set "cluster.loadBalancerIp" "${lb_ip}"
|
||||
# Prompt for configuration using helper functions
|
||||
prompt_if_unset_config "cluster.ipAddressPool" "Enter IP address pool for MetalLB (CIDR format, e.g., 192.168.1.240-192.168.1.250)" "192.168.1.240-192.168.1.250"
|
||||
prompt_if_unset_config "cluster.loadBalancerIp" "Enter load balancer IP address" "192.168.1.240"
|
||||
|
||||
print_success "Configuration collected successfully"
|
||||
|
||||
|
@@ -2,17 +2,13 @@
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
# Source common utilities
|
||||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../../bin/wild-common.sh"
|
||||
|
||||
# Initialize Wild-Cloud environment
|
||||
init_wild_env
|
||||
|
||||
if [ -z "${WC_HOME}" ]; then
|
||||
echo "Please source the wildcloud environment first. (e.g., \`source ./env.sh\`)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source "${WC_ROOT}/bin/wild-common.sh"
|
||||
|
||||
CLUSTER_SETUP_DIR="${WC_HOME}/setup/cluster"
|
||||
NFS_DIR="${CLUSTER_SETUP_DIR}/nfs"
|
||||
|
||||
@@ -21,22 +17,10 @@ print_header "Registering NFS server with Kubernetes cluster"
|
||||
# Collect required configuration variables
|
||||
print_info "Collecting NFS configuration..."
|
||||
|
||||
# Get current values
|
||||
current_nfs_host=$(get_current_config "cloud.nfs.host")
|
||||
current_media_path=$(get_current_config "cloud.nfs.mediaPath")
|
||||
current_storage_capacity=$(get_current_config "cloud.nfs.storageCapacity")
|
||||
|
||||
# Prompt for NFS host
|
||||
nfs_host=$(prompt_with_default "Enter NFS server hostname or IP address" "192.168.1.100" "${current_nfs_host}")
|
||||
wild-config-set "cloud.nfs.host" "${nfs_host}"
|
||||
|
||||
# Prompt for NFS media path
|
||||
media_path=$(prompt_with_default "Enter NFS export path for media storage" "/mnt/storage/media" "${current_media_path}")
|
||||
wild-config-set "cloud.nfs.mediaPath" "${media_path}"
|
||||
|
||||
# Prompt for storage capacity
|
||||
storage_capacity=$(prompt_with_default "Enter NFS storage capacity (e.g., 1Ti, 500Gi)" "1Ti" "${current_storage_capacity}")
|
||||
wild-config-set "cloud.nfs.storageCapacity" "${storage_capacity}"
|
||||
# Prompt for configuration using helper functions
|
||||
prompt_if_unset_config "cloud.nfs.host" "Enter NFS server hostname or IP address" "192.168.1.100"
|
||||
prompt_if_unset_config "cloud.nfs.mediaPath" "Enter NFS export path for media storage" "/mnt/storage/media"
|
||||
prompt_if_unset_config "cloud.nfs.storageCapacity" "Enter NFS storage capacity (e.g., 1Ti, 500Gi)" "1Ti"
|
||||
|
||||
print_success "Configuration collected successfully"
|
||||
|
||||
|
@@ -2,17 +2,13 @@
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
# Source common utilities
|
||||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../../bin/wild-common.sh"
|
||||
|
||||
# Initialize Wild-Cloud environment
|
||||
init_wild_env
|
||||
|
||||
if [ -z "${WC_HOME}" ]; then
|
||||
echo "Please source the wildcloud environment first. (e.g., \`source ./env.sh\`)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source "${WC_ROOT}/bin/wild-common.sh"
|
||||
|
||||
CLUSTER_SETUP_DIR="${WC_HOME}/setup/cluster"
|
||||
TRAEFIK_DIR="${CLUSTER_SETUP_DIR}/traefik"
|
||||
|
||||
@@ -21,12 +17,8 @@ print_header "Setting up Traefik ingress controller"
|
||||
# Collect required configuration variables
|
||||
print_info "Collecting Traefik configuration..."
|
||||
|
||||
# Get current value
|
||||
current_lb_ip=$(get_current_config "cluster.loadBalancerIp")
|
||||
|
||||
# Prompt for load balancer IP
|
||||
lb_ip=$(prompt_with_default "Enter load balancer IP address for Traefik" "192.168.1.240" "${current_lb_ip}")
|
||||
wild-config-set "cluster.loadBalancerIp" "${lb_ip}"
|
||||
# Prompt for configuration using helper functions
|
||||
prompt_if_unset_config "cluster.loadBalancerIp" "Enter load balancer IP address for Traefik" "192.168.1.240"
|
||||
|
||||
print_success "Configuration collected successfully"
|
||||
|
||||
|
@@ -1,11 +1,14 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
if [ -z "${WC_HOME}" ]; then
|
||||
echo "Please source the wildcloud environment first. (e.g., \`source ./env.sh\`)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source "${WC_ROOT}/bin/wild-common.sh"
|
||||
|
||||
CLUSTER_SETUP_DIR="${WC_HOME}/setup/cluster"
|
||||
UTILS_DIR="${CLUSTER_SETUP_DIR}/utils"
|
||||
|
||||
@@ -21,4 +24,4 @@ fi
|
||||
echo "Applying utility manifests..."
|
||||
kubectl apply -f ${UTILS_DIR}/kustomize/
|
||||
|
||||
echo "✅ Cluster utilities setup complete!"
|
||||
echo "✅ Cluster utilities setup complete!"
|
||||
|
Reference in New Issue
Block a user