diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 5adbb4d..88f86bc 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -35,7 +35,7 @@ jobs: sudo mv kubectl /usr/local/bin/ # Install helmfile - curl -L https://github.com/helmfile/helmfile/releases/download/v0.156.0/helmfile_0.156.0_linux_amd64.tar.gz | tar xz + curl -L https://github.com/helmfile/helmfile/releases/download/v1.2.3/helmfile_1.2.3_linux_amd64.tar.gz | tar xz sudo mv helmfile /usr/local/bin/ echo "✅ All prerequisites installed successfully" diff --git a/.gitignore b/.gitignore index 2224aef..5b89781 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ -# Grounds Development Infrastructure (grounds-dev) .gitignore -# Ignores temporary files, build artifacts, and sensitive data - # Kubernetes and Helm artifacts *.kubeconfig *.kubeconfig.backup diff --git a/.shellcheckrc b/.shellcheckrc index 9f3a842..6d345a4 100644 --- a/.shellcheckrc +++ b/.shellcheckrc @@ -1,6 +1,3 @@ -# ShellCheck configuration for Grounds Development Infrastructure -# Ensures consistent shell script quality and security - # Disable specific warnings that are acceptable for this project disable=SC1091,SC2034,SC2155,SC2164 diff --git a/.yamllint b/.yamllint index b18234c..3a252c8 100644 --- a/.yamllint +++ b/.yamllint @@ -1,6 +1,3 @@ -# yamllint configuration for Grounds Development Infrastructure -# Ensures consistent YAML formatting across the repository - extends: default rules: diff --git a/Makefile b/Makefile index caaf993..8b80b7f 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,3 @@ -# Grounds Development Infrastructure (grounds-dev) Makefile -# Automation for local Kubernetes development environment -# Provides one-command setup and management of k3d cluster with PostgreSQL, Agones, and Open Match - SHELL := /usr/bin/env bash # Colors for fancy output @@ -109,16 +105,3 @@ test: ## Test the deployment @echo -e "$(BLUE)ℹ️ Testing dummy HTTP server...$(NC)" @curl -s http://localhost/demo || echo -e "$(YELLOW)⚠️ Dummy server not accessible (may still be starting)$(NC)" @echo -e "$(GREEN)✅ Tests completed$(NC)" - -# Utility targets -.PHONY: check-prereqs -check-prereqs: ## Check prerequisites - @echo -e "$(BLUE)ℹ️ Checking prerequisites...$(NC)" - @./scripts/install-prereqs.sh --check-only || true - -.PHONY: export-kubeconfig -export-kubeconfig: ## Export k3d cluster kubeconfig to ./kubeconfig - @echo -e "$(BLUE)ℹ️ Exporting kubeconfig...$(NC)" - @k3d kubeconfig get dev > kubeconfig - @echo -e "$(GREEN)✅ Kubeconfig exported to ./kubeconfig$(NC)" - @echo -e "$(CYAN)Use it with: export KUBECONFIG=\$$(pwd)/kubeconfig$(NC)" diff --git a/cluster/bootstrap.sh b/cluster/bootstrap.sh index 54a2fa1..744c939 100755 --- a/cluster/bootstrap.sh +++ b/cluster/bootstrap.sh @@ -1,42 +1,10 @@ #!/usr/bin/env bash -# Bootstrap script for Grounds Development Infrastructure (grounds-dev) k3d cluster -# Creates cluster, sets up namespaces, and configures Helm repositories set -euo pipefail -# Colors and emojis for fancy console output -readonly RED='\033[0;31m' -readonly GREEN='\033[0;32m' -readonly YELLOW='\033[1;33m' -readonly BLUE='\033[0;34m' -readonly PURPLE='\033[0;35m' -readonly CYAN='\033[0;36m' -readonly WHITE='\033[1;37m' -readonly NC='\033[0m' # No Color - -# Logging functions -log_info() { - echo -e "${BLUE}ℹ️ $1${NC}" -} - -log_success() { - echo -e "${GREEN}✅ $1${NC}" -} - -log_warning() { - echo -e "${YELLOW}⚠️ $1${NC}" -} - -log_error() { - echo -e "${RED}❌ $1${NC}" -} - -log_step() { - echo -e "${PURPLE}🚀 $1${NC}" -} - # Get script directory here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${here}/../scripts/common.sh" log_step "Starting Grounds Development Infrastructure cluster bootstrap..." @@ -56,20 +24,20 @@ if k3d cluster list | grep -q "^dev "; then retry_count=0 cluster_healthy=false - while [ $retry_count -lt $max_retries ]; do + while [[ "${retry_count}" -lt "${max_retries}" ]]; do if kubectl cluster-info >/dev/null 2>&1 && kubectl get nodes >/dev/null 2>&1; then cluster_healthy=true break fi retry_count=$((retry_count + 1)) - log_warning "Cluster health check failed (attempt $retry_count/$max_retries), retrying in 5 seconds..." + log_warning "Cluster health check failed (attempt ${retry_count}/${max_retries}), retrying in 5 seconds..." sleep 5 done - if [ "$cluster_healthy" = true ]; then + if [[ "${cluster_healthy}" = true ]]; then log_success "Cluster 'dev' is healthy, skipping creation" else - log_warning "Cluster 'dev' exists but is unhealthy after $max_retries attempts, recreating..." + log_warning "Cluster 'dev' exists but is unhealthy after ${max_retries} attempts, recreating..." k3d cluster delete dev log_step "Creating k3d cluster 'dev'..." k3d cluster create --config "${here}/k3d.yaml" @@ -86,33 +54,6 @@ log_info "Setting kubectl context to k3d-dev..." kubectl config use-context k3d-dev log_success "kubectl context set to k3d-dev" -# Export kubeconfig to project root -log_info "Exporting kubeconfig to ./kubeconfig..." -k3d kubeconfig get dev > "${here}/../kubeconfig" -log_success "Kubeconfig exported to ./kubeconfig" - -# Install kubeconfig for kubectx if available -if command -v kubectx >/dev/null 2>&1; then - log_info "kubectx detected, installing kubeconfig to ~/.kube/config..." - - # Ensure ~/.kube directory exists - mkdir -p "$HOME/.kube" - - # Merge kubeconfigs using kubectl's native merge capability - if [ -f "$HOME/.kube/config" ]; then - KUBECONFIG="$HOME/.kube/config:${here}/../kubeconfig" kubectl config view --flatten > /tmp/merged-config - mv /tmp/merged-config "$HOME/.kube/config" - log_success "k3d-dev context merged into ~/.kube/config" - else - cp "${here}/../kubeconfig" "$HOME/.kube/config" - log_success "kubeconfig installed to ~/.kube/config" - fi - - log_info "You can now use: kubectx k3d-dev" -else - log_info "kubectx not found, skipping kubeconfig installation to ~/.kube/" -fi - # Create namespaces log_info "Creating namespaces..." for ns in infra databases games api; do @@ -123,7 +64,7 @@ log_success "Namespaces created: infra, databases, games, api" # Load .env file if it exists env_file="${here}/../.env" -if [ -f "${env_file}" ]; then +if [[ -f "${env_file}" ]]; then log_info "Loading environment variables from .env file..." set -a # shellcheck source=/dev/null @@ -135,19 +76,9 @@ else fi # Create GHCR pull secret if credentials are provided -if [ -n "${GHCR_USERNAME:-}" ] && [ -n "${GHCR_TOKEN:-}" ]; then +if [[ -n "${GHCR_USERNAME:-}" && -n "${GHCR_TOKEN:-}" ]]; then log_step "Creating GHCR pull secret..." - # Create secret in default namespace - log_info "Creating ghcr-pull-secret in default namespace..." - kubectl create secret docker-registry ghcr-pull-secret \ - --docker-server=ghcr.io \ - --docker-username="${GHCR_USERNAME}" \ - --docker-password="${GHCR_TOKEN}" \ - --namespace=default \ - --dry-run=client -o yaml | kubectl apply -f - - log_success "GHCR pull secret created in default namespace" - # Function to patch service account with GHCR pull secret patch_service_account() { local namespace=$1 @@ -156,25 +87,25 @@ if [ -n "${GHCR_USERNAME:-}" ] && [ -n "${GHCR_TOKEN:-}" ]; then log_info "GHCR pull secret already configured in default service account for namespace: ${namespace}" else log_info "Patching default service account in namespace: ${namespace}" - # Create imagePullSecrets array if it doesn't exist - if ! kubectl get serviceaccount default -n "${namespace}" -o jsonpath='{.imagePullSecrets}' 2>/dev/null | grep -q "."; then + local pull_secrets_raw + pull_secrets_raw="$(kubectl get serviceaccount default -n "${namespace}" -o jsonpath='{.imagePullSecrets}' 2>/dev/null || true)" + if [[ -z "${pull_secrets_raw}" ]]; then + # Initialize imagePullSecrets so we can append entries later. kubectl patch serviceaccount default \ --namespace="${namespace}" \ --type=json \ - -p='[{"op": "add", "path": "/imagePullSecrets", "value": []}]' || true + -p='[{"op": "add", "path": "/imagePullSecrets", "value": [{"name": "ghcr-pull-secret"}]}]' + else + # Add the secret to the existing list. + kubectl patch serviceaccount default \ + --namespace="${namespace}" \ + --type=json \ + -p='[{"op": "add", "path": "/imagePullSecrets/-", "value": {"name": "ghcr-pull-secret"}}]' fi - # Add the secret to imagePullSecrets - kubectl patch serviceaccount default \ - --namespace="${namespace}" \ - --type=json \ - -p='[{"op": "add", "path": "/imagePullSecrets/-", "value": {"name": "ghcr-pull-secret"}}]' || true log_success "Default service account patched in namespace: ${namespace}" fi } - # Patch default service account in default namespace - patch_service_account default - # Create secret and patch service accounts in all namespaces for ns in infra databases games api; do log_info "Creating ghcr-pull-secret in namespace: ${ns}" @@ -194,44 +125,32 @@ else log_info "To enable GHCR authentication, set GHCR_USERNAME and GHCR_TOKEN in your .env file" fi -# Add Helm repositories -log_step "Adding Helm repositories..." -helm repo add bitnami https://charts.bitnami.com/bitnami -helm repo add agones https://agones.dev/chart/stable -log_success "Helm repositories added" - -# Update Helm repositories -log_info "Updating Helm repository cache..." -helm repo update -log_success "Helm repositories updated" - # Verify cluster is ready with retry log_info "Verifying cluster readiness..." max_retries=5 retry_count=0 cluster_ready=false -while [ $retry_count -lt $max_retries ]; do +while [[ "${retry_count}" -lt "${max_retries}" ]]; do if kubectl get nodes >/dev/null 2>&1; then cluster_ready=true break fi retry_count=$((retry_count + 1)) - log_warning "Cluster readiness check failed (attempt $retry_count/$max_retries), retrying in 10 seconds..." + log_warning "Cluster readiness check failed (attempt ${retry_count}/${max_retries}), retrying in 10 seconds..." sleep 10 done -if [ "$cluster_ready" = true ]; then +if [[ "${cluster_ready}" = true ]]; then kubectl get nodes log_success "Cluster is ready!" else - log_error "Cluster failed to become ready after $max_retries attempts" + log_error "Cluster failed to become ready after ${max_retries} attempts" exit 1 fi log_step "Bootstrap completed successfully! 🎉" log_info "Next steps:" -echo -e " ${CYAN}•${NC} Run ${WHITE}make up${NC} to deploy the full stack" -echo -e " ${CYAN}•${NC} Run ${WHITE}make status${NC} to check deployment status" -echo -e " ${CYAN}•${NC} Access services at ${WHITE}http://localhost${NC}" -echo -e " ${CYAN}•${NC} Use kubeconfig: ${WHITE}export KUBECONFIG=\$(pwd)/kubeconfig${NC}" +log_info "• Run 'make up' to deploy the full stack" +log_info "• Run 'make status' to check deployment status" +log_info "• Access services at 'http://localhost'" diff --git a/cluster/k3d.yaml b/cluster/k3d.yaml index 7e1e28d..75f2e77 100644 --- a/cluster/k3d.yaml +++ b/cluster/k3d.yaml @@ -1,7 +1,3 @@ -# k3d cluster configuration for local development -# This creates a lightweight Kubernetes cluster with 1 server + 2 agents -# Includes integrated registry and ingress port mapping for local development - apiVersion: k3d.io/v1alpha5 kind: Simple metadata: @@ -11,7 +7,6 @@ metadata: servers: 1 agents: 2 -# Use k3s version 1.34.1 for stability and compatibility image: rancher/k3s:v1.34.1-k3s1 # Port mappings for ingress traffic @@ -41,15 +36,6 @@ registries: username: ${DOCKER_USERNAME} password: ${DOCKER_PASSWORD} -# k3d and k3s options options: k3d: wait: true # Wait for cluster to be ready before returning - # k3s: - # extraArgs: - # # Keep ServiceLB enabled for LoadBalancer services - # - arg: --disable=servicelb=false - # nodeFilters: [server:0] - # # Keep Traefik enabled for ingress controller - # - arg: --disable=traefik=false - # nodeFilters: [server:0] diff --git a/helmfile.yaml b/helmfile.yaml index 971269a..6bfd6fe 100644 --- a/helmfile.yaml +++ b/helmfile.yaml @@ -1,7 +1,3 @@ -# Helmfile configuration for grounds-dev -# Orchestrates deployment of PostgreSQL and Agones -# Uses declarative approach with proper dependency management - # Helm repositories repositories: - name: bitnami diff --git a/scripts/common.sh b/scripts/common.sh new file mode 100644 index 0000000..467f95f --- /dev/null +++ b/scripts/common.sh @@ -0,0 +1,28 @@ +# Colors and emojis for log output +readonly RED='\033[0;31m' +readonly GREEN='\033[0;32m' +readonly YELLOW='\033[1;33m' +readonly BLUE='\033[0;34m' +readonly PURPLE='\033[0;35m' +readonly NC='\033[0m' # No Color + +# Logging functions +log_info() { + echo -e "${BLUE}ℹ️ $1${NC}" +} + +log_success() { + echo -e "${GREEN}✅ $1${NC}" +} + +log_warning() { + echo -e "${YELLOW}⚠️ $1${NC}" +} + +log_error() { + echo -e "${RED}❌ $1${NC}" +} + +log_step() { + echo -e "${PURPLE}🚀 $1${NC}" +} diff --git a/scripts/install-prereqs.sh b/scripts/install-prereqs.sh index 03264f8..8784930 100755 --- a/scripts/install-prereqs.sh +++ b/scripts/install-prereqs.sh @@ -1,114 +1,21 @@ #!/usr/bin/env bash -# Prerequisites installation script for Grounds Development Infrastructure -# Automatically installs missing dependencies for local Kubernetes development set -euo pipefail -# Colors and emojis for fancy console output -readonly RED='\033[0;31m' -readonly GREEN='\033[0;32m' -readonly YELLOW='\033[1;33m' -readonly BLUE='\033[0;34m' -readonly PURPLE='\033[0;35m' -readonly CYAN='\033[0;36m' -readonly WHITE='\033[1;37m' -readonly NC='\033[0m' # No Color +here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${here}/common.sh" -# Logging functions -log_info() { - echo -e "${BLUE}ℹ️ $1${NC}" -} - -log_success() { - echo -e "${GREEN}✅ $1${NC}" -} - -log_warning() { - echo -e "${YELLOW}⚠️ $1${NC}" -} - -log_error() { - echo -e "${RED}❌ $1${NC}" -} - -log_step() { - echo -e "${PURPLE}🚀 $1${NC}" -} - -# Check if command exists command_exists() { - command -v "$1" >/dev/null 2>&1 -} - -# Detect OS -detect_os() { - if [[ "${OSTYPE}" == "linux-gnu"* ]]; then - local has_apt has_yum has_pacman - command_exists apt-get - has_apt=$? - command_exists yum - has_yum=$? - command_exists pacman - has_pacman=$? - - if [[ "${has_apt}" -eq 0 ]]; then - echo "ubuntu" - elif [[ "${has_yum}" -eq 0 ]]; then - echo "rhel" - elif [[ "${has_pacman}" -eq 0 ]]; then - echo "arch" - else - echo "linux" - fi - elif [[ "${OSTYPE}" == "darwin"* ]]; then - echo "macos" - elif [[ "${OSTYPE}" == "msys" ]] || [[ "${OSTYPE}" == "cygwin" ]]; then - echo "windows" + if command -v "$1" >/dev/null 2>&1; then + echo 0 else - echo "unknown" + echo 1 fi } -# Install Docker -install_docker() { - local os="$1" - log_info "Installing Docker..." - - case "${os}" in - "ubuntu") - local docker_exists - command_exists docker - docker_exists=$? - if [[ "${docker_exists}" -ne 0 ]]; then - curl -fsSL https://get.docker.com | sh - sudo usermod -aG docker "${USER}" - log_success "Docker installed. Please log out and back in for group changes to take effect." - else - log_success "Docker already installed" - fi - ;; - "macos") - local docker_exists - command_exists docker - docker_exists=$? - if [[ "${docker_exists}" -ne 0 ]]; then - log_warning "Please install Docker Desktop for macOS from https://www.docker.com/products/docker-desktop" - log_info "Or install via Homebrew: brew install --cask docker" - else - log_success "Docker already installed" - fi - ;; - *) - log_warning "Please install Docker manually for your OS" - ;; - esac -} - -# Install k3d install_k3d() { local k3d_exists - command_exists k3d - k3d_exists=$? + k3d_exists=$(command_exists k3d) if [[ "${k3d_exists}" -ne 0 ]]; then log_info "Installing k3d..." curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash @@ -118,11 +25,9 @@ install_k3d() { fi } -# Install kubectl install_kubectl() { local kubectl_exists - command_exists kubectl - kubectl_exists=$? + kubectl_exists=$(command_exists kubectl) if [[ "${kubectl_exists}" -ne 0 ]]; then log_info "Installing kubectl..." local kubectl_version=$(curl -L -s https://dl.k8s.io/release/stable.txt) @@ -135,11 +40,9 @@ install_kubectl() { fi } -# Install Helm install_helm() { local helm_exists - command_exists helm - helm_exists=$? + helm_exists=$(command_exists helm) if [[ "${helm_exists}" -ne 0 ]]; then log_info "Installing Helm..." curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash @@ -149,23 +52,23 @@ install_helm() { fi } -# Install Helmfile install_helmfile() { local helmfile_exists - command_exists helmfile - helmfile_exists=$? + helmfile_exists=$(command_exists helmfile) if [[ "${helmfile_exists}" -ne 0 ]]; then log_info "Installing Helmfile..." - local helmfile_version="v0.156.0" - curl -L "https://github.com/helmfile/helmfile/releases/download/${helmfile_version}/helmfile_${helmfile_version#v}_linux_amd64.tar.gz" | tar xz - sudo mv helmfile /usr/local/bin/ + local helmfile_version="v1.2.3" + local tmp_dir + tmp_dir="$(mktemp -d)" + curl -L "https://github.com/helmfile/helmfile/releases/download/${helmfile_version}/helmfile_${helmfile_version#v}_linux_amd64.tar.gz" | tar -xz -C "${tmp_dir}" + sudo mv "${tmp_dir}/helmfile" /usr/local/bin/ + rm -rf "${tmp_dir}" log_success "Helmfile installed" else log_success "Helmfile already installed" fi } -# Install DevSpace install_devspace() { if ! command -v devspace >/dev/null 2>&1; then log_info "Installing DevSpace..." @@ -180,84 +83,18 @@ install_devspace() { fi } -# Check Docker daemon check_docker_daemon() { if ! docker info >/dev/null 2>&1; then - log_warning "Docker daemon is not running. Please start Docker and try again." - log_info "On Linux: sudo systemctl start docker" - log_info "On macOS: Start Docker Desktop" + log_warning "Docker daemon is not running. Please install or start Docker and try again." return 1 fi return 0 } -# Check prerequisites only -check_prereqs() { - log_info "Checking prerequisites..." - local missing=() - local docker_exists k3d_exists kubectl_exists helm_exists helmfile_exists devspace_exists - - command_exists docker - docker_exists=$? - command_exists k3d - k3d_exists=$? - command_exists kubectl - kubectl_exists=$? - command_exists helm - helm_exists=$? - command_exists helmfile - helmfile_exists=$? - command_exists devspace - devspace_exists=$? - - if [[ "${docker_exists}" -ne 0 ]]; then - missing+=("docker") - fi - - if [[ "${k3d_exists}" -ne 0 ]]; then - missing+=("k3d") - fi - - if [[ "${kubectl_exists}" -ne 0 ]]; then - missing+=("kubectl") - fi - - if [[ "${helm_exists}" -ne 0 ]]; then - missing+=("helm") - fi - - if [[ "${helmfile_exists}" -ne 0 ]]; then - missing+=("helmfile") - fi - - if [[ "${devspace_exists}" -ne 0 ]]; then - missing+=("devspace") - fi - - if [[ ${#missing[@]} -eq 0 ]]; then - log_success "All prerequisites found" - return 0 - else - log_warning "Missing prerequisites: ${missing[*]}" - return 1 - fi -} - -# Main installation function main() { - # Check if --check-only flag is provided - if [[ "${1:-}" == "--check-only" ]]; then - check_prereqs - return $? - fi - log_step "Checking and installing prerequisites for Grounds Development Infrastructure..." - local os=$(detect_os) - log_info "Detected OS: ${os}" - # Install prerequisites - install_docker "${os}" install_k3d install_kubectl install_helm diff --git a/scripts/kubehelpers.sh b/scripts/kubehelpers.sh index 27f76ab..17998b3 100755 --- a/scripts/kubehelpers.sh +++ b/scripts/kubehelpers.sh @@ -1,41 +1,10 @@ #!/usr/bin/env bash -# Kubernetes helper utilities with fancy console output -# Provides common kubectl operations with colored logging set -euo pipefail -# Colors and emojis for fancy console output -readonly RED='\033[0;31m' -readonly GREEN='\033[0;32m' -readonly YELLOW='\033[1;33m' -readonly BLUE='\033[0;34m' -readonly PURPLE='\033[0;35m' -readonly CYAN='\033[0;36m' -readonly WHITE='\033[1;37m' -readonly NC='\033[0m' # No Color +here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${here}/common.sh" -# Logging functions -log_info() { - echo -e "${BLUE}ℹ️ $1${NC}" -} - -log_success() { - echo -e "${GREEN}✅ $1${NC}" -} - -log_warning() { - echo -e "${YELLOW}⚠️ $1${NC}" -} - -log_error() { - echo -e "${RED}❌ $1${NC}" -} - -log_step() { - echo -e "${PURPLE}🚀 $1${NC}" -} - -# Check if kubectl is available check_kubectl() { if ! command -v kubectl >/dev/null 2>&1; then log_error "kubectl is not installed or not in PATH" @@ -43,8 +12,7 @@ check_kubectl() { fi } -# Check cluster connectivity -check_cluster() { +check_cluster_connectivity() { log_info "Checking cluster connectivity..." if ! kubectl cluster-info >/dev/null 2>&1; then log_error "Cannot connect to Kubernetes cluster" @@ -53,21 +21,22 @@ check_cluster() { log_success "Cluster is accessible" } -# Get cluster status get_cluster_status() { log_step "Getting cluster status..." - echo -e "\n${CYAN}📊 Cluster Nodes:${NC}" + echo "" + log_info "📊 Cluster Nodes:" kubectl get nodes -o wide - echo -e "\n${CYAN}📦 All Pods:${NC}" + echo "" + log_info "📦 All Pods:" kubectl get pods -A - echo -e "\n${CYAN}🔧 Services:${NC}" + echo "" + log_info "🔧 Services:" kubectl get services -A } -# Wait for pods to be ready wait_for_pods() { local namespace="$1" local selector="$2" @@ -84,7 +53,6 @@ wait_for_pods() { fi } -# Check namespace exists check_namespace() { local namespace="$1" @@ -97,7 +65,6 @@ check_namespace() { fi } -# Get pod logs get_pod_logs() { local namespace="$1" local pod="$2" @@ -107,7 +74,6 @@ get_pod_logs() { kubectl logs -n "${namespace}" "${pod}" --tail="${lines}" } -# Port forward helper port_forward() { local namespace="$1" local service="$2" @@ -118,12 +84,11 @@ port_forward() { kubectl port-forward -n "${namespace}" "service/${service}" "${local_port}:${service_port}" } -# Main function for script usage main() { case "${1:-help}" in "status") check_kubectl - check_cluster + check_cluster_connectivity get_cluster_status ;; "wait-pods") @@ -155,8 +120,8 @@ main() { port_forward "$2" "$3" "$4" "$5" ;; "help"|*) - echo -e "${WHITE}Kubernetes Helper Script${NC}" - echo -e "${CYAN}Usage:${NC}" + log_info "Kubernetes Helper Script" + log_info "Usage:" echo " $0 status - Get cluster status" echo " $0 wait-pods - Wait for pods to be ready" echo " $0 check-ns - Check if namespace exists" diff --git a/scripts/wait-for-crds.sh b/scripts/wait-for-crds.sh index 85d1a05..dab55e3 100755 --- a/scripts/wait-for-crds.sh +++ b/scripts/wait-for-crds.sh @@ -1,47 +1,19 @@ #!/usr/bin/env bash -# Wait for Agones CRDs to be ready -# Provides fancy console output with spinner and progress indicators set -euo pipefail -# Colors and emojis for fancy console output -readonly RED='\033[0;31m' -readonly GREEN='\033[0;32m' -readonly YELLOW='\033[1;33m' -readonly BLUE='\033[0;34m' -readonly PURPLE='\033[0;35m' -readonly CYAN='\033[0;36m' -readonly WHITE='\033[1;37m' -readonly NC='\033[0m' # No Color +here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${here}/common.sh" # Spinner characters spinner_chars=("⠋" "⠙" "⠹" "⠸" "⠼" "⠴" "⠦" "⠧" "⠇" "⠏") spinner_index=0 -# Logging functions -log_info() { - echo -e "${BLUE}ℹ️ $1${NC}" -} - -log_success() { - echo -e "${GREEN}✅ $1${NC}" -} - -log_warning() { - echo -e "${YELLOW}⚠️ $1${NC}" -} - -log_error() { - echo -e "${RED}❌ $1${NC}" -} - -# Spinner function show_spinner() { - printf "\r%s%s%s %s" "${PURPLE}" "${spinner_chars[${spinner_index}]}" "${NC}" "$1" + printf "\r%s %s" "${spinner_chars[${spinner_index}]}" "$1" spinner_index=$(( (spinner_index + 1) % ${#spinner_chars[@]} )) } -# Wait for CRD function wait_for_crd() { local crd="$1" local timeout="${2:-60}" @@ -64,7 +36,6 @@ wait_for_crd() { return 1 } -# Main execution main() { log_info "Starting CRD readiness check..." diff --git a/values/agones.values.yaml b/values/agones.values.yaml index 30ecad9..51f0646 100644 --- a/values/agones.values.yaml +++ b/values/agones.values.yaml @@ -15,8 +15,10 @@ agones: service: http: port: 10443 + targetPort: 8443 grpc: port: 10444 + targetPort: 8444 # Controller configuration controller: