Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/kustomize-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Kustomize Validation

on:
pull_request:
branches:
- main

permissions:
contents: read

jobs:
kustomize-validation:
name: Validate Kustomization Files
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Kustomize
run: |
# Download with retries to prevent flaky CI failures
MAX_ATTEMPTS=3
ATTEMPT=1

while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do
echo "Attempt $ATTEMPT of $MAX_ATTEMPTS: Downloading kustomize install script..."
if curl -fsSL --retry 3 --retry-delay 2 "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash; then
echo "Successfully downloaded and installed kustomize"
break
else
echo "Failed to install kustomize"
if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then
echo "All attempts failed"
exit 1
fi
echo "Waiting 5 seconds before retry..."
sleep 5
ATTEMPT=$((ATTEMPT + 1))
fi
done

sudo mv kustomize /usr/local/bin/
kustomize version

- name: Validate Kustomization Files
run: make test-kustomize

4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ test-upgrade-e2e: build-e2e-all
test-must-gather-e2e: build-must-gather-e2e
hack/run-test-must-gather-e2e.sh

.PHONY: test-kustomize
test-kustomize: ## Validate all kustomization.yaml files can build successfully
hack/test-kustomize.sh

# intentional left out:
# api/, because autogeneration
# cmd/, because kubebuilder scaffolding
Expand Down
94 changes: 94 additions & 0 deletions hack/test-kustomize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/bin/bash

set -e

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

# Directories that require external kustomize plugins
# All kustomization.yaml files in this repository use standard kustomize functionality
# and do not require any external plugins, so this array is empty.
EXCLUDED_DIRS=(
)

# Check if kustomize is installed
if ! command -v kustomize &> /dev/null; then
echo -e "${RED}ERROR: kustomize is not installed${NC}"
echo ""
echo "Please install kustomize to run this check:"
echo " - macOS: brew install kustomize"
echo " - Linux: curl -s \"https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh\" | bash"
echo " - Manual: https://kubectl.docs.kubernetes.io/installation/kustomize/"
echo ""
exit 1
fi

echo "Checking all kustomization.yaml files can build successfully..."
echo ""

ERRORS=0
CHECKED=0
SKIPPED=0

# Helper function to check if directory should be excluded
is_excluded() {
local dir="$1"
for excluded in "${EXCLUDED_DIRS[@]}"; do
if [ "$dir" = "$excluded" ]; then
return 0
fi
done
return 1
}

# Find all kustomization.yaml files
kustomize_files=()
while IFS= read -r file; do
kustomize_files+=("$file")
done < <(find . -name 'kustomization.yaml' -not -path '*/vendor/*' -not -path '*/.git/*' | sort)

if [ ${#kustomize_files[@]} -eq 0 ]; then
echo -e "${YELLOW}WARNING: No kustomization.yaml files found${NC}"
exit 0
fi

for kustomize_file in "${kustomize_files[@]}"; do
dir=$(dirname "$kustomize_file")
echo -n " $dir: "

# Check if this directory requires external plugins
if is_excluded "$dir"; then
echo -e "${BLUE}SKIPPED${NC} (requires external plugins)"
SKIPPED=$((SKIPPED + 1))
continue
fi

# Try to build the kustomization
if kustomize build "$dir" > /dev/null 2>&1; then
echo -e "${GREEN}OK${NC}"
CHECKED=$((CHECKED + 1))
else
echo -e "${RED}FAILED${NC}"
echo -e "${YELLOW} Error details:${NC}"
kustomize build "$dir" 2>&1 | sed 's/^/ /'
echo ""
ERRORS=$((ERRORS + 1))
CHECKED=$((CHECKED + 1))
fi
done

echo ""
echo "Summary: Checked $CHECKED kustomization.yaml files, skipped $SKIPPED (require external plugins)"

if [[ $ERRORS -eq 0 ]]; then
echo -e "${GREEN}All kustomization files validated successfully!${NC}"
exit 0
else
echo -e "${RED}$ERRORS kustomization file(s) failed validation${NC}"
exit 1
fi

Loading