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:
parent
9e98445fa2
commit
4930d82cb9
18 changed files with 1120 additions and 105 deletions
92
internal/daemon/doctor.go
Normal file
92
internal/daemon/doctor.go
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
package daemon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"banger/internal/config"
|
||||
"banger/internal/model"
|
||||
"banger/internal/paths"
|
||||
"banger/internal/system"
|
||||
)
|
||||
|
||||
func Doctor(ctx context.Context) (system.Report, error) {
|
||||
layout, err := paths.Resolve()
|
||||
if err != nil {
|
||||
return system.Report{}, err
|
||||
}
|
||||
cfg, err := config.Load(layout)
|
||||
if err != nil {
|
||||
return system.Report{}, err
|
||||
}
|
||||
d := &Daemon{
|
||||
layout: layout,
|
||||
config: cfg,
|
||||
runner: system.NewRunner(),
|
||||
}
|
||||
return d.doctorReport(ctx), nil
|
||||
}
|
||||
|
||||
func (d *Daemon) doctorReport(ctx context.Context) system.Report {
|
||||
report := system.Report{}
|
||||
|
||||
report.AddPreflight("runtime bundle", d.runtimeBundleChecks(), runtimeBundleStatus(d.config))
|
||||
report.AddPreflight("core vm lifecycle", d.coreVMLifecycleChecks(), "required host tools available")
|
||||
d.addCapabilityDoctorChecks(ctx, &report)
|
||||
report.AddPreflight("image build", d.imageBuildChecks(ctx), "image build prerequisites available")
|
||||
|
||||
return report
|
||||
}
|
||||
|
||||
func (d *Daemon) runtimeBundleChecks() *system.Preflight {
|
||||
checks := system.NewPreflight()
|
||||
hint := paths.RuntimeBundleHint()
|
||||
checks.RequireExecutable(d.config.FirecrackerBin, "firecracker binary", hint)
|
||||
checks.RequireFile(d.config.SSHKeyPath, "ssh private key", `set "ssh_key_path" or refresh the runtime bundle`)
|
||||
checks.RequireFile(d.config.DefaultRootfs, "default rootfs image", `set "default_rootfs" or refresh the runtime bundle`)
|
||||
checks.RequireFile(d.config.DefaultKernel, "kernel image", `set "default_kernel" or refresh the runtime bundle`)
|
||||
if strings.TrimSpace(d.config.DefaultInitrd) != "" {
|
||||
checks.RequireFile(d.config.DefaultInitrd, "initrd image", `set "default_initrd" or refresh the runtime bundle`)
|
||||
}
|
||||
if strings.TrimSpace(d.config.DefaultPackagesFile) != "" {
|
||||
checks.RequireFile(d.config.DefaultPackagesFile, "package manifest", `set "default_packages_file" or refresh the runtime bundle`)
|
||||
}
|
||||
return checks
|
||||
}
|
||||
|
||||
func (d *Daemon) coreVMLifecycleChecks() *system.Preflight {
|
||||
checks := system.NewPreflight()
|
||||
d.addBaseStartCommandPrereqs(checks)
|
||||
return checks
|
||||
}
|
||||
|
||||
func (d *Daemon) imageBuildChecks(ctx context.Context) *system.Preflight {
|
||||
checks := system.NewPreflight()
|
||||
d.addImageBuildPrereqs(
|
||||
ctx,
|
||||
checks,
|
||||
firstNonEmpty(d.config.DefaultBaseRootfs, d.config.DefaultRootfs),
|
||||
d.config.DefaultKernel,
|
||||
d.config.DefaultInitrd,
|
||||
d.config.DefaultModulesDir,
|
||||
"",
|
||||
)
|
||||
return checks
|
||||
}
|
||||
|
||||
func runtimeBundleStatus(cfg model.DaemonConfig) string {
|
||||
if strings.TrimSpace(cfg.RuntimeDir) == "" {
|
||||
return "runtime dir not configured"
|
||||
}
|
||||
return fmt.Sprintf("runtime dir %s", cfg.RuntimeDir)
|
||||
}
|
||||
|
||||
func firstNonEmpty(values ...string) string {
|
||||
for _, value := range values {
|
||||
if strings.TrimSpace(value) != "" {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue