Skip to content

Ship pre-generated CRD JSON schemas as a release asset#4984

Closed
rdimitrov wants to merge 1 commit intomainfrom
ship-crd-schemas-as-release-asset
Closed

Ship pre-generated CRD JSON schemas as a release asset#4984
rdimitrov wants to merge 1 commit intomainfrom
ship-crd-schemas-as-release-asset

Conversation

@rdimitrov
Copy link
Copy Markdown
Member

Summary

Adds thv-crd-schemas.tar.gz to each release, containing per-CRD JSON Schemas + minimal YAML examples + an index.json with an inter-CRD reference graph. Generated at release time from the CRD manifests in deploy/charts/operator-crds/files/crds/.

Motivation

Consumers that want per-CRD JSON schemas — notably stacklok/docs-website, which renders them as reference pages — today run an equivalent Node script on their side after downloading the CRD manifests. Moving the extraction upstream:

  • Makes toolhive the canonical source of truth for how CRDs project into JSON Schemas (which fields to strip, how to heuristically identify inter-CRD references, etc.)
  • Lets consumers just gh release download rather than clone + extract on their side
  • Produces schemas suitable for validation by other tooling (IDE integrations, CI validators)

Part of a rollup with #4982 (CRD tarball) and #4983 (re-exported core schemas), documented from the docs-website side in PR #748.

What's in this PR

  • hack/extract-crd-schemas.mjs — 276-line script ported from docs-website. Takes --src <crds-dir> and --out <out-dir>. Produces <plural>.schema.json, <plural>.example.yaml, and index.json.
  • hack/package.json + hack/package-lock.json — single dep: yaml ^2.6.
  • .github/workflows/releaser.yml — Node setup step, npm ci, run the extractor, tar -czf build/thv-crd-schemas.tar.gz.
  • .goreleaser.yaml — adds build/thv-crd-schemas.tar.gz to release.extra_files.

Caveat: Node footprint in a Go repo

This PR introduces a small Node toolchain to hack/ — this repo was pure Go before. Three alternatives if that's undesirable:

  1. Defer / close this PR. The docs-website side can keep running the extractor locally after downloading the raw CRD tarball from #4982. Nothing else depends on this.
  2. Port the script to Go. ~300 lines of Go; heavier effort but fits the repo's toolchain.
  3. Explore controller-gen adjacent tooling. kubebuilder ships tools that produce JSON Schemas from CRDs; might be adoptable with less custom code.

Happy to take any of these directions. This PR is the smallest-diff version of the feature.

Test plan

Local smoke test:

cd hack && npm install
node extract-crd-schemas.mjs \
  --src ../deploy/charts/operator-crds/files/crds \
  --out /tmp/crds
ls /tmp/crds  # per-CRD .schema.json + .example.yaml + index.json

Verified locally: produces 12 schema pairs + index.json from the current CRD manifests.

🤖 Generated with Claude Code

Adds `thv-crd-schemas.tar.gz` to each release, containing per-CRD
JSON Schemas + minimal YAML examples + an `index.json` with an
inter-CRD reference graph. Generated at release time from the CRD
manifests in `deploy/charts/operator-crds/files/crds/`.

A new `hack/` package carries the extraction script. It adds a small
Node footprint to this repo (otherwise pure Go) — if you'd prefer a
Go port or a different tool (controller-gen has adjacent
capabilities), happy to rework or defer this PR.

Motivation: consumers that want per-CRD schemas — specifically
stacklok/docs-website, which renders them as reference pages — today
run an equivalent Node script on their side after downloading the
CRD manifests. Moving the extraction upstream:

  - Makes toolhive the source of truth for how CRDs project into
    JSON Schemas (strip-metadata rules, reference-graph heuristics).
  - Lets downstream consumers just `gh release download` instead of
    clone + Node-transform.
  - Produces schemas that can be validated against by tooling (IDE
    integrations, CI validators, etc.) without inventing their own
    extraction.

Part of a rollup on the docs-website side in
stacklok/docs-website#748, alongside
#4982 (CRD tarball) and
#4983 (re-exported core
schemas).

## What's new

  - `hack/extract-crd-schemas.mjs` (276 lines) — script ported from
    docs-website. Takes `--src <crds-dir>` and `--out <out-dir>`.
    Produces `<plural>.schema.json`, `<plural>.example.yaml`, and
    `index.json`.
  - `hack/package.json` + `hack/package-lock.json` — just `yaml ^2.6`.
  - `.github/workflows/releaser.yml` — Node setup + npm ci + run
    extractor + tar up outputs.
  - `.goreleaser.yaml` — `release.extra_files` entry for the tarball.

## Test plan

Local smoke test:

  cd hack && npm install
  node extract-crd-schemas.mjs \\
    --src ../deploy/charts/operator-crds/files/crds \\
    --out /tmp/crds
  ls /tmp/crds  # per-CRD .schema.json + .example.yaml + index.json

Verified locally: the script produces 12 schema pairs + index.json
from the current CRD manifests.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@rdimitrov rdimitrov requested a review from JAORMX as a code owner April 21, 2026 17:39
@github-actions github-actions Bot added the size/M Medium PR: 300-599 lines changed label Apr 21, 2026
@rdimitrov
Copy link
Copy Markdown
Member Author

Closing per discussion — introducing a Node toolchain to this Go repo for a docs-specific transform isn't the right trade-off. The CRD extraction will stay on the docs-website side, consuming the raw CRD tarball from #4982.

Thanks for your time.

@rdimitrov rdimitrov closed this Apr 21, 2026
@rdimitrov rdimitrov deleted the ship-crd-schemas-as-release-asset branch April 21, 2026 17:43
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.62%. Comparing base (63ee62a) to head (87cb8c3).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4984      +/-   ##
==========================================
- Coverage   69.63%   69.62%   -0.02%     
==========================================
  Files         552      552              
  Lines       55951    55951              
==========================================
- Hits        38962    38955       -7     
- Misses      13991    13999       +8     
+ Partials     2998     2997       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Medium PR: 300-599 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant