Skip to content

templates: add fork-only template registry and promotion lifecycle#213

Draft
sjmiller609 wants to merge 1 commit intomainfrom
hypeship/templates
Draft

templates: add fork-only template registry and promotion lifecycle#213
sjmiller609 wants to merge 1 commit intomainfrom
hypeship/templates

Conversation

@sjmiller609
Copy link
Copy Markdown
Collaborator

Summary

  • New lib/templates package with a JSON file-backed Registry (Save/Get/GetByName/List/Delete + IncrementForkCount/DecrementForkCount).
  • Adds Template model with hypervisor type/version, image+digest, vCPU/memory, fork refcount, and a reserved HotPagesPath field for PR 8.
  • Wires lib/instances template plumbing: promote/list/get/delete plus paths.TemplatesDir() etc.
  • Stores IsTemplate / TemplateID / ForkOfTemplate on instance metadata; the manager owns a templates.Registry it constructs at startup.

Why

Foundation for snapshot fan-out: templates are the durable "tagged Standby instance promoted to fork-only parent" record that downstream PRs (shared mem-file, GC, UFFD page server) hang off of. Splitting it out keeps each follow-up reviewable.

Test plan

  • go test ./lib/templates/...
  • go test ./lib/instances/... for unit coverage of new metadata fields
  • Manual: promote a Standby instance, list templates, attempt to delete with a live fork (must refuse), unfork, delete

🤖 Generated with Claude Code

Introduces a templates package and Standby-instance promotion path so
later PRs can wire fork-from-template into firecracker. The registry
persists one JSON file per template under <data>/templates/<id>/, with
fork refcount accounting and Delete-blocked-when-in-use.

The instance manager owns the registry because template lifecycle is
coupled to instance lifecycle: promotion guards on Standby+HasSnapshot,
deletion clears IsTemplate on the source instance, and forks (PR 3)
will increment the refcount.

Hypervisor wire-up is deferred — this PR ships the registry, the
StoredMetadata flags, and the manager helpers (templateGuard,
templateForFork, validateForkResolvedFromTemplate) so PR 3 can plug in.
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