Skip to content

feat(schema): config schema generation pipeline (foundation)#362

Draft
viniciusdc wants to merge 2 commits into
mainfrom
feat/config-schema-gen
Draft

feat(schema): config schema generation pipeline (foundation)#362
viniciusdc wants to merge 2 commits into
mainfrom
feat/config-schema-gen

Conversation

@viniciusdc

@viniciusdc viniciusdc commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Refs

Status

Draft — JSON Schema pipeline + CI drift gate are live. YAML reference output, godoc cleanup, and ARCHITECTURE.md updates land on this branch before the PR moves out of Draft.

What's in this PR

  • provider.Provider and dnsprovider.DNSProvider interfaces gain ConfigType() reflect.Type. One-line implementations on all 7 registered providers (aws, gcp, azure, hetzner, local, existing, cloudflare).
  • pkg/nic/config_types.go — new (*Client).RegisteredConfigTypes(ctx) accessor + ConfigTypes struct. Walks the registry; no hard-coded provider list anywhere in the pipeline.
  • pkg/configschema/ — wraps github.com/invopop/jsonschema. Generate(ctx, t, FormatJSON, opts) produces JSON Schema with godoc descriptions extracted via Reflector.AddGoComments. Configured to read yaml tags (not json), package-qualify $defs keys to avoid name collisions (e.g. aws.Config vs longhorn.Config), and emit additionalProperties: false. FormatYAML is stubbed.
  • cmd/schemagen/ — writes schemas/manifest.json, schemas/nebari-config.json, schemas/providers/<name>.json. Walks pkg/ to collect package paths for godoc extraction. Flags: -out, -providers, -pkg-root, -version.
  • schemas/ committed in-tree (~28KB total). 6 cluster providers + 1 DNS provider + top-level nebari-config + manifest.
  • Makefilemake schemas target.
  • .github/workflows/schemas.yml — drift-check on PRs and main pushes, paths-filtered to config / provider / schema-gen files. Fails on divergence with a clear "run make schemas locally" message. No auto-commit (kubebuilder CRD-regen pattern).

Planned follow-ups

Best-guess ordering; may shift as the work progresses.

  • goccy/go-yaml CommentMap integration for FormatYAML (the human-readable reference document).
  • AWS provider godoc cleanup (the curated content migration from examples/aws-config.yaml).
  • ARCHITECTURE.md + WALKTHROUGH.md updates (directory map + new "Single Provider Registry" subsection).
  • Remaining provider godoc cleanup (hetzner is already gold-standard; local + existing need light review).

Once those land the PR moves out of Draft.

Docs-site consumption

Docusaurus fetches schemas/manifest.json from raw.githubusercontent.com/nebari-dev/nebari-infrastructure-core/<ref>/schemas/manifest.json, then each referenced schema. Tagged releases give versioned docs for free; main can be surfaced as an "experimental" / "unstable" track.

Test plan

  • go build ./... clean
  • make schemas regenerates schemas/ with no drift on a clean tree
  • go run ./cmd/schemagen enumerates all 7 registered providers via the registry
  • go run ./cmd/schemagen -providers aws,hetzner narrows correctly
  • Generated schemas/providers/hetzner.json includes field-level godoc as description and per-package-qualified $defs keys
  • CI: schemas/ drift check passes on this push (verifying the gate)
  • CI: deliberately modify a Config field tag without running make schemas, push, confirm CI fails with the expected message

… accessor

Establishes the architectural foundation for the upcoming JSON Schema +
commented YAML reference pipeline (consumed by nebari-docs). The actual
generation logic lands in follow-up commits on this branch.

What this commit changes:

- pkg/provider/provider.go: adds `ConfigType() reflect.Type` to the
  Provider interface. One-line implementations on all 6 cluster
  providers (aws, gcp, azure, hetzner, local, existing).
- pkg/dnsprovider/provider.go: same addition to DNSProvider, with the
  one-line implementation on cloudflare.
- pkg/nic/config_types.go: adds `(*Client).RegisteredConfigTypes(ctx)`
  returning a ConfigTypes struct keyed by provider name. Walks the
  registry; no hard-coded provider list.
- pkg/configschema/: skeleton package with Format constants, Options
  struct, and Generate signature. Body returns "not yet implemented"
  for now; the invopop/jsonschema + goccy CommentMap wiring lands in
  the next commit.
- cmd/schemagen/: skeleton binary that wires up nic.Client →
  RegisteredConfigTypes → configschema.Generate. Currently does a
  dry-run discovery print so reviewers can see the registry-driven
  enumeration working end-to-end. Run: `go run ./cmd/schemagen`.
- Makefile: `make schemas` target wraps the schemagen invocation.

Design rationale lives in ADR-0005 (#360) and the architecture review
that drove the registry-driven approach. Chuck's prior proposal in #40
arrived at the same architectural conclusion (registry-driven
enumeration, new providers picked up automatically); the output format
shifted to JSON Schema + commented YAML for the Docusaurus renderer.

Refs #40.
Wires up the schema-gen pipeline end-to-end:

- pkg/configschema.Generate (FormatJSON) now produces real JSON Schema
  using invopop/jsonschema with godoc descriptions extracted via
  Reflector.AddGoComments. Configured to read yaml tags (not json),
  package-qualify $defs keys to avoid collisions across providers
  (e.g. aws.Config vs longhorn.Config), and emit
  additionalProperties:false to match the validator's strict-on-unknown
  contract.
- cmd/schemagen now writes schemas/manifest.json,
  schemas/nebari-config.json, and schemas/providers/<name>.json. Walks
  pkg/ to collect package paths for godoc extraction. Supports -version,
  -providers, -pkg-root flags.
- schemas/ committed in-tree. 6 cluster providers (aws, gcp, azure,
  hetzner, local, existing) + 1 DNS provider (cloudflare) + top-level
  nebari-config + manifest. Total ~28KB of JSON.
- .github/workflows/schemas.yml drift-check on PRs and main pushes,
  paths-filtered to config/provider/schema-gen files. Authors run
  `make schemas` locally and commit; CI fails on divergence (kubebuilder
  CRD-regen pattern, no auto-commit).

YAML reference output (FormatYAML) still stubbed; lands in a follow-up
commit on this branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants