feat(labs): add the labd provisioner with clone pool, time to live and limits

This commit is contained in:
shira committed 2026-10-11 15:43:04 +03:00
1 parent 9fdaa62b9b
commit 9385b2ddd4
53 files changed
+14675 -6

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
package template
import "fmt"
type registryKey struct {
id string
version int
}
// Registry holds the templates of the labd build by ID and version.
type Registry struct {
templates map[registryKey]Template
}
// NewRegistry validates the templates and indexes them. A duplicate ID and
// version is a build error.
func NewRegistry(templates ...Template) (*Registry, error) {
registry := &Registry{templates: make(map[registryKey]Template, len(templates))}
for _, template := range templates {
if err := template.Validate(); err != nil {
return nil, err
}
key := registryKey{id: template.ID, version: template.Version}
if _, duplicate := registry.templates[key]; duplicate {
return nil, fmt.Errorf("template.NewRegistry - duplicate template %s version %d", template.ID, template.Version)
}
registry.templates[key] = template
}
return registry, nil
}
// Lookup returns the template with the given ID and version.
func (r *Registry) Lookup(id string, version int) (Template, bool) {
template, ok := r.templates[registryKey{id: id, version: version}]
return template, ok
}
// All returns every template in no particular order.
func (r *Registry) All() []Template {
all := make([]Template, 0, len(r.templates))
for _, template := range r.templates {
all = append(all, template)
}
return all
}
// Builtin returns the templates of this build. Real templates and their
// prepared images arrive with the MikroTik and Ubuntu lab images; until then
// the registry is empty and every CreateLab answers validation_failed.
func Builtin() []Template {
return nil
}