Separates cluster service config from install.
This commit is contained in:
148
bin/wild-cluster-services-fetch
Executable file
148
bin/wild-cluster-services-fetch
Executable file
@@ -0,0 +1,148 @@
|
||||
#\!/bin/bash
|
||||
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
# Usage function
|
||||
usage() {
|
||||
echo "Usage: wild-cluster-services-fetch [options]"
|
||||
echo ""
|
||||
echo "Fetch cluster services setup files from the repository."
|
||||
echo ""
|
||||
echo "Arguments:"
|
||||
echo " service Specific service(s) to install (optional)"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " -h, --help Show this help message"
|
||||
echo " --force Force fetching even if files exist"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " wild-cluster-services-fetch # Fetch all services"
|
||||
echo " wild-cluster-services-fetch metallb traefik # Fetch specific services"
|
||||
echo ""
|
||||
echo "Available services:"
|
||||
echo " metallb, longhorn, traefik, coredns, cert-manager,"
|
||||
echo " externaldns, kubernetes-dashboard, nfs, docker-registry"
|
||||
}
|
||||
|
||||
# Parse arguments
|
||||
FORCE=false
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
--force)
|
||||
FORCE=true
|
||||
shift
|
||||
;;
|
||||
-*)
|
||||
echo "Unknown option $1"
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
echo "Unexpected argument: $1"
|
||||
usage
|
||||
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
|
||||
|
||||
print_header "Fetching cluster services templates"
|
||||
|
||||
SOURCE_DIR="${WC_ROOT}/setup/cluster-services"
|
||||
DEST_DIR="${WC_HOME}/setup/cluster-services"
|
||||
|
||||
# Check if source directory exists
|
||||
if [ ! -d "$SOURCE_DIR" ]; then
|
||||
print_error "Cluster setup source directory not found: $SOURCE_DIR"
|
||||
print_info "Make sure the wild-cloud repository is properly set up"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if destination already exists
|
||||
if [ -d "$DEST_DIR" ] && [ "$FORCE" = false ]; then
|
||||
print_warning "Cluster setup directory already exists: $DEST_DIR"
|
||||
read -p "Overwrite existing files? (y/N): " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
FORCE=true
|
||||
fi
|
||||
else
|
||||
mkdir -p "$DEST_DIR"
|
||||
fi
|
||||
|
||||
# Copy README
|
||||
if [ ! -f "${WC_HOME}/setup/README.md" ]; then
|
||||
cp "${WC_ROOT}/setup/README.md" "${WC_HOME}/setup/README.md"
|
||||
fi
|
||||
|
||||
# Get list of services to install
|
||||
if [ ${#SPECIFIC_SERVICES[@]} -gt 0 ]; then
|
||||
SERVICES_TO_INSTALL=("${SPECIFIC_SERVICES[@]}")
|
||||
print_info "Fetching specific services: ${SERVICES_TO_INSTALL[*]}"
|
||||
else
|
||||
# Install all available services in a specific order for dependencies
|
||||
SERVICES_TO_INSTALL=(
|
||||
"metallb"
|
||||
"longhorn"
|
||||
"traefik"
|
||||
"coredns"
|
||||
"cert-manager"
|
||||
"externaldns"
|
||||
"kubernetes-dashboard"
|
||||
"nfs"
|
||||
"docker-registry"
|
||||
)
|
||||
print_info "Fetching all available services."
|
||||
fi
|
||||
|
||||
for service in "${SERVICES_TO_INSTALL[@]}"; do
|
||||
|
||||
SERVICE_SOURCE_DIR="$SOURCE_DIR/$service"
|
||||
SERVICE_DEST_DIR="$DEST_DIR/$service"
|
||||
TEMPLATE_SOURCE_DIR="$SERVICE_SOURCE_DIR/kustomize.template"
|
||||
TEMPLATE_DEST_DIR="$SERVICE_DEST_DIR/kustomize.template"
|
||||
|
||||
if [ ! -d "$TEMPLATE_SOURCE_DIR" ]; then
|
||||
print_error "Source directory not found: $TEMPLATE_SOURCE_DIR"
|
||||
continue
|
||||
fi
|
||||
|
||||
if $FORCE && [ -d "$TEMPLATE_DEST_DIR" ]; then
|
||||
print_info "Removing existing $service templates in: $TEMPLATE_DEST_DIR"
|
||||
rm -rf "$TEMPLATE_DEST_DIR"
|
||||
elif [ -d "$TEMPLATE_DEST_DIR" ]; then
|
||||
print_info "Files already exist for $service, skipping (use --force to overwrite)."
|
||||
continue
|
||||
fi
|
||||
|
||||
mkdir -p "$SERVICE_DEST_DIR"
|
||||
mkdir -p "$TEMPLATE_DEST_DIR"
|
||||
cp -f "$SERVICE_SOURCE_DIR/README.md" "$SERVICE_DEST_DIR/"
|
||||
|
||||
if [ -f "$SERVICE_SOURCE_DIR/configure.sh" ]; then
|
||||
cp -f "$SERVICE_SOURCE_DIR/configure.sh" "$SERVICE_DEST_DIR/"
|
||||
fi
|
||||
|
||||
if [ -f "$SERVICE_SOURCE_DIR/install.sh" ]; then
|
||||
cp -f "$SERVICE_SOURCE_DIR/install.sh" "$SERVICE_DEST_DIR/"
|
||||
fi
|
||||
|
||||
if [ -d "$TEMPLATE_SOURCE_DIR" ]; then
|
||||
cp -r "$TEMPLATE_SOURCE_DIR/"* "$TEMPLATE_DEST_DIR/"
|
||||
fi
|
||||
|
||||
print_success "Fetched $service templates."
|
||||
done
|
Reference in New Issue
Block a user