// `carlos status --layout` (isolated-exec design §8.4, plan 4 task 5): which // layout each instance is on, box by box — the operator's console-backed // view of the layout pass's own on-box classification (internal/layout's // Pass.Classify), rather than a bucket walk with bucket credentials. // // GATE: the identical posture handleAPIStatusInstances already has // (apistatusinstances.go): cliUser, then s.store.IsOperator, then a bare // byte-identical 404 for anyone else. Registered through cliRoute with an // EMPTY role set — this is an operator's view across the whole fleet, not a // workload's, and no service credential of any role reaches it. package console import ( "log" "net/http" "sort" "time" "github.com/carlosframework/platform/internal/status" ) // apiStatusLayoutRow is one instance-kind route's layout, as the box's own // pass classified it — see status.RowLayout, which this mirrors on the // wire. type apiStatusLayoutRow struct { Host string `json:"host"` Layout string `json:"layout"` Reason string `json:"reason,omitempty"` // Note is the pass's last non-refusal event for the host (what a move // quarantined or kept aside). Additive; an old CLI ignores it. Note string `json:"note,omitempty"` } // apiStatusLayoutBox is one box's layout report: the mode it last converged // to, whether its snapshot is stale (status.BoxStale — the same rule every // other private reader of status/boxes/ uses), and its rows. type apiStatusLayoutBox struct { Box string `json:"box"` Mode string `json:"mode"` Stale bool `json:"stale"` Rows []apiStatusLayoutRow `json:"rows"` // Mixed is set when the box has a flat, foreign or external row // beside a nested one, or under a nested intent. Each of those runs as the agent's uid in the // agent's mount namespace, so it reaches every nested sibling's raw // directory: the nested rows are not isolated until none remains on // the box. Additive; an old CLI ignores it. Mixed bool `json:"mixed,omitempty"` // Default is set when the box is nested by the deployment's default // rather than a recorded intent; DefaultBlocked is why the default is // not in force on a box whose mode is none (design §8.6). Additive. Default bool `json:"default,omitempty"` DefaultBlocked string `json:"default_blocked,omitempty"` } // layoutMixed is the Mixed rule: a row that runs as the agent's uid with // no namespace, which is a flat row, a foreign one (paths the pass leaves // alone, spawned the flat way) or an external one (another supervisor's // process, also uid carlos), on a box that is nested, either by a nested // row beside it or by the box's intent (mode) being nested. The second // half (plan 5) keeps the warning loud for a box that has gone nested but // whose only remaining rows are the ones the pass cannot move: with no // nested row left to stand beside, they would otherwise read as clean. // Fenced and conflict rows are stopped and count for neither side. func layoutMixed(mode string, rows []apiStatusLayoutRow) bool { nested, unisolated := mode == "nested", false for _, r := range rows { switch r.Layout { case "nested": nested = true case "flat", "foreign", "external": unisolated = true } } return nested && unisolated } func (s *Server) handleAPIStatusLayout(w http.ResponseWriter, r *http.Request) { addr, ok := s.cliUser(w, r) if !ok { return } isOp, err := s.store.IsOperator(addr) if err != nil { log.Printf("console: api status layout: is-operator: %v", err) http.NotFound(w, r) return } if !isOp { http.NotFound(w, r) return } // systemBoxes is systemapply's own reader (apisystemupdate.go): the // platform's own status.LoadBoxes plus every customer fleet's boxes // under fleets//status/boxes/ — the same union carlos system // status already answers with, rather than a second, narrower one that // would miss fleet boxes (finding S14). boxes, _, err := s.systemBoxes(r.Context(), false) if err != nil { log.Printf("console: api status layout: boxes: %v", err) jsonError(w, http.StatusBadGateway, "could not read the fleet's box snapshots — try again") return } now := time.Now() out := make([]apiStatusLayoutBox, 0, len(boxes)) for _, b := range boxes { if b.Metrics == nil || b.Metrics.Layout == nil { // A box that predates layout reporting, or has no layout pass // armed yet (no activator running): nothing to add. continue } rows := make([]apiStatusLayoutRow, 0, len(b.Metrics.Layout.Rows)) for host, rl := range b.Metrics.Layout.Rows { rows = append(rows, apiStatusLayoutRow{Host: host, Layout: rl.Layout, Reason: rl.Reason, Note: rl.Note}) } sort.Slice(rows, func(i, j int) bool { return rows[i].Host < rows[j].Host }) out = append(out, apiStatusLayoutBox{ Box: b.Label, Mode: b.Metrics.Layout.Mode, Stale: status.BoxStale(b, now, status.SnapshotPeriod), Rows: rows, Mixed: layoutMixed(b.Metrics.Layout.Mode, rows), Default: b.Metrics.Layout.Default, DefaultBlocked: b.Metrics.Layout.DefaultBlocked, }) } sort.Slice(out, func(i, j int) bool { return out[i].Box < out[j].Box }) writeJSON(w, http.StatusOK, map[string]any{"boxes": out}) }