Skip to content

feat(render): share one definition generator between mage and a dev render subcommand - #1054

Open
a1994sc wants to merge 3 commits into
mainfrom
feature/rendor
Open

a1994sc wants to merge 3 commits into
mainfrom
feature/rendor

Conversation

@a1994sc

@a1994sc a1994sc commented Nov 8, 2026

Copy link
Copy Markdown
Member

Description

Package definitions were generated in exactly one place - the mage-only example generator under magefiles/pkg/gen/examples/, which renders the committed examples under example/ and is reachable from nothing else - so an operator who wanted a template plus a values file per release had to fork this repository or hand-write every distro.yaml. The rendering core moves into pkg/distrogen and is shared: mage keeps its pins, tags, flavors, caches and probes, and cargoship dev render exposes the same generator against values an operator supplies.

One generator, four call sites collapsed

pkg/distrogen is Render, Write, CheckOutputs and ValidateDistro, rendering through the existing helmvalues.RenderTemplate so there is no second template engine. The four duplicated render sites in magefiles/pkg/gen/examples/ - parseExampleTemplate, writeExampleValues, writeExampleContentManifests and parseUpstreamTemplate - now call it, and the first, second and fourth are deleted. Rendering and writing stay separate steps because content.go needs the bytes first, to drop a manifest that turns out to declare nothing.

Behaviour preserved, and one behaviour changed

The example templates now render under sprig with helmvalues.FuncMap rather than bare text/template, with the digest helpers injected through a new helmvalues.WithFuncs option. generate:examples produces a byte-identical example/ tree, including main's k3s-oci flavor, which is the acceptance test for the refactor. What does change: helmvalues.RenderTemplate rejects a template that resolved a key to <no value>, so a key absent for a new tag now fails generate:exampleLine rather than rendering that literal into a file. Better behaviour, but a new failure mode on the refresh path. Separately, Write is not atomic - a mid-loop write error leaves a partial directory - while validation does gate every write.

Tests

pkg/distrogen covers output naming, injected funcs, the missing-key rejection, directory creation, schema validation, and CheckOutputs - which refuses to render a template onto itself (dev render -t ./distro.yaml with no --out overwrote the template with its own output), refuses two templates colliding on one output name, and refuses a name that would escape --out. cmd/dev_render_test.go covers writing, validation blocking the write, --no-validate, values merge order, template clobbering, and the line printed when no distro.yaml was rendered and so nothing was schema-checked. go test -short ./api/... ./cmd/... ./config/... ./internal/... ./pkg/... ./types/... and ./magefiles/pkg/gen/examples/ pass, go run ./magefiles/core generate:examples leaves example/ unchanged, prek run --all-files is clean, and mdbook build reports no warnings. mage build:binary moves the linux/amd64 binary by 8 KiB, 39.77 to 39.89 MiB, since helmvalues, pkg/schema and goccy/go-yaml were already linked.

Related Issue

Relates to N/A

Checklist before merging

  • Test, docs, adr added or updated as needed

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

Binary size

Size
Latest release 40MB
This PR 40MB
Difference +172KB (0.42%)

@a1994sc
a1994sc marked this pull request as ready for review November 8, 2026 03:43
@a1994sc
a1994sc requested a review from a team as a code owner November 8, 2026 03:43
Signed-off-by: Allen Conlon <software@conlon.dev>
Signed-off-by: Allen Conlon <software@conlon.dev>
Signed-off-by: Allen Conlon <software@conlon.dev>

This branch has not been deployed

No deployments
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.

1 participant