diff --git a/docs/README.md b/docs/README.md index ed5fa2bf..7dca380b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -75,6 +75,7 @@ Each topic folder has a `README.md` entry point: | [Device operations](enhancements/device-operations/README.md) | Proposed custody and operations for every physical action on a server | | [OS images and bootstrap data](enhancements/machine-images/README.md) | Proposed image catalog and sealed bootstrap data for installs | | [Boot delivery](enhancements/boot-delivery/README.md) | Proposed network boot and virtual media behind one install contract | +| [Capacity supply](enhancements/capacity-supply/README.md) | Proposed provider view of available machines, and offer, withdraw and supply hold actions | | [Proposals](proposals/fleet-management/README.md) | Broader service proposals, examples, diagrams, and provenance | ## Read implementation and design separately diff --git a/docs/enhancements/capacity-supply/README.md b/docs/enhancements/capacity-supply/README.md new file mode 100644 index 00000000..7e006310 --- /dev/null +++ b/docs/enhancements/capacity-supply/README.md @@ -0,0 +1,508 @@ +--- +status: provisional +stage: alpha +--- + +# Offer ready machines for allocation + +[Documentation overview](../../README.md) ยท [Functionality guide](../../functionality/README.md) + +- [Summary](#summary) +- [Motivation](#motivation) +- [Proposal](#proposal) +- [Design details](#design-details) + - [Supply states](#supply-states) + - [Actions](#actions) + - [Who may act](#who-may-act) + - [Where the view is computed and stored](#where-the-view-is-computed-and-stored) + - [Provider view](#provider-view) + - [Acceptance tests](#acceptance-tests) +- [Out of scope](#out-of-scope) +- [Open questions](#open-questions) +- [Implementation history](#implementation-history) +- [Drawbacks](#drawbacks) +- [Alternatives](#alternatives) + +## Summary + +A provider operator needs to see, for each site and pool, how many machines can +be allocated now, and why every other machine cannot. This enhancement adds +that view, plus three actions on a machine: offer, withdraw, and supply hold. +A supply hold is a supply-side block on the capacity record. It never holds the +server's custody. + +No action can make a machine allocatable. A machine is allocatable only when +evidence says it is prepared, healthy, free, and cleaned. Actions can only +remove a machine from supply or allow evidence to count. + +This enhancement is a proposal. It tracks [issue #120][issue]. Where it +mentions behavior that exists, that behavior is in open pull requests +([#200][pr-status] and [#201][pr-enable]), not in a released build. The release +gates, the pinned cleaning policy, and commissioning that the states rely on +come from the open proposals [#183][pr-cleaning] and [#185][pr-commissioning]. +Those states are proposed until those land. + +## Motivation + +Provider operators run owned machines through registration, commissioning, +allocation, cleaning, and recovery. Each step already records its own state, but +no place shows the result. To answer "how many machines can we sell?", an +operator reads capacity records, custody records, and operation history by +hand, and still cannot tell a machine that is waiting for cleaning from one +that needs a person. + +### Goals + +- Show supply per site, class, and pool, with every unavailable machine counted + once under one reason. +- Show what check returns each unavailable machine to service. +- Let an operator withdraw a machine from new allocations without touching its + current customer. +- Let an operator hold a machine that cannot be trusted, and return it + only after named checks pass. +- Keep one writer for every field, and no new database. + +### Non-goals + +See [Out of scope](#out-of-scope). + +## Proposal + +Four parts, each using records Fleet already has or proposes: + +1. **Supply state.** The capacity projector classifies each registered machine + into exactly one state with a reason and the checks that remain. The + projector proposed in [#200][pr-status] writes the capacity conditions from + evidence. +2. **Actions.** Offer and withdraw change the capacity's allocation policy. + A supply hold adds a block with required checks to the capacity. +3. **Summary.** The projector also writes a small count per site and pool. +4. **Provider view.** Staff read the summary and drill into machines. + +Customers never see this view. They keep seeing the class-level availability +that capacity publication already provides. + +### User stories + +- An operator sees why a machine is held and which checks return it to + service. +- An operator withdraws a machine for planned work. Its customer keeps running. +- A capacity planner reports available supply and separates it from machines + that are being cleaned or commissioned. +- An operator places a supply hold on a machine after a failed wipe, and the + machine stays out of supply after the customer releases it. A failed release + wipe does not close `WipeVerified`: the check stays open until a later wipe + that the contract admits succeeds with verified evidence. + +## Design details + +Names marked provisional may change. Examples use synthetic data. + +### Supply states + +Each registered machine is in the first state below that matches. Evaluating in +this order counts each machine once. + +| State | Meaning | Evidence | Returns to service when | +| --- | --- | --- | --- | +| `Retired` | The Device is `Retired`, or custody is `Retired`. | Inventory lifecycle, custody holder | Never. Register a new Device. | +| `Recovery` | An operation outcome is unknown, or custody is `Unverified`. | Recovery hold, custody state | A recovery decision settles the hold, or an operator resolves custody. | +| `Allocated` | A customer Machine holds the server. | Custody holder `Allocation` | The customer releases it. | +| `Cleaning` | The allocation ended and release gates are open. | Custody holder `Release`, open gates | Every gate has evidence, including a wipe that meets the pinned cleaning policy. | +| `Held` | Staff blocked the capacity from supply. | Supply hold block on the capacity | Every check on the block has evidence. | +| `Withdrawn` | Allocation policy is `Disabled`. | Capacity spec | An operator offers it again. | +| `Commissioning` | The server is not `Prepared` or `Healthy`: never commissioned, commissioning running or failed, plan changed, or evidence expired. A withdrawn machine that was never commissioned shows `Withdrawn`, because that state is evaluated first. | Commissioning result, discovery | A commissioning under the current plan succeeds. | +| `Unknown` | Evidence is missing, such as an unreachable cleaning policy owner. | The capacity's `Available` condition | The evidence returns. | +| `Available` | The capacity's `Available` condition is true. | Capacity conditions | Not applicable. | + +A machine in the automatic quarantine that [machine lifecycle][lifecycle] +applies to an unknown outcome shows `Recovery` first, whether or not it also +carries a supply hold. An `Allocated` or `Cleaning` machine that an operator +also withdrew or held keeps its current state. The reason lists the pending +block or withdrawal, so the operator sees that the machine will not return to +supply on release. + +Every state has a reason code drawn from the existing capacity condition +reasons (for example `NotCommissioned`, `PlanChanged`, `EvidenceExpired`, +`DeviceReplaced`, `RecoveryHold`), plus the open release gates and supply hold +checks. The state never contains customer identity. + +### Actions + +Offer and withdraw move a machine between `Withdrawn` and the evidence-derived +states. A supply hold keeps a machine out of supply until named checks have +evidence. It can be recorded at any time, and it never changes custody. + +#### Offer + +Offer sets the capacity's allocation policy to `Enabled`. Registered capacity +starts `Disabled`, and the registration rules proposed in [#201][registration] +require an `Active` Device, a pool label, and a resolving cleaning policy before +the update is admitted. On main, stage 1 still denies every update of +inventory-backed capacity, so offer and withdraw depend on that proposal. +Offering does not require commissioning. + +Offer changes intent only. The machine is `Available` only after the projector +finds it `Prepared`, `Healthy`, free, and not held. An offered +machine that was never commissioned shows `Commissioning`. + +#### Withdraw + +Withdraw sets the allocation policy to `Disabled`. It stops new allocations +only. The current customer's allocation, installation, power control, and +release continue unchanged. When that customer releases the machine, cleaning +runs as usual and the machine then shows `Withdrawn`. + +An allocator that selected the capacity but has not yet claimed its server +withdraws that selection, as it does today. + +#### Supply hold + +A supply hold records that a machine must not be offered until named checks have +evidence. It is proposed. It lives on the capacity record, which decides +whether a machine is offered, and it never holds custody. Custody keeps its +current holder, its fence, and its admission rules, so a supply hold adds no +holder, no transition, and no change to the [device operations +contract][device-ops]. + +A supply hold is not the quarantine in [machine lifecycle][lifecycle]. That +quarantine is automatic: Fleet applies it when an operation outcome is unknown, +and recovery clears it. A supply hold is a staff decision about supply. The two +do not depend on each other and can apply to one machine. Such a machine shows +`Recovery` first, and it returns to supply only when neither applies. + +A staff recovery operator records the block on the capacity, with a reason code +and a set of required checks. The capacity operator may not set it. There is no +separate request kind: the block is part of the capacity record, and each part +has one writer. + +```yaml +# Capacity spec, written by a staff recovery operator (provisional) +supplyHold: + reason: SuspectedHardwareFault # provisional reason codes + setBy: ops-example@provider.example + setAt: "2026-11-27T10:00:00Z" + checks: [Recommissioned, IdentityReverified, PersonReview] + reviewedBy: null # a different staff recovery operator, for PersonReview + removedChecks: [] # each entry: check, removedBy, reason, approvedBy +``` + +Re-wiping a machine that is in supply and not being released is out of scope +here. It would need a new admitted wipe in the device operations contract, which +this proposal does not change. `WipeVerified` is for a machine that is being +released. + +The projector reports progress in the capacity status as `openChecks`, the +checks that still lack evidence. Webhook admission stamps `setBy` from the +caller of the write that sets it, and `reviewedBy` from the caller of the write +that sets that field. It refuses a value that differs from the caller, refuses +`reviewedBy` equal to `setBy`, and refuses any change to either once set. A +block with no checks, an unknown check, or a check that cannot be satisfied for +this machine is refused. + +Each `removedChecks` entry follows the same rule. Admission stamps `removedBy` +from the caller of the write that adds the entry, and `approvedBy` from the +caller of the write that sets that field. It refuses a value that differs from +the caller, refuses `approvedBy` equal to `removedBy`, and refuses any change to +either once set. It refuses removing the whole block while any check is open: a +check is closed by evidence or by a recorded removal, never by deleting the +block. + +Kubernetes RBAC cannot grant write on one field of a spec, so RBAC alone would +let the capacity operator edit or drop the block in the same write that offers +or withdraws. Admission closes that gap. It rejects any add, change, or removal +of the `supplyHold` part from a caller who lacks the separate supply hold +permission, and it leaves writes that do not touch the part unaffected. The +permission is a distinct verb on a resource named for the supply hold, which +admission checks with an authorization review of the caller. A subresource with +its own verb is the alternative if admission cannot carry this. The same +admission covers the `reviewedBy`, `removedChecks`, and removal writes. + +Setting or editing a supply hold, like withdraw, does not require the +registration checks that offering requires: an Active Device, a pool label, and +a resolving cleaning policy. A machine that fails registration can still be +held. + +Each check is satisfied by an operation or observation that the device +operations contract already admits. Evidence counts only if it is +recorded after `setAt`. The one exception is a release wipe already in progress +when the block is recorded: it counts if it finishes with verified evidence +after `setAt`. + +| Check | Satisfied by | Refused at admission when | +| --- | --- | --- | +| `WipeVerified` | The verified wipe of the release that ends the current allocation, including one already in progress, or a later wipe the contract admits, which is a settling wipe for a held operation. The wipe meets the cleaning policy pinned for the server and finishes after `setAt`. A failed release wipe, or one whose outcome is unknown, does not close the check and does not count as finished: the check stays open until a later wipe the contract admits succeeds with verified evidence. If the server is retired instead, the hold ends with the capacity record. | The holder is `None` or `Service`, or the release wipe has already finished with success, because the contract admits no wipe from those holders and a finished wipe cannot count. A block set while the machine is allocated or being released is accepted. | +| `Recommissioned` | A `DeviceCommissioning` that succeeds under the current plan. It is admitted from holder `None`, after the release finishes. | The Device is Retired, because the contract admits no commissioning there. | +| `IdentityReverified` | Discovery matches the Device's serial, system UUID, and BMC key. | Never. | +| `PersonReview` | A staff recovery operator other than `setBy` records `reviewedBy`. | Never. | + +The allocator reads the block on the capacity itself and refuses any capacity +that carries one. It stops refusing only when one of two things holds: it has +re-evaluated the evidence for every required check and each is closed, or the +projector has observed the block at its current generation and reports no open +checks. A block the projector has not yet observed therefore blocks, so a hold +recorded just before an allocation pass takes effect at once. The allocator +never trusts status alone: it does not treat a missing or stale `openChecks` as +no open checks. + +The projector marks a check closed from that evidence and keeps the machine +`Held` while any check is open. A machine with all checks closed is no +longer blocked by the supply hold, and its state follows from the rest of the +evidence. Removing the finished block is housekeeping and changes no allocation +outcome. + +A check can become impossible to meet, for example when the Device is later +retired. The person who may clear a supply hold may then remove that check. The +removal is recorded in `removedChecks` with who removed it, why, and the second +person who approved it, under the same rule as `PersonReview`. A block on +capacity whose Device is Retired or removed ends with the capacity record, +because capacity of a Retired Device is removed ([#201][capacity-retired]). + +If the machine is allocated, the customer is undisturbed. The release runs as +normal, including its wipe, and custody finishes at `None` as it does today. +The machine stays out of supply after release because the capacity still +carries the block. The release wipe closes `WipeVerified` when it finishes +with verified evidence after the block is recorded, so a wipe already running +at that moment counts. A wipe that fails, or whose outcome is unknown, leaves +the check open, and under the contract it holds the release, so the server +cannot return to `None` until a later wipe the contract admits succeeds. +Commissioning, wipe, and recovery then run under the admission rules the +contract already has: staff commission from `None`, and +recovery settles any hold. If the release wipe finished before the block was +recorded, or the holder is `None` or `Service`, `WipeVerified` is refused at +admission, and the block uses the other checks. + +#### Safety rules + +- The allocator reads the supply hold block itself. A block it cannot show to be + fully closed, including one the projector has not yet observed, blocks supply. +- No action writes a capacity condition. `Prepared`, `Healthy`, and `Available` + stay derived from evidence by the projector, and the allocator evaluates the + evidence itself. +- Offering never skips commissioning. Clearing a supply hold never skips a + required wipe or release gate. +- A supply hold never writes custody, never adds a holder, and never admits an + operation the contract refuses. +- A finished supply hold returns a server to the state its evidence supports. It + can still be `Cleaning`, `Commissioning`, or `Withdrawn`. +- An action that cannot be recorded leaves the server out of supply. An + unknown outcome is never treated as ready. + +### Who may act + +Each action maps to one permission, so IAM can grant them separately. Role names +are provisional. + +| Action | Record changed | Role | Notes | +| --- | --- | --- | --- | +| Offer | Capacity allocation policy | Capacity operator | Update permission on capacity, proposed in #201. Subject to the registration checks. | +| Withdraw | Capacity allocation policy | Capacity operator | Same permission. Always allowed. | +| Supply hold | Capacity supply hold block (spec) | Staff recovery operator | Separate supply hold permission, enforced by admission, which rejects any add, change, or removal of the part from a caller without it. IAM can grant it without offer. The capacity operator does not have it unless IAM grants it. A server that has a customer or a recovery hold is still accepted. Registration checks do not apply. | +| Review a supply hold | Capacity supply hold `reviewedBy` | Staff recovery operator other than `setBy` | Satisfies `PersonReview`. | +| Close a supply hold check | Capacity status `openChecks` | Projector, from evidence | Staff cannot write it. | +| Remove a finished supply hold | Capacity supply hold block (spec) | Same permission as supply hold | Allowed once `openChecks` is empty. Admission refuses removal while any check is open. Removing a check that can no longer be met needs a second person. | +| Read the supply view | None | Staff roles that read capacity | Customer identity needs the separate role that reads MachineAllocations. | + +Withdraw and supply hold must always be possible, even for a person who cannot +offer. Reducing supply is the safe direction. + +### Where the view is computed and stored + +The capacity projector proposed in [#200][pr-status] computes capacity +conditions from evidence and is the only writer of registered capacity status. +Custody is not written by anything in this proposal. This proposal extends the +projector rather than adding a second computing component. + +| Surface | Kind | Writer | Readers | +| --- | --- | --- | --- | +| Allocation policy, pool label | Capacity spec | Capacity operator, who cannot touch the supply hold part | Projector, allocator | +| Supply hold block | Capacity spec, supply hold part | Staff recovery operator, enforced by admission | Projector, allocator | +| Per-machine supply state, reason, `openChecks` | Capacity status | Projector | Staff, summary | +| Per-site and pool counts | `CapacitySummary` status (provisional) | Projector | Staff | + +`CapacitySummary` is a new kind in the provider project, one object per site +and pool. It has no spec that anyone edits. The projector rebuilds each object +from the current capacity records on every pass instead of adding and +subtracting, so a missed event cannot cause lasting drift. No count is stored +anywhere else, and no SQL or other database is involved. + +```yaml +apiVersion: metal.datumapis.com/v1alpha1 # group as on main; version provisional +kind: CapacitySummary +metadata: + name: site-example-a-pool-standard + namespace: default +status: + site: site-example-a + pool: standard + observedAt: "2026-11-27T10:05:00Z" + total: 40 + counts: + Available: 22 + Allocated: 11 + Cleaning: 2 + Recovery: 1 + Commissioning: 2 + Held: 1 + Withdrawn: 1 + Retired: 0 + Unknown: 0 + reasons: + Cleaning: {ReleaseGateOpen: 2} + Commissioning: {NotCommissioned: 1, EvidenceExpired: 1} +``` + +Rules for the summary: + +- The allocator never reads it. A stale or edited summary cannot affect which + machine a customer receives. +- Counts add up to `total`. A machine whose evidence cannot be read counts as + `Unknown`, not `Available`. +- A summary older than a stated freshness limit is shown as stale in the view. + Stale numbers are not shown as current. +- The projector writes status only. A webhook admits status writes only from the + projector's identity, as it does for capacity status today. + +Classes overlap. A MachineClass selects capacity by label, so one machine can +match several classes. The summary is keyed by pool, which is a single label on +the capacity, so pools never double count. A class view lists the pools its +selector matches and does not sum across overlapping classes without warning. +This preserves the rule that overlapping classes must not duplicate supply. + +Site comes from the Device the capacity names. + +### Provider view + +The provider portal and CLI show: + +1. A table of site and pool rows with one column per state. +2. For each row, the machines in each unavailable state with reason, who or + what is blocking, how long, and the checks that remain. +3. For a held machine, the reason, who set it, and `openChecks`. + +The view reads the summary for counts and lists capacity records for machines. +It does not read customer records. + +### Acceptance tests + +These tests are required and not implemented: + +- A machine in each state is counted once, and the counts equal the machine + list. +- Withdrawing an allocated machine leaves the customer running. After release, + the machine is cleaned and shows `Withdrawn`. +- Offering a never-commissioned machine shows `Commissioning`, not `Available`. +- A hand-edited summary or capacity status does not change allocation. +- Placing a supply hold on an allocated machine leaves the customer running and + custody unchanged. After release, custody finishes at `None`, and the + machine stays out of supply while any check is open. +- A supply hold with `WipeVerified` set during an allocation closes that check + from the release wipe and from no earlier evidence. +- A supply hold with `WipeVerified` set while the release wipe is in progress + closes that check when the wipe finishes with verified evidence. The same + request is refused after the wipe has finished or when the holder is `None` + or `Service`. +- A supply hold requiring `Recommissioned` on a Retired Device is refused. +- A check that can no longer be met is removed only with who and why recorded + and a second person, and a block on capacity of a Retired Device ends with the + capacity record. +- A machine that fails offer registration can still be held. +- A supply hold recorded just before an allocation pass, before any projector + pass, blocks that pass. The allocator does not wait for `openChecks`. +- A hold whose checks are all closed by evidence the allocator re-evaluates, or + that the projector reports closed at the hold's current generation, stops + blocking before staff remove it. +- A failed or unknown release wipe does not close `WipeVerified` and does not + count as finished for the admission refusal. The check closes only when a + later wipe the contract admits succeeds with verified evidence, and a + server retired instead ends the hold with the capacity record. +- A supply hold with `Recommissioned` set on a machine in `None` closes only + after a commissioning admitted from `None` succeeds under the current plan. +- A supply hold requiring `WipeVerified` on a machine in `None` with no hold is + refused, because the contract admits no wipe there. +- Every check can be satisfied without a custody holder change or an operation + the device operations contract refuses. +- A supply hold with no checks, or with an unknown check, is refused. +- A capacity operator write cannot add, edit, or remove a supply hold, including + in the same write that offers or withdraws. +- A new supply hold with no projected status blocks allocation. +- Removing the whole block while any check is open is refused. +- `removedBy` and `approvedBy` are stamped from the caller, a mismatch is + refused, `approvedBy` equal to `removedBy` is refused, and neither changes + once set. +- A caller cannot set `setBy` or `reviewedBy` to another identity, set + `reviewedBy` equal to `setBy`, or change either once set. +- The requester of a supply hold cannot satisfy its `PersonReview` check. +- An unreachable cleaning policy owner makes machines `Unknown`, not `Available`. +- Deleting and rebuilding a summary reproduces the same counts. +- Two classes selecting one pool never count a machine twice. + +## Out of scope + +- Purchasing machines and ordering hardware. +- Demand forecasting and capacity planning models. +- Rented-provider integrations and procurement policy. +- Power and feed planning ([#117][power-issue]). +- Customer-facing availability. Capacity publication owns it. +- Changing how commissioning, cleaning, or recovery decide success. + +## Open questions + +These need a person's decision. + +1. **Who may clear a supply hold?** Is the projector closing evidence checks + automatically enough, or must a person always confirm? Does the + `PersonReview` check need a second person, as commissioning approval may? +2. **Does evidence alone end a supply hold?** A supply hold lives on the capacity + record, not in custody. The remaining question is whether a block with every + check closed stops blocking by itself, as drafted (the allocator + re-evaluates the evidence or reads the projector at the hold's generation, + and removal is housekeeping), or stays until staff remove it. Staff removal + gives a person the last say but lets a stale block hide supply. +3. **Withdrawn versus never offered.** Should the view separate machines that + were withdrawn from machines never offered? The policy value cannot tell + them apart without recording history. +4. **Who may place a supply hold?** Drafted as the staff recovery operator only. + Should the capacity operator role also be able to? +5. **Summary freshness limit.** What age makes counts stale in the view? +6. **Class view.** Should the view list classes at all, given overlap, or only + pools? +7. **Supply hold reasons.** Is a fixed reason list enough, or do operators need + free text? Free text may carry sensitive detail. + +## Implementation history + +- 2026-11-27: Proposed. + +## Drawbacks + +- The projector gains another output and must stay correct as states are added. +- A supply hold adds a field to the capacity spec, which the allocator and + projector must both honor. +- A pool-keyed summary cannot answer class questions exactly where classes + overlap. + +## Alternatives + +- **Compute counts in the portal.** Each client would repeat the rules and could + disagree. Automation could not read the result. +- **A separate component for the summary.** It would need its own credentials and + would duplicate the projector's evidence reads. +- **Store counts in a database.** The design already avoids one, and a database + adds a second source of truth that can drift. +- **A supply hold as a custody hold.** A hold would need a new holder or a move + out of `Release`, and the device operations contract admits commissioning + only from `None`. That would change a contract this proposal does not own. +- **Let an offer set `Available`.** A person could then make an unprepared + machine allocatable. + +[issue]: https://github.com/datum-cloud/fleet/issues/120 +[pr-status]: https://github.com/datum-cloud/fleet/pull/200 +[pr-enable]: https://github.com/datum-cloud/fleet/pull/201 +[pr-cleaning]: https://github.com/datum-cloud/fleet/pull/183 +[pr-commissioning]: https://github.com/datum-cloud/fleet/pull/185 +[power-issue]: https://github.com/datum-cloud/fleet/issues/117 +[registration]: https://github.com/datum-cloud/fleet/pull/201 +[device-ops]: ../device-operations/README.md +[lifecycle]: ../machine-lifecycle/README.md +[capacity-retired]: https://github.com/datum-cloud/fleet/pull/201