Files
foundation/scripts/validate.sh
Morten Olsen 038e160376 init
2025-11-25 20:13:58 +01:00

87 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check if tools are installed
check_tool() {
if ! command -v "$1" &> /dev/null; then
echo -e "${RED}$1 is not installed${NC}"
echo " Install with: make install-tools"
return 1
fi
return 0
}
echo "🔍 Running validation checks..."
# Check required tools
MISSING_TOOLS=0
check_tool kubeconform || MISSING_TOOLS=1
check_tool yamllint || MISSING_TOOLS=1
check_tool kustomize || MISSING_TOOLS=1
if [ $MISSING_TOOLS -eq 1 ]; then
exit 1
fi
# Validate Kubernetes manifests
echo -e "\n${YELLOW}Validating Kubernetes manifests...${NC}"
VALIDATION_FAILED=0
# Validate individual YAML files (skip CRDs that kubeconform doesn't handle well)
for file in apps/*.yaml storage/*.yaml; do
if [ -f "$file" ]; then
# Skip kustomization files as they're not Kubernetes resources
if [[ "$file" == *"kustomization.yaml" ]]; then
continue
fi
if ! kubeconform -strict -skip Certificate,Issuer,CertificateRequest,ClusterIssuer "$file" 2>&1; then
echo -e "${RED}✗ Validation failed: $file${NC}"
VALIDATION_FAILED=1
else
echo -e "${GREEN}$file${NC}"
fi
fi
done
# Validate Kustomize builds
echo -e "\n${YELLOW}Validating Kustomize configurations...${NC}"
if ! kustomize build apps/ > /dev/null 2>&1; then
echo -e "${RED}✗ Kustomize build failed: apps/${NC}"
VALIDATION_FAILED=1
else
echo -e "${GREEN}✓ apps/kustomization.yaml${NC}"
fi
if ! kustomize build storage/ > /dev/null 2>&1; then
echo -e "${RED}✗ Kustomize build failed: storage/${NC}"
VALIDATION_FAILED=1
else
echo -e "${GREEN}✓ storage/kustomization.yaml${NC}"
fi
# Lint YAML files
echo -e "\n${YELLOW}Linting YAML files...${NC}"
if ! yamllint -c .yamllint apps/ storage/; then
echo -e "${RED}✗ YAML linting failed${NC}"
VALIDATION_FAILED=1
else
echo -e "${GREEN}✓ YAML linting passed${NC}"
fi
# Summary
echo ""
if [ $VALIDATION_FAILED -eq 0 ]; then
echo -e "${GREEN}✓ All validation checks passed!${NC}"
exit 0
else
echo -e "${RED}✗ Some validation checks failed${NC}"
exit 1
fi