Ship pre-generated CRD JSON schemas as a release asset#4984
Closed
Ship pre-generated CRD JSON schemas as a release asset#4984
Conversation
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>
7 tasks
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. |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
thv-crd-schemas.tar.gzto each release, containing per-CRD JSON Schemas + minimal YAML examples + anindex.jsonwith an inter-CRD reference graph. Generated at release time from the CRD manifests indeploy/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:
gh release downloadrather than clone + extract on their sidePart 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, andindex.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— addsbuild/thv-crd-schemas.tar.gztorelease.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:Happy to take any of these directions. This PR is the smallest-diff version of the feature.
Test plan
Local smoke test:
Verified locally: produces 12 schema pairs +
index.jsonfrom the current CRD manifests.🤖 Generated with Claude Code