24 lines
798 B
Bash
Executable File
24 lines
798 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# Extract OpenAPI v3 schemas from CRD definitions in all kustomize overlays
|
|
# and write JSON schema files to ci/crd-schemas/ for kubeconform validation.
|
|
#
|
|
# Run this script whenever CRD versions change, then commit the output.
|
|
# Usage: ci/generate-crd-schemas.sh [output-dir]
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
OUTPUT_DIR="${1:-${SCRIPT_DIR}/crd-schemas}"
|
|
mkdir -p "$OUTPUT_DIR"
|
|
|
|
total=0
|
|
|
|
while IFS= read -r -d "" k; do
|
|
dir="$(dirname "$k")"
|
|
n=$(kustomize build --enable-helm "$dir" 2>/dev/null \
|
|
| "$SCRIPT_DIR/generate-crd-schemas.py" "$OUTPUT_DIR") || continue
|
|
total=$((total + n))
|
|
done < <(find apps/overlays clusters -name kustomization.yaml -print0 | sort -z)
|
|
|
|
echo "Generated ${total} schema(s) in ${OUTPUT_DIR}" >&2
|