Updates service installs to not copy kustomize templates.

This commit is contained in:
2025-06-29 13:30:28 -07:00
parent ddac8775b1
commit 5579e1e3c0
19 changed files with 214 additions and 102 deletions

View File

@@ -72,17 +72,12 @@ if [ -z "$NODE_IP" ]; then
exit 1
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
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"
print_info "Run 'wild-setup' to configure your cluster"
exit 1
fi

View File

@@ -102,34 +102,71 @@ elif [ "$FORCE" = true ] && [ -d "$DEST_DIR" ]; then
rm -rf "$DEST_DIR"
fi
# Copy cluster setup files
print_info "Copying cluster setup files from repository..."
# Copy and compile cluster setup files
print_info "Copying and compiling cluster setup files from repository..."
mkdir -p "${WC_HOME}/setup"
cp -r "$SOURCE_DIR" "$DEST_DIR"
# Copy README if it doesn't exist
if [ ! -f "${WC_HOME}/setup/README.md" ]; then
cp "${WC_ROOT}/setup/README.md" "${WC_HOME}/setup/README.md"
fi
print_success "Cluster setup files copied"
# Create destination directory
mkdir -p "$DEST_DIR"
# Compile templates
print_info "Compiling service templates with current configuration..."
# First, copy root-level files from setup/cluster/ (install-all.sh, get_helm.sh, etc.)
print_info "Copying root-level cluster setup files..."
for item in "$SOURCE_DIR"/*; do
if [ -f "$item" ]; then
item_name=$(basename "$item")
print_info " Copying: ${item_name}"
cp "$item" "$DEST_DIR/$item_name"
fi
done
COMPILED_COUNT=0
find "$DEST_DIR" -type f \( -name "*.yaml" -o -name "*.yml" -o -name "*.conf" -o -name "*.json" \) | while read -r file; do
# Skip files that don't contain template variables
if ! grep -q "{{" "$file" 2>/dev/null; then
# Then, process each service directory in the source
print_info "Processing service directories..."
for service_dir in "$SOURCE_DIR"/*; do
if [ ! -d "$service_dir" ]; then
continue
fi
print_info "Compiling: ${file#${WC_HOME}/}"
wild-compile-template < "$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
COMPILED_COUNT=$((COMPILED_COUNT + 1))
service_name=$(basename "$service_dir")
dest_service_dir="$DEST_DIR/$service_name"
print_info "Processing service: $service_name"
# Create destination service directory
mkdir -p "$dest_service_dir"
# Copy all files except kustomize.template directory
for item in "$service_dir"/*; do
item_name=$(basename "$item")
if [ "$item_name" = "kustomize.template" ]; then
# Compile kustomize.template to kustomize directory
if [ -d "$item" ]; then
print_info " Compiling kustomize templates for $service_name"
wild-compile-template-dir --clean "$item" "$dest_service_dir/kustomize"
fi
else
# Copy other files as-is (install.sh, README.md, etc.)
if [ -f "$item" ]; then
# Compile individual template files
if grep -q "{{" "$item" 2>/dev/null; then
print_info " Compiling: ${item_name}"
wild-compile-template < "$item" > "$dest_service_dir/$item_name"
else
cp "$item" "$dest_service_dir/$item_name"
fi
elif [ -d "$item" ]; then
cp -r "$item" "$dest_service_dir/"
fi
fi
done
done
print_success "Template compilation completed"
print_success "Cluster setup files copied and compiled"
# Verify required configuration
print_info "Verifying service configuration..."

View File

@@ -58,6 +58,7 @@ export WC_HOME
# Template directory (in WC_ROOT, never written to)
TEMPLATE_DIR="${WC_ROOT}/setup/home-scaffold"
echo "Using template directory: ${TEMPLATE_DIR}"
if [ ! -d "${TEMPLATE_DIR}" ]; then
echo "Error: Template directory not found at ${TEMPLATE_DIR}"

View File

@@ -72,10 +72,10 @@ print_info "Installing Kubernetes cluster services (Phase 4)"
echo ""
# =============================================================================
# PHASE 4: Cluster Services Installation
# Cluster Services Installation
# =============================================================================
print_header "Phase 4: Cluster Services Installation"
print_header "Cluster Services Installation"
# Configure DNS and certificates
if [ -z "$(get_current_config "cluster.certManager.cloudflare.domain")" ]; then
@@ -115,6 +115,54 @@ if [ -z "$(get_current_config "cluster.certManager.cloudflare.domain")" ]; then
echo ""
fi
# Configure core network settings
print_header "Network Configuration"
# Get basic domain configuration (should already be set from earlier setup)
domain=$(get_current_config "cloud.domain")
internal_domain=$(get_current_config "cloud.internalDomain")
operator_email=$(get_current_config "operator.email")
if [ -z "$domain" ] || [ -z "$internal_domain" ] || [ -z "$operator_email" ]; then
print_error "Basic domain and operator configuration missing"
print_info "Please run 'wild-setup-scaffold' first to configure basic settings"
exit 1
fi
# Load balancer IP configuration
current_lb_ip=$(get_current_config "cluster.loadBalancerIp")
if [ -z "$current_lb_ip" ] || [ "$current_lb_ip" = "null" ]; then
lb_ip=$(prompt_with_default "Load balancer IP address" "" "${current_lb_ip}")
wild-config-set "cluster.loadBalancerIp" "${lb_ip}"
fi
# IP address pool for MetalLB
current_ip_pool=$(get_current_config "cluster.ipAddressPool")
if [ -z "$current_ip_pool" ] || [ "$current_ip_pool" = "null" ]; then
current_lb_ip=$(get_current_config "cluster.loadBalancerIp")
ip_pool=$(prompt_with_default "IP address pool for load balancer (range)" "${current_lb_ip}-${current_lb_ip}" "${current_ip_pool}")
wild-config-set "cluster.ipAddressPool" "${ip_pool}"
fi
# External DNS resolver for CoreDNS
current_dns_resolver=$(get_current_config "cloud.dns.externalResolver")
if [ -z "$current_dns_resolver" ] || [ "$current_dns_resolver" = "null" ]; then
dns_resolver=$(prompt_with_default "External DNS resolver" "1.1.1.1" "${current_dns_resolver}")
wild-config-set "cloud.dns.externalResolver" "${dns_resolver}"
fi
# ExternalDNS owner ID (unique identifier for DNS records)
current_owner_id=$(get_current_config "cluster.externalDns.ownerId")
if [ -z "$current_owner_id" ] || [ "$current_owner_id" = "null" ]; then
cluster_name=$(get_current_config "cluster.name")
default_owner_id="${cluster_name:-wild-cloud}-$(date +%s)"
owner_id=$(prompt_with_default "ExternalDNS owner ID (unique identifier)" "${default_owner_id}" "${current_owner_id}")
wild-config-set "cluster.externalDns.ownerId" "${owner_id}"
fi
print_success "Network configuration completed"
echo ""
# Configure storage settings
print_header "Storage Configuration"
@@ -181,9 +229,9 @@ else
fi
if [ "${SKIP_INSTALL}" = false ] && [ "${SERVICES_INSTALLED:-false}" = true ]; then
print_success "Phase 4 completed: Cluster services installation"
print_success "Completed: Cluster services installation"
else
print_success "Phase 4 completed: Cluster services configuration generated"
print_success "Completed: Cluster services configuration generated"
fi
echo ""

View File

@@ -9,9 +9,12 @@ fi
CLUSTER_SETUP_DIR="${WC_HOME}/setup/cluster"
CERT_MANAGER_DIR="${CLUSTER_SETUP_DIR}/cert-manager"
# Process templates with wild-compile-template-dir
echo "Processing cert-manager templates..."
wild-compile-template-dir --clean ${CERT_MANAGER_DIR}/kustomize.template ${CERT_MANAGER_DIR}/kustomize
# Templates should already be compiled by wild-cluster-services-generate
echo "Using pre-compiled cert-manager templates..."
if [ ! -d "${CERT_MANAGER_DIR}/kustomize" ]; then
echo "Error: Compiled templates not found. Run 'wild-cluster-services-generate' first."
exit 1
fi
echo "Setting up cert-manager..."

View File

@@ -11,18 +11,17 @@ COREDNS_DIR="${CLUSTER_SETUP_DIR}/coredns"
echo "Setting up CoreDNS for k3s..."
# Process templates with wild-compile-template-dir
echo "Processing CoreDNS templates..."
wild-compile-template-dir --clean ${COREDNS_DIR}/kustomize.template ${COREDNS_DIR}/kustomize
# Templates should already be compiled by wild-cluster-services-generate
echo "Using pre-compiled CoreDNS templates..."
if [ ! -d "${COREDNS_DIR}/kustomize" ]; then
echo "Error: Compiled templates not found. Run 'wild-cluster-services-generate' first."
exit 1
fi
# Apply the k3s-compatible custom DNS override (k3s will preserve this)
echo "Applying CoreDNS custom override configuration..."
kubectl apply -f "${COREDNS_DIR}/kustomize/coredns-custom-config.yaml"
# Apply the LoadBalancer service for external access to CoreDNS
echo "Applying CoreDNS service configuration..."
kubectl apply -f "${COREDNS_DIR}/kustomize/coredns-lb-service.yaml"
# Restart CoreDNS pods to apply the changes
echo "Restarting CoreDNS pods to apply changes..."
kubectl rollout restart deployment/coredns -n kube-system

View File

@@ -14,7 +14,7 @@ data:
reload
template IN A {
match (.*)\.{{ .cloud.internalDomain | strings.ReplaceAll "." "\\." }}\.
answer "{{`{{"{{ .Name }}"}}`}} 60 IN A {{ .cluster.loadBalancerIp }}"
answer "{{`{{ .Name }}`}} 60 IN A {{ .cluster.loadBalancerIp }}"
}
template IN AAAA {
match (.*)\.{{ .cloud.internalDomain | strings.ReplaceAll "." "\\." }}\.

View File

@@ -1,23 +0,0 @@
---
apiVersion: v1
kind: Service
metadata:
name: coredns-lb
namespace: kube-system
spec:
type: LoadBalancer
ports:
- name: dns
port: 53
protocol: UDP
targetPort: 53
- name: dns-tcp
port: 53
protocol: TCP
targetPort: 53
- name: metrics
port: 9153
protocol: TCP
targetPort: 9153
selector:
k8s-app: kube-dns

View File

@@ -11,9 +11,12 @@ DOCKER_REGISTRY_DIR="${CLUSTER_SETUP_DIR}/docker-registry"
echo "Setting up Docker Registry..."
# Process templates with wild-compile-template-dir
echo "Processing Docker Registry templates..."
wild-compile-template-dir --clean ${DOCKER_REGISTRY_DIR}/kustomize.template ${DOCKER_REGISTRY_DIR}/kustomize
# Templates should already be compiled by wild-cluster-services-generate
echo "Using pre-compiled Docker Registry templates..."
if [ ! -d "${DOCKER_REGISTRY_DIR}/kustomize" ]; then
echo "Error: Compiled templates not found. Run 'wild-cluster-services-generate' first."
exit 1
fi
# Apply the docker registry manifests using kustomize
kubectl apply -k "${DOCKER_REGISTRY_DIR}/kustomize"

View File

@@ -9,9 +9,12 @@ fi
CLUSTER_SETUP_DIR="${WC_HOME}/setup/cluster"
EXTERNALDNS_DIR="${CLUSTER_SETUP_DIR}/externaldns"
# Process templates with wild-compile-template-dir
echo "Processing ExternalDNS templates..."
wild-compile-template-dir --clean ${EXTERNALDNS_DIR}/kustomize.template ${EXTERNALDNS_DIR}/kustomize
# Templates should already be compiled by wild-cluster-services-generate
echo "Using pre-compiled ExternalDNS templates..."
if [ ! -d "${EXTERNALDNS_DIR}/kustomize" ]; then
echo "Error: Compiled templates not found. Run 'wild-cluster-services-generate' first."
exit 1
fi
echo "Setting up ExternalDNS..."

View File

@@ -11,9 +11,12 @@ KUBERNETES_DASHBOARD_DIR="${CLUSTER_SETUP_DIR}/kubernetes-dashboard"
echo "Setting up Kubernetes Dashboard..."
# Process templates with wild-compile-template-dir
echo "Processing Dashboard templates..."
wild-compile-template-dir --clean ${KUBERNETES_DASHBOARD_DIR}/kustomize.template ${KUBERNETES_DASHBOARD_DIR}/kustomize
# Templates should already be compiled by wild-cluster-services-generate
echo "Using pre-compiled Dashboard templates..."
if [ ! -d "${KUBERNETES_DASHBOARD_DIR}/kustomize" ]; then
echo "Error: Compiled templates not found. Run 'wild-cluster-services-generate' first."
exit 1
fi
NAMESPACE="kubernetes-dashboard"

View File

@@ -11,9 +11,12 @@ LONGHORN_DIR="${CLUSTER_SETUP_DIR}/longhorn"
echo "Setting up Longhorn..."
# Process templates with wild-compile-template-dir
echo "Processing Longhorn templates..."
wild-compile-template-dir --clean ${LONGHORN_DIR}/kustomize.template ${LONGHORN_DIR}/kustomize
# Templates should already be compiled by wild-cluster-services-generate
echo "Using pre-compiled Longhorn templates..."
if [ ! -d "${LONGHORN_DIR}/kustomize" ]; then
echo "Error: Compiled templates not found. Run 'wild-cluster-services-generate' first."
exit 1
fi
# Apply Longhorn with kustomize to apply our customizations
kubectl apply -k ${LONGHORN_DIR}/kustomize/

View File

@@ -11,9 +11,12 @@ METALLB_DIR="${CLUSTER_SETUP_DIR}/metallb"
echo "Setting up MetalLB..."
# Process templates with gomplate
echo "Processing MetalLB templates..."
wild-compile-template-dir --clean ${METALLB_DIR}/kustomize.template ${METALLB_DIR}/kustomize
# Templates should already be compiled by wild-cluster-services-generate
echo "Using pre-compiled MetalLB templates..."
if [ ! -d "${METALLB_DIR}/kustomize" ]; then
echo "Error: Compiled templates not found. Run 'wild-cluster-services-generate' first."
exit 1
fi
echo "Deploying MetalLB..."
kubectl apply -k ${METALLB_DIR}/kustomize/installation

View File

@@ -12,9 +12,12 @@ NFS_DIR="${CLUSTER_SETUP_DIR}/nfs"
echo "Registering NFS server with Kubernetes cluster..."
# Process templates with wild-compile-template-dir
echo "Processing NFS templates..."
wild-compile-template-dir --clean ${NFS_DIR}/kustomize.template ${NFS_DIR}/kustomize
# Templates should already be compiled by wild-cluster-services-generate
echo "Using pre-compiled NFS templates..."
if [ ! -d "${NFS_DIR}/kustomize" ]; then
echo "Error: Compiled templates not found. Run 'wild-cluster-services-generate' first."
exit 1
fi
# Get NFS configuration from config.yaml
NFS_HOST=$(wild-config cloud.nfs.host) || exit 1

View File

@@ -24,9 +24,12 @@ kubectl wait --for condition=established crd/gatewayclasses.gateway.networking.k
kubectl wait --for condition=established crd/ingressroutes.traefik.io --timeout=60s
kubectl wait --for condition=established crd/middlewares.traefik.io --timeout=60s
# Process templates with wild-compile-template-dir
echo "Processing Traefik templates..."
wild-compile-template-dir --clean ${TRAEFIK_DIR}/kustomize.template ${TRAEFIK_DIR}/kustomize
# Templates should already be compiled by wild-cluster-services-generate
echo "Using pre-compiled Traefik templates..."
if [ ! -d "${TRAEFIK_DIR}/kustomize" ]; then
echo "Error: Compiled templates not found. Run 'wild-cluster-services-generate' first."
exit 1
fi
# Apply Traefik using kustomize
echo "Deploying Traefik..."

View File

@@ -14,7 +14,7 @@ metadata:
app.kubernetes.io/name: traefik
spec:
type: LoadBalancer
loadBalancerIP: { { .cluster.loadBalancerIP } }
loadBalancerIP: {{ .cluster.loadBalancerIp }}
selector:
app.kubernetes.io/instance: traefik-kube-system
app.kubernetes.io/name: traefik

View File

@@ -11,9 +11,12 @@ UTILS_DIR="${CLUSTER_SETUP_DIR}/utils"
echo "Setting up cluster utilities..."
# Process templates with wild-compile-template-dir
echo "Processing utils templates..."
wild-compile-template-dir --clean ${UTILS_DIR}/kustomize.template ${UTILS_DIR}/kustomize
# Templates should already be compiled by wild-cluster-services-generate
echo "Using pre-compiled utils templates..."
if [ ! -d "${UTILS_DIR}/kustomize" ]; then
echo "Error: Compiled templates not found. Run 'wild-cluster-services-generate' first."
exit 1
fi
echo "Applying utility manifests..."
kubectl apply -f ${UTILS_DIR}/kustomize/

View File

@@ -1,6 +1,5 @@
.wildcloud
secrets.yaml
.wildcloud/cache
.bots/*/sessions
backup/
.working
.claude

View File

@@ -9,25 +9,52 @@ export PATH="$WC_HOME/bin:$PATH"
# Install kubectl
if ! command -v kubectl &> /dev/null; then
echo "Error: kubectl is not installed. Installing."
echo "Installing kubectl"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
echo "$(cat kubectl.sha256) kubectl" | sha256sum --check
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
rm kubectl kubectl.sha256
echo "kubectl installed successfully."
fi
# Install talosctl
if ! command -v talosctl &> /dev/null; then
echo "Error: talosctl is not installed. Installing."
echo "Installing talosctl"
curl -sL https://talos.dev/install | sh
if [ $? -ne 0 ]; then
echo "Error installing talosctl. Please check the installation script."
exit 1
fi
echo "talosctl installed successfully."
fi
# Check if gomplate is installed
if ! command -v gomplate &> /dev/null; then
echo "Error: gomplate is not installed. Please install gomplate first."
echo "Visit: https://docs.gomplate.ca/installing/"
exit 1
echo "Installing gomplate"
curl -sSL https://github.com/hairyhenderson/gomplate/releases/latest/download/gomplate_linux-amd64 -o $HOME/.local/bin/gomplate
chmod +x $HOME/.local/bin/gomplate
echo "gomplate installed successfully."
fi
# Install kustomize
if ! command -v kustomize &> /dev/null; then
echo "Installing kustomize"
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
mv kustomize $HOME/.local/bin/
echo "kustomize installed successfully."
fi
## Install yq
if ! command -v yq &> /dev/null; then
echo "Installing yq"
VERSION=v4.45.4
BINARY=yq_linux_amd64
wget https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY}.tar.gz -O - | tar xz
mv ${BINARY} $HOME/.local/bin/yq
chmod +x $HOME/.local/bin/yq
rm yq.1
echo "yq installed successfully."
fi
KUBECONFIG=~/.kube/config
@@ -37,13 +64,15 @@ export KUBECONFIG
CLUSTER_NAME=$(wild-config cluster.name)
if [ -z "${CLUSTER_NAME}" ] || [ "${CLUSTER_NAME}" = "null" ]; then
echo "Error: cluster.name not set in config.yaml"
exit 1
fi
# Only try to use the kubectl context if it exists
if kubectl config get-contexts "${CLUSTER_NAME}" >/dev/null 2>&1; then
kubectl config use-context "${CLUSTER_NAME}"
echo "Using Kubernetes context: ${CLUSTER_NAME}"
# else
# echo "Kubernetes context '${CLUSTER_NAME}' not found, skipping context switch"
else
KUBE_CONTEXT="admin@${CLUSTER_NAME}"
CURRENT_KUBE_CONTEXT=$(kubectl config current-context)
if [ "${CURRENT_KUBE_CONTEXT}" != "${KUBE_CONTEXT}" ]; then
if kubectl config get-contexts | grep -q "${KUBE_CONTEXT}"; then
echo "Switching to kubernetes context ${KUBE_CONTEXT}"
else
echo "WARNING: Context ${KUBE_CONTEXT} does not exist."
# kubectl config set-context "${KUBE_CONTEXT}" --cluster="${CLUSTER_NAME}" --user=admin
fi
fi
fi