Files
wild-cloud-poc/bin/wild-setup-services

178 lines
5.3 KiB
Bash
Executable File

#!/bin/bash
set -e
set -o pipefail
# Parse arguments
FETCH=false
NO_DEPLOY=false
while [[ $# -gt 0 ]]; do
case $1 in
--fetch)
FETCH=true
shift
;;
--no-deploy|--skip-install)
NO_DEPLOY=true
shift
;;
-h|--help)
echo "Usage: $0 [options]"
echo ""
echo "Set up all Kubernetes cluster services (Phase 4)."
echo ""
echo "Options:"
echo " --fetch Fetch fresh templates for all services before setup"
echo " --no-deploy Configure all services but skip deployment"
echo " --skip-install Alias for --no-deploy (deprecated)"
echo " -h, --help Show this help message"
echo ""
echo "This script will:"
echo " - Set up core services in dependency order (MetalLB, Traefik, cert-manager, etc.)"
echo " - Each service validates its prerequisites before deployment"
echo " - Fail-fast with clear recovery instructions on errors"
echo ""
echo "Prerequisites:"
echo " - Run 'wild-setup-cluster' to set up cluster infrastructure"
echo " - Kubernetes cluster must be running and kubectl configured"
exit 0
;;
-*)
echo "Unknown option $1"
echo "Usage: $0 [options]"
echo "Use --help for full usage information"
exit 1
;;
*)
echo "Unexpected argument: $1"
echo "Usage: $0 [options]"
echo "Use --help for full usage information"
exit 1
;;
esac
done
# Initialize Wild Cloud environment
if [ -z "${WC_ROOT}" ]; then
print "WC_ROOT is not set."
exit 1
else
source "${WC_ROOT}/scripts/common.sh"
init_wild_env
fi
# Check cluster configuration
if [ -z "$(wild-config "cluster.name")" ]; then
print_error "Cluster configuration is missing"
print_info "Run 'wild-setup-cluster' first to configure cluster settings"
exit 1
fi
print_header "Wild Cloud services setup"
# Define services in dependency order
SERVICES_TO_INSTALL=(
"metallb"
"longhorn"
"traefik"
"coredns"
"cert-manager"
"externaldns"
"kubernetes-dashboard"
"nfs"
"docker-registry"
)
# Set up services one by one
INSTALLED_COUNT=0
FAILED_COUNT=0
# Build service setup command flags
SERVICE_FLAGS=""
if [ "$FETCH" = true ]; then
SERVICE_FLAGS="$SERVICE_FLAGS --fetch"
fi
if [ "$NO_DEPLOY" = true ]; then
SERVICE_FLAGS="$SERVICE_FLAGS --no-deploy"
fi
if [ "$NO_DEPLOY" = false ]; then
for service in "${SERVICES_TO_INSTALL[@]}"; do
echo ""
print_header "Setting up service: $service"
if wild-service-setup "$service" $SERVICE_FLAGS; then
print_success "$service setup completed"
INSTALLED_COUNT=$((INSTALLED_COUNT + 1))
else
print_error "$service setup failed"
FAILED_COUNT=$((FAILED_COUNT + 1))
# Stop on first failure for easier debugging
break
fi
done
if [ $FAILED_COUNT -eq 0 ]; then
SERVICES_INSTALLED=true
print_success "All $INSTALLED_COUNT services set up successfully!"
else
print_error "Service setup stopped after $service failure"
print_info "Fix the issue and resume with: wild-service-setup $service $SERVICE_FLAGS"
print_info "Then continue with remaining services or re-run wild-setup-services"
exit 1
fi
else
print_info "Skipping cluster services deployment (--no-deploy specified)"
print_info "Services will be configured but not deployed to cluster."
for service in "${SERVICES_TO_INSTALL[@]}"; do
echo ""
print_header "Configuring service: $service"
if wild-service-setup "$service" $SERVICE_FLAGS; then
print_success "$service configuration completed"
INSTALLED_COUNT=$((INSTALLED_COUNT + 1))
else
print_error "$service configuration failed"
FAILED_COUNT=$((FAILED_COUNT + 1))
break
fi
done
if [ $FAILED_COUNT -eq 0 ]; then
print_success "All $INSTALLED_COUNT services configured successfully!"
print_info "To deploy them later, run: wild-setup-services"
else
print_error "Service configuration stopped after $service failure"
exit 1
fi
fi
# Summary output
print_header "Wild Cloud Services Setup Complete!"
echo ""
if [ "${SERVICES_INSTALLED:-false}" = true ]; then
INTERNAL_DOMAIN=$(wild-config cloud.internalDomain 2>/dev/null || echo "your-internal-domain")
echo "Next steps:"
echo " 1. Access the dashboard at: https://dashboard.${INTERNAL_DOMAIN}"
echo " 2. Get the dashboard token with: wild-dashboard-token"
echo ""
echo "To verify components, run:"
echo " - kubectl get pods -n cert-manager"
echo " - kubectl get pods -n externaldns"
echo " - kubectl get pods -n kubernetes-dashboard"
echo " - kubectl get clusterissuers"
else
echo "Next steps:"
echo " 1. Ensure your cluster is running and kubectl is configured"
echo " 2. Install services with: wild-cluster-services-up"
echo " 3. Verify components are running correctly"
fi
print_success "Wild Cloud setup completed!"