Files
edge-gitops/bootstrap.sh
2026-05-05 11:15:49 -05:00

96 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Configuration
GITEA_URL="${GITEA_URL:-ssh://git@gitea.example.com/edge-gitops/edge-gitops.git}"
GITEA_BRANCH="${GITEA_BRANCH:-main}"
CLUSTER_NAME="${CLUSTER_NAME:-k3s-dgx}"
NAMESPACE="${NAMESPACE:-flux-system}"
echo -e "${GREEN}=== Edge GitOps Bootstrap Script ===${NC}"
echo ""
# Check prerequisites
echo -e "${YELLOW}Checking prerequisites...${NC}"
if ! command -v kubectl &> /dev/null; then
echo -e "${RED}kubectl is not installed${NC}"
exit 1
fi
if ! command -v flux &> /dev/null; then
echo -e "${RED}flux is not installed${NC}"
echo "Install from: https://fluxcd.io/flux/installation/"
exit 1
fi
if ! kubectl cluster-info &> /dev/null; then
echo -e "${RED}Cannot connect to kubernetes cluster${NC}"
exit 1
fi
echo -e "${GREEN}✓ Prerequisites met${NC}"
echo ""
# Check if Flux is already installed
if kubectl get namespace flux-system &> /dev/null; then
echo -e "${YELLOW}FluxCD is already installed${NC}"
read -p "Do you want to reinstall? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Exiting..."
exit 0
fi
echo -e "${YELLOW}Uninstalling existing FluxCD...${NC}"
flux uninstall --namespace=flux-system --silent || true
fi
# Bootstrap FluxCD
echo -e "${YELLOW}Bootstrapping FluxCD...${NC}"
flux bootstrap git \
--url="$GITEA_URL" \
--branch="$GITEA_BRANCH" \
--path="clusters/$CLUSTER_NAME" \
--namespace="$NAMESPACE" \
--components=source-controller,kustomize-controller,helm-controller,notification-controller \
--timeout=10m
echo -e "${GREEN}✓ FluxCD bootstrapped${NC}"
echo ""
# Wait for FluxCD to be ready
echo -e "${YELLOW}Waiting for FluxCD components to be ready...${NC}"
kubectl wait --for=condition=ready --timeout=300s \
-n "$NAMESPACE" \
deployment/source-controller \
deployment/kustomize-controller \
deployment/helm-controller \
deployment/notification-controller
echo -e "${GREEN}✓ FluxCD components ready${NC}"
echo ""
# Verify installation
echo -e "${YELLOW}Verifying installation...${NC}"
flux check
echo ""
echo -e "${GREEN}=== Bootstrap Complete ===${NC}"
echo ""
echo "Next steps:"
echo "1. Update the Gitea URL in clusters/k3s-dgx/flux-system/gotk-sync.yaml"
echo "2. Commit and push the changes to your repository"
echo "3. Monitor the sync: flux get all --all-namespaces"
echo ""
echo "Useful commands:"
echo " flux get all --all-namespaces # Show all Flux resources"
echo " flux logs # Show Flux logs"
echo " flux reconcile kustomization flux-system --with-source # Force sync"
echo ""