Refactor VM lifecycle around capabilities

Make host-integrated VM features fit a standard Go extension path instead of adding more one-off branches through vm.go. This is the enabling refactor for future work like shared mounts, not the /work feature itself.

Add a daemon capability pipeline plus a structured guest-config builder, then move the existing /root work-disk mount, built-in DNS, and NAT wiring onto those hooks. Generalize Firecracker drive config at the same time so later storage features can extend machine setup without another hardcoded path.

Add banger doctor on top of the shared readiness checks, update the docs to describe the new architecture, and cover the new seams with guest-config, capability, report, CLI, and full go test verification. Also verify make build and a real ./banger doctor run on the host.
This commit is contained in:
Thales Maciel 2026-03-18 19:28:26 -03:00
parent 9e98445fa2
commit 4930d82cb9
No known key found for this signature in database
GPG key ID: 33112E6833C34679
18 changed files with 1120 additions and 105 deletions

View file

@ -86,6 +86,15 @@ func (p *Preflight) Addf(format string, args ...any) {
p.add(format, args...)
}
func (p *Preflight) Problems() []string {
if len(p.problems) == 0 {
return nil
}
out := make([]string, len(p.problems))
copy(out, p.problems)
return out
}
func (p *Preflight) Err(prefix string) error {
if len(p.problems) == 0 {
return nil

61
internal/system/report.go Normal file
View file

@ -0,0 +1,61 @@
package system
type CheckStatus string
const (
CheckStatusPass CheckStatus = "pass"
CheckStatusWarn CheckStatus = "warn"
CheckStatusFail CheckStatus = "fail"
)
type CheckResult struct {
Name string
Status CheckStatus
Details []string
}
type Report struct {
Checks []CheckResult
}
func (r *Report) Add(status CheckStatus, name string, details ...string) {
r.Checks = append(r.Checks, CheckResult{
Name: name,
Status: status,
Details: append([]string(nil), details...),
})
}
func (r *Report) AddPass(name string, details ...string) {
r.Add(CheckStatusPass, name, details...)
}
func (r *Report) AddWarn(name string, details ...string) {
r.Add(CheckStatusWarn, name, details...)
}
func (r *Report) AddFail(name string, details ...string) {
r.Add(CheckStatusFail, name, details...)
}
func (r *Report) AddPreflight(name string, checks *Preflight, successDetail string) {
problems := checks.Problems()
if len(problems) == 0 {
if successDetail == "" {
r.AddPass(name)
return
}
r.AddPass(name, successDetail)
return
}
r.AddFail(name, problems...)
}
func (r Report) HasFailures() bool {
for _, check := range r.Checks {
if check.Status == CheckStatusFail {
return true
}
}
return false
}

View file

@ -0,0 +1,27 @@
package system
import "testing"
func TestReportAddPreflightPassAndFail(t *testing.T) {
report := Report{}
pass := NewPreflight()
report.AddPreflight("runtime bundle", pass, "ready")
fail := NewPreflight()
fail.Addf("missing firecracker")
report.AddPreflight("core vm lifecycle", fail, "")
if len(report.Checks) != 2 {
t.Fatalf("len(report.Checks) = %d, want 2", len(report.Checks))
}
if report.Checks[0].Status != CheckStatusPass {
t.Fatalf("report.Checks[0].Status = %s, want pass", report.Checks[0].Status)
}
if report.Checks[1].Status != CheckStatusFail {
t.Fatalf("report.Checks[1].Status = %s, want fail", report.Checks[1].Status)
}
if !report.HasFailures() {
t.Fatal("HasFailures() = false, want true")
}
}