Implements the hypervisor design's Phase 1: a second runtime.Runtime backend (QEMU) that runs each service component as a Nanos unikernel VM instead of a podman container, selected per-component via a new runtime = "unikernel" service-def field. - internal/runtime/qemu.go: QEMURuntime. Pull extracts the ELF from the OCI image; Run does `ops build` + boots qemu-system-x86_64 with KVM, user-mode net port-forwards, QMP control socket and serial console log; Stop/Remove/Inspect/List/Logs map onto VM lifecycle + state dir. - proto/registry/servicedef: add runtime, memory_mb, vcpus fields (registry migration 5). - agent: holds both runtimes; runtimeFor() selects per component; listAllContainers() merges containers + VMs so drift/status see both. Unikernel runtime auto-enables on nodes with /dev/kvm + ops. Validated end-to-end on straylight: a test service deploys via `mcp deploy --direct`, boots as a Nanos unikernel, serves HTTP through the agent port-forward, and reports running via `mcp status`/`mcp logs`. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
131 lines
3.2 KiB
Go
131 lines
3.2 KiB
Go
package master
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
mcpv1 "git.wntrmute.dev/mc/mcp/gen/mcp/v1"
|
|
"git.wntrmute.dev/mc/mcp/internal/masterdb"
|
|
)
|
|
|
|
// Status returns the status of services across the fleet.
|
|
func (m *Master) Status(ctx context.Context, req *mcpv1.MasterStatusRequest) (*mcpv1.MasterStatusResponse, error) {
|
|
m.Logger.Debug("Status", "service", req.GetServiceName())
|
|
|
|
resp := &mcpv1.MasterStatusResponse{}
|
|
|
|
// If a specific service is requested, look up its placement.
|
|
if name := req.GetServiceName(); name != "" {
|
|
placement, err := masterdb.GetPlacement(m.DB, name)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("lookup placement: %w", err)
|
|
}
|
|
if placement == nil {
|
|
return resp, nil // empty — service not found
|
|
}
|
|
|
|
ss := m.getServiceStatus(ctx, placement)
|
|
resp.Services = append(resp.Services, ss)
|
|
return resp, nil
|
|
}
|
|
|
|
// All services.
|
|
placements, err := masterdb.ListPlacements(m.DB)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("list placements: %w", err)
|
|
}
|
|
|
|
for _, p := range placements {
|
|
ss := m.getServiceStatus(ctx, p)
|
|
resp.Services = append(resp.Services, ss)
|
|
}
|
|
|
|
return resp, nil
|
|
}
|
|
|
|
func (m *Master) getServiceStatus(ctx context.Context, p *masterdb.Placement) *mcpv1.ServiceStatus {
|
|
ss := &mcpv1.ServiceStatus{
|
|
Name: p.ServiceName,
|
|
Node: p.Node,
|
|
Tier: p.Tier,
|
|
Status: "unknown",
|
|
}
|
|
|
|
// Query the agent for live status.
|
|
client, err := m.Pool.Get(p.Node)
|
|
if err != nil {
|
|
ss.Status = "unreachable"
|
|
return ss
|
|
}
|
|
|
|
statusCtx, cancel := context.WithTimeout(ctx, m.Config.Timeouts.HealthCheck.Duration)
|
|
defer cancel()
|
|
|
|
agentResp, err := client.GetServiceStatus(statusCtx, &mcpv1.GetServiceStatusRequest{
|
|
Name: p.ServiceName,
|
|
})
|
|
if err != nil {
|
|
ss.Status = "unreachable"
|
|
return ss
|
|
}
|
|
|
|
// Map agent status to master status.
|
|
for _, info := range agentResp.GetServices() {
|
|
if info.GetName() == p.ServiceName {
|
|
if info.GetActive() {
|
|
ss.Status = "running"
|
|
} else {
|
|
ss.Status = "stopped"
|
|
}
|
|
break
|
|
}
|
|
}
|
|
|
|
// Attach edge route info.
|
|
edgeRoutes, err := masterdb.ListEdgeRoutesForService(m.DB, p.ServiceName)
|
|
if err == nil {
|
|
for _, er := range edgeRoutes {
|
|
ss.EdgeRoutes = append(ss.EdgeRoutes, &mcpv1.EdgeRouteStatus{
|
|
Hostname: er.Hostname,
|
|
EdgeNode: er.EdgeNode,
|
|
})
|
|
}
|
|
}
|
|
|
|
return ss
|
|
}
|
|
|
|
// ListNodes returns all nodes in the registry with placement counts.
|
|
func (m *Master) ListNodes(_ context.Context, _ *mcpv1.ListNodesRequest) (*mcpv1.ListNodesResponse, error) {
|
|
m.Logger.Debug("ListNodes")
|
|
|
|
nodes, err := masterdb.ListNodes(m.DB)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("list nodes: %w", err)
|
|
}
|
|
|
|
counts, err := masterdb.CountPlacementsPerNode(m.DB)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("count placements: %w", err)
|
|
}
|
|
|
|
resp := &mcpv1.ListNodesResponse{}
|
|
for _, n := range nodes {
|
|
ni := &mcpv1.NodeInfo{
|
|
Name: n.Name,
|
|
Role: n.Role,
|
|
Address: n.Address,
|
|
Arch: n.Arch,
|
|
Status: n.Status,
|
|
Containers: int32(n.Containers), //nolint:gosec // small number
|
|
Services: int32(counts[n.Name]), //nolint:gosec // small number
|
|
}
|
|
if n.LastHeartbeat != nil {
|
|
ni.LastHeartbeat = n.LastHeartbeat.Format("2006-01-02T15:04:05Z")
|
|
}
|
|
resp.Nodes = append(resp.Nodes, ni)
|
|
}
|
|
|
|
return resp, nil
|
|
}
|