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

3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ ocp-doc-check: ## Download and run ocp-doc-checker against markdown files
rm -f ./$$BINARY_NAME; \
echo "ocp-doc-check completed"

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

ci-validate: lintCheck check-reference-core check-reference-ran check-reference-hub

.PHONY: check-reference-core
Expand Down
112 changes: 112 additions & 0 deletions hack/test-kustomize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/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 OpenShift ZTP external kustomize plugins
# These plugins (PolicyGenerator, ClusterInstance, SiteConfig, PolicyGenTemplate) are distributed
# via Red Hat container images and are designed to run in OpenShift ArgoCD with ACM/MCE installed.
#
# These plugins come from:
# - registry.redhat.io/openshift4/ztp-site-generate-rhel8 (ClusterInstance, SiteConfig)
# - registry.redhat.io/rhacm2/multicluster-operators-subscription-rhel9 (PolicyGenerator)
#
# They require:
# - KUSTOMIZE_PLUGIN_HOME environment variable
# - kustomize --enable-alpha-plugins flag
# - The plugin binaries extracted from the container images
#
# These can only be validated in an OpenShift cluster environment with ZTP tooling installed.
# Standard kustomize cannot process them without these prerequisites.
EXCLUDED_DIRS=(
"./telco-core/configuration"
"./telco-ran/configuration/argocd/example/acmpolicygenerator"
"./telco-ran/configuration/argocd/example/clusterinstance"
"./telco-ran/configuration/argocd/example/image-based-upgrades"
"./telco-ran/configuration/argocd/example/policygentemplates"
"./telco-ran/configuration/argocd/example/siteconfig"
)

# 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 '*/venv/*' -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