#!/usr/bin/env bash set -euo pipefail # Get the directory where the script is located SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" COMPONENTS_DIR="$(cd "${SCRIPT_DIR}/../components" && pwd)" # Colors for output GREEN='\033[0;32m' RED='\033[0;31m' NC='\033[0m' # No Color # Function to check if a deployment is ready check_deployment() { local namespace=$1 local deployment=$2 local description=$3 echo -n "Checking ${description}... " if kubectl get deployment -n "${namespace}" "${deployment}" >/dev/null 2>&1; then if kubectl wait --for=condition=available --timeout=5s deployment/"${deployment}" -n "${namespace}" >/dev/null 2>&1; then echo -e "${GREEN}OK${NC}" return 0 else echo -e "${RED}Not Ready${NC}" return 1 fi else echo -e "${RED}Not Found${NC}" return 1 fi } # Function to check post-install manifests check_post_install() { local component_dir=$1 local description=$2 echo -n "Checking ${description} post-install configurations... " if [ -n "$(find "${component_dir}/post-install" -type f \( -name '*.yaml' -o -name '*.yml' -o -name '*.json' \) 2>/dev/null)" ]; then if kubectl diff -f "${component_dir}/post-install/" >/dev/null 2>&1; then echo -e "${GREEN}OK${NC}" return 0 else echo -e "${RED}Out of sync${NC}" return 1 fi else echo -e "${GREEN}No post-install configs${NC}" return 0 fi } # Function to check if a daemon set is ready check_daemonset() { local namespace=$1 local daemonset=$2 local description=$3 echo -n "Checking ${description}... " if kubectl get daemonset -n "${namespace}" "${daemonset}" >/dev/null 2>&1; then if kubectl rollout status daemonset/"${daemonset}" -n "${namespace}" --timeout=5s >/dev/null 2>&1; then echo -e "${GREEN}OK${NC}" return 0 else echo -e "${RED}Not Ready${NC}" return 1 fi else echo -e "${RED}Not Found${NC}" return 1 fi } # Main validation process main() { local errors=0 echo "Validating platform components..." echo # Validate Cilium echo "Checking Cilium components:" check_daemonset kube-system cilium "Cilium CNI" || ((errors++)) check_deployment kube-system hubble-relay "Hubble Relay" || ((errors++)) check_deployment kube-system hubble-ui "Hubble UI" || ((errors++)) check_post_install "${COMPONENTS_DIR}/01-cilium" "Cilium" || ((errors++)) echo # Validate ArgoCD echo "Checking ArgoCD components:" check_deployment argocd argocd-server "ArgoCD Server" || ((errors++)) check_deployment argocd argocd-repo-server "ArgoCD Repo Server" || ((errors++)) check_deployment argocd argocd-applicationset-controller "ArgoCD ApplicationSet Controller" || ((errors++)) check_post_install "${COMPONENTS_DIR}/02-argocd" "ArgoCD" || ((errors++)) echo # Summary echo "================================================================" if [ "${errors}" -eq 0 ]; then echo -e "${GREEN}All components are running correctly!${NC}" exit 0 else echo -e "${RED}Found ${errors} component(s) with issues${NC}" echo "Check the component logs for more details:" echo " kubectl logs -n deployment/" exit 1 fi } # Run main function main "$@"