|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +# Colors for output |
| 6 | +RED='\033[0;31m' |
| 7 | +GREEN='\033[0;32m' |
| 8 | +YELLOW='\033[1;33m' |
| 9 | +BLUE='\033[0;34m' |
| 10 | +NC='\033[0m' # No Color |
| 11 | + |
| 12 | +# Directories that require external kustomize plugins |
| 13 | +# All kustomization.yaml files in this repository use standard kustomize functionality |
| 14 | +# and do not require any external plugins, so this array is empty. |
| 15 | +EXCLUDED_DIRS=( |
| 16 | +) |
| 17 | + |
| 18 | +# Check if kustomize is installed |
| 19 | +if ! command -v kustomize &> /dev/null; then |
| 20 | + echo -e "${RED}ERROR: kustomize is not installed${NC}" |
| 21 | + echo "" |
| 22 | + echo "Please install kustomize to run this check:" |
| 23 | + echo " - macOS: brew install kustomize" |
| 24 | + echo " - Linux: curl -s \"https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh\" | bash" |
| 25 | + echo " - Manual: https://kubectl.docs.kubernetes.io/installation/kustomize/" |
| 26 | + echo "" |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | + |
| 30 | +echo "Checking all kustomization.yaml files can build successfully..." |
| 31 | +echo "" |
| 32 | + |
| 33 | +ERRORS=0 |
| 34 | +CHECKED=0 |
| 35 | +SKIPPED=0 |
| 36 | + |
| 37 | +# Helper function to check if directory should be excluded |
| 38 | +is_excluded() { |
| 39 | + local dir="$1" |
| 40 | + for excluded in "${EXCLUDED_DIRS[@]}"; do |
| 41 | + if [ "$dir" = "$excluded" ]; then |
| 42 | + return 0 |
| 43 | + fi |
| 44 | + done |
| 45 | + return 1 |
| 46 | +} |
| 47 | + |
| 48 | +# Find all kustomization.yaml files |
| 49 | +kustomize_files=() |
| 50 | +while IFS= read -r file; do |
| 51 | + kustomize_files+=("$file") |
| 52 | +done < <(find . -name 'kustomization.yaml' -not -path '*/vendor/*' -not -path '*/.git/*' | sort) |
| 53 | + |
| 54 | +if [ ${#kustomize_files[@]} -eq 0 ]; then |
| 55 | + echo -e "${YELLOW}WARNING: No kustomization.yaml files found${NC}" |
| 56 | + exit 0 |
| 57 | +fi |
| 58 | + |
| 59 | +for kustomize_file in "${kustomize_files[@]}"; do |
| 60 | + dir=$(dirname "$kustomize_file") |
| 61 | + echo -n " $dir: " |
| 62 | + |
| 63 | + # Check if this directory requires external plugins |
| 64 | + if is_excluded "$dir"; then |
| 65 | + echo -e "${BLUE}SKIPPED${NC} (requires external plugins)" |
| 66 | + SKIPPED=$((SKIPPED + 1)) |
| 67 | + continue |
| 68 | + fi |
| 69 | + |
| 70 | + # Try to build the kustomization |
| 71 | + if kustomize build "$dir" > /dev/null 2>&1; then |
| 72 | + echo -e "${GREEN}OK${NC}" |
| 73 | + CHECKED=$((CHECKED + 1)) |
| 74 | + else |
| 75 | + echo -e "${RED}FAILED${NC}" |
| 76 | + echo -e "${YELLOW} Error details:${NC}" |
| 77 | + kustomize build "$dir" 2>&1 | sed 's/^/ /' |
| 78 | + echo "" |
| 79 | + ERRORS=$((ERRORS + 1)) |
| 80 | + CHECKED=$((CHECKED + 1)) |
| 81 | + fi |
| 82 | +done |
| 83 | + |
| 84 | +echo "" |
| 85 | +echo "Summary: Checked $CHECKED kustomization.yaml files, skipped $SKIPPED (require external plugins)" |
| 86 | + |
| 87 | +if [[ $ERRORS -eq 0 ]]; then |
| 88 | + echo -e "${GREEN}All kustomization files validated successfully!${NC}" |
| 89 | + exit 0 |
| 90 | +else |
| 91 | + echo -e "${RED}$ERRORS kustomization file(s) failed validation${NC}" |
| 92 | + exit 1 |
| 93 | +fi |
| 94 | + |
0 commit comments