784c3b5de1
## Summary - New `ci/generate-schemas.sh` script that generates JSON schemas from three sources: 1. Live cluster CRDs via `kubectl get crds` 2. Offline CRD manifests (ArgoCD v3.3.2, Gateway API v1.5.1) 3. Kubernetes v1.33.7 swagger spec for native types - Schemas follow Datree catalog convention (`<group>/<Kind>_<version>.json`) - `validate-apps.sh` and `validate-clusters.sh` check local schemas first, falling back to remote - Fixes TLSRoute (and other CRD) schema validation failures in kubeconform ## Sources - ArgoCD: `artifactapi.../argoproj/argo-cd/refs/tags/v3.3.2/manifests/ha/install.yaml` - Gateway API: `artifactapi.../kubernetes-sigs/gateway-api/releases/download/v1.5.1/standard-install.yaml` - Kubernetes: `artifactapi.../kubernetes/kubernetes/refs/tags/v1.33.7/api/openapi-spec/swagger.json` Reviewed-on: #212 Co-authored-by: Ben Vincent <ben@unkin.net> Co-committed-by: Ben Vincent <ben@unkin.net>
51 lines
1.8 KiB
Bash
Executable File
51 lines
1.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
SCHEMA_DIR="${1:-schemas}"
|
|
rm -rf "$SCHEMA_DIR"
|
|
mkdir -p "$SCHEMA_DIR"
|
|
|
|
echo "==> Fetching CRDs from cluster..." >&2
|
|
kubectl get crds -o json | python3 -c "
|
|
import sys, json, os
|
|
|
|
def write_schema(schema, schema_dir, group, kind, version):
|
|
def strip_descriptions(obj):
|
|
if isinstance(obj, dict):
|
|
return {k: strip_descriptions(v) for k, v in obj.items() if k != 'description'}
|
|
if isinstance(obj, list):
|
|
return [strip_descriptions(i) for i in obj]
|
|
return obj
|
|
|
|
schema = strip_descriptions(schema)
|
|
group_dir = os.path.join(schema_dir, group)
|
|
os.makedirs(group_dir, exist_ok=True)
|
|
fname = f'{kind}_{version}.json'.lower()
|
|
with open(os.path.join(group_dir, fname), 'w') as f:
|
|
json.dump(schema, f, indent=2, sort_keys=True)
|
|
f.write('\n')
|
|
print(f' Generated: {group}/{fname}', file=sys.stderr)
|
|
|
|
data = json.load(sys.stdin)
|
|
for crd in data.get('items', []):
|
|
spec = crd.get('spec', {})
|
|
group = spec.get('group', '')
|
|
kind = spec.get('names', {}).get('kind', '')
|
|
for ver in spec.get('versions', []):
|
|
version = ver.get('name', '')
|
|
openapi = ver.get('schema', {}).get('openAPIV3Schema', {})
|
|
if not openapi:
|
|
continue
|
|
schema = dict(openapi)
|
|
schema['\$schema'] = 'http://json-schema.org/draft-07/schema#'
|
|
schema['type'] = 'object'
|
|
schema.setdefault('properties', {})
|
|
schema['properties'].setdefault('apiVersion', {'type': 'string'})
|
|
schema['properties'].setdefault('kind', {'type': 'string'})
|
|
schema['properties'].setdefault('metadata', {'type': 'object'})
|
|
write_schema(schema, '$SCHEMA_DIR', group, kind, version)
|
|
"
|
|
|
|
total=$(find "$SCHEMA_DIR" -name '*.json' | wc -l)
|
|
echo "==> Schema generation complete: $total schemas in $SCHEMA_DIR" >&2
|