diff --git a/seaweed-block/docs/wiki/deep-dives/csi-lifecycle.md b/seaweed-block/docs/wiki/deep-dives/csi-lifecycle.md index 78cf809a0f..d4eadd944e 100644 --- a/seaweed-block/docs/wiki/deep-dives/csi-lifecycle.md +++ b/seaweed-block/docs/wiki/deep-dives/csi-lifecycle.md @@ -3,6 +3,41 @@ This page explains the Kubernetes-facing path from PVC to Seaweed Block operation-layer identity. +## Reader Orientation + +CSI is the Kubernetes standard interface between an orchestrator and a storage +system. It is where Kubernetes lifecycle intent becomes storage-side actions. + +You need this page before changing: + +- `core/csi`, +- Helm CSI RBAC/flags, +- `SwBlockVolume` CR creation, +- PVC/PV delete behavior, +- node stage/publish behavior, +- any operation-layer code that assumes a `SwBlockVolume` identity exists. + +## Domain Background + +Kubernetes users request storage with a PersistentVolumeClaim. CSI receives +controller and node RPCs that turn that claim into a usable filesystem inside a +pod. + +Practical CSI vocabulary: + +| Term | Meaning | +|---|---| +| `CreateVolume` | controller-side creation/provisioning for a PVC | +| `DeleteVolume` | controller-side delete request for the storage volume | +| `ControllerPublishVolume` | attach/publish intent for a node | +| `NodeStageVolume` | node-side setup, e.g. login, format, mount to staging path | +| `NodePublishVolume` | bind or publish staged volume into the pod path | +| idempotency | repeated RPCs after retry must produce the same logical result | +| publish target | address/protocol target the node can connect to | + +CSI does not know Seaweed Block authority by itself. It must consume the current +truth from blockmaster and the operation layer. + ## Problem Kubernetes users think in PVCs and pods. Seaweed Block internally needs a diff --git a/seaweed-block/docs/wiki/deep-dives/operation-layer-v05.md b/seaweed-block/docs/wiki/deep-dives/operation-layer-v05.md index c9925f0f3b..aa86ad4d70 100644 --- a/seaweed-block/docs/wiki/deep-dives/operation-layer-v05.md +++ b/seaweed-block/docs/wiki/deep-dives/operation-layer-v05.md @@ -1,133 +1,287 @@ # Operation Layer v0.5 -The v0.5 operation layer is the first bounded mutating lifecycle path. It is -not a broad operator. It exists to prove one controlled loop: +This page explains the first bounded mutating control-plane path in Seaweed +Block. It is written for developers who know Go and Kubernetes basics but may +not know storage operator design. + +## Reader Orientation + +Before v0.5, Seaweed Block could observe and explain a volume, but it did not +own a Kubernetes lifecycle mutation. v0.5 adds exactly one bounded mutation: ```text -facts -> judgment -> status/action -> admission-confined mutation -> evidence +add or remove block.seaweedfs.com/swblockvolume-protection +from SwBlockVolume.metadata.finalizers ``` -## Why It Exists - -Before this layer, Seaweed Block could observe many states but could not safely -own a Kubernetes lifecycle mutation. Phase 39 showed why: patching finalizers on -a CRD requires main-object patch permission, which is too broad unless an -admission boundary confines the write. - -This is the key historical trap: +Everything else remains out of scope: ```text -CRD finalizers are changed through main-object patch -main-object patch can also change spec/metadata -RBAC cannot express "only this one finalizer field" for this CRD -therefore code review alone is not a safety boundary +no automatic cleanup +no PVC/PV/workload deletion +no rebuild/failback/backup execution +no broad production operator claim ``` -The product choice was not "just add a finalizer". The real choice was whether -Seaweed Block could prove a bounded mutation against a real Kubernetes API. +The goal is not "make an operator". The goal is to prove the first safe +operation loop: -v0.5 resolves that by separating three components: +```text +facts -> judgment -> status/action -> admitted mutation -> evidence +``` -| Component | Role | +## Domain Background + +### Kubernetes CRD Status + +Kubernetes custom resources usually have two important areas: + +| Area | Meaning | |---|---| -| CSI | create/update `SwBlockVolume` identity CR | -| operator-status | publish `.status` and Events only | -| lifecycle-owner | add/release only the Seaweed Block protection finalizer | +| `.spec` | desired identity or user intent | +| `.status` | observed state written by a controller | + +A status-only controller should patch only the `/status` subresource. That keeps +observation separate from lifecycle mutation. + +### Kubernetes Finalizers + +A finalizer is a string in `metadata.finalizers`. When a user deletes an object, +Kubernetes sets `deletionTimestamp` but does not remove the object until all +finalizers are gone. + +For Seaweed Block, the finalizer is: + +```text +block.seaweedfs.com/swblockvolume-protection +``` + +The finalizer protects the `SwBlockVolume` lifecycle object from disappearing +while delete-safety evidence is missing, stale, or unsafe. + +### The CRD Finalizer Trap + +Built-in Kubernetes resources sometimes have special subresources. Generic CRDs +do not expose a useful `/finalizers` endpoint for normal finalizer mutation. In +practice, changing a CRD finalizer means patching the main object: + +```text +PATCH swblockvolumes/ +{"metadata":{"finalizers":[...]}} +``` + +That is dangerous because the same main-object patch permission can also change +other fields unless something else blocks it. + +The trap: + +```text +CRD finalizers require main-object patch +main-object patch can change spec and metadata +RBAC cannot express "only this one finalizer string" +therefore code review is not a safety boundary +``` + +This is why v0.5 needed real admission-policy proof. + +## Product Problem + +Seaweed Block needed to deliver a lifecycle behavior that feels product-owned: + +```text +user creates PVC +-> Seaweed Block creates SwBlockVolume CR +-> CR is protected by a Seaweed Block finalizer +-> user requests delete +-> unsafe evidence holds deletion +-> clean evidence releases deletion +``` + +But the product must not silently become a broad storage operator. The hard part +is preserving this boundary under retries, stale evidence, schema validation, +RBAC, and Kubernetes admission behavior. + +The easy but unsafe answer would be: + +```text +give operator-status patch swblockvolumes +let it add/remove finalizers and maybe cleanup things later +``` + +That would destroy the v0.4 claim that `operator-status` is status/events-only. + +The v0.5 answer is role separation: + +| Role | Writes | Why | +|---|---|---| +| CSI | `SwBlockVolume` identity/spec | Create the CR from the normal PVC path | +| operator-status | `.status` and Events | Publish judgment and evidence | +| lifecycle-owner | protection finalizer only | Own object lifecycle metadata | + +## Methodology + +The method follows the older problem-shape rule: + +```text +observe facts +-> apply constraints +-> decide in one place +-> execute narrowly +-> close with terminal evidence +``` + +For v0.5: + +| Step | Owner | Evidence | +|---|---|---| +| observe live volume and cleanup facts | operator-status | cluster evidence, `cleanup-summary.txt` | +| classify delete safety | operator-status | `SwBlockVolume.status.deleteSafety` | +| decide finalizer hold/release | lifecycle-owner | status decision and deletionTimestamp | +| execute mutation | lifecycle-owner | main-object patch | +| confine mutation | Kubernetes admission | ValidatingAdmissionPolicy | +| close loop | CRD status, Events, QA cleanup verifier | finalizer held/released, zero residue | + +## State Machine + +```mermaid +stateDiagram-v2 + [*] --> Active: SwBlockVolume created + Active --> Protected: lifecycle-owner adds protection finalizer + Protected --> DeleteRequested: deletionTimestamp observed + DeleteRequested --> HoldUnknown: cleanup evidence missing or stale + DeleteRequested --> HoldBlocked: cleanup residue present + HoldUnknown --> Releasable: fresh clean cleanup evidence + HoldBlocked --> Releasable: residue cleared and clean evidence observed + Releasable --> Released: lifecycle-owner removes protection finalizer + Released --> [*]: Kubernetes deletes CR +``` ## End-To-End Loop ```mermaid flowchart TD - A[Live facts: PVC, volume, cleanup evidence] --> B[operator-status judgment] - B --> C[SwBlockVolume.status deleteSafety] - C --> D{lifecycle-owner decision} - D -->|missing/stale/residue| E[hold finalizer] - D -->|allowed + releasable| F[patch finalizer list] - F --> G[VAP admits only protection finalizer shape] - G --> H[CR deletion completes] - E --> I[Warning Event + user-facing reason] - H --> J[Normal Event + zero residue gate] + A[CSI creates SwBlockVolume identity CR] --> B[lifecycle-owner adds protection finalizer] + B --> C[operator-status reads live facts] + C --> D[operator-status writes status.deleteSafety] + D --> E{lifecycle-owner decision} + E -->|missing/stale/residue| F[hold finalizer + Warning Event] + E -->|allowed/releasable| G[patch finalizer list] + G --> H[VAP admits only protection finalizer patch] + H --> I[CR deletion completes] + I --> J[cleanup verifier reports zero residue] ``` -## Delete-Safety Contract +## Delete-Safety Decision Table -| Evidence | Decision | State | Finalizer | +| Evidence | Decision | State | Finalizer behavior | |---|---|---|---| -| missing cleanup evidence | unknown | requested | held | -| stale cleanup evidence | unknown | requested | held | -| residue present | rejected | blocked | held | -| clean fresh evidence | allowed | releasable | released | +| no cleanup evidence | `unknown` | `requested` | hold | +| stale cleanup evidence | `unknown` | `requested` | hold | +| iSCSI/multipath/dmsetup/process/hostPath/K8s residue | `rejected` | `blocked` | hold | +| fresh clean cleanup evidence | `allowed` | `releasable` | release | The cleanup evidence is external. The lifecycle-owner does not execute cleanup. ## Why This Is Not Automatic Cleanup -Automatic cleanup would require an executor that mutates host or Kubernetes -state: +Automatic cleanup would mutate host or Kubernetes state: -- iSCSI session/node DB cleanup, -- multipath map cleanup, -- dmsetup cleanup, -- hostPath cleanup, -- PVC/PV/workload cleanup. +- iSCSI session or node DB records, +- multipath maps, +- dmsetup devices, +- hostPath data, +- generated Kubernetes resources, +- PVC/PV/workload objects. -Those are different risk domains. v0.5 deliberately stops before that line. -The lifecycle-owner only decides whether the `SwBlockVolume` CR may disappear. -It does not repair the world to make that decision true. +Those are separate executor domains. v0.5 deliberately stops at lifecycle +metadata: -## Main Code +```text +Can this CR be released? +``` -| Behavior | Entry point | +It does not answer: + +```text +Can the operator repair or clean the cluster? +``` + +## Implementation Map + +| Responsibility | Code / config | |---|---| -| operator-status reconcile | `core/ops/operator_status_controller.go` | +| CSI creates identity CR | `core/csi/kubernetes_metadata.go`, `core/csi/controller.go`, `cmd/blockcsi/main.go` | +| status projection | `core/ops/operator_status_controller.go` | | Kubernetes status writer | `core/ops/kubernetes_status_writer.go` | | cleanup evidence parsing | `core/ops/cleanup_evidence.go` | | delete-safety projection | `core/ops/observation_bundle.go` | | lifecycle-owner reconcile | `core/ops/lifecycle_owner_controller.go` | -| action model | `core/ops/action_model.go` | +| action vocabulary | `core/ops/action_model.go` | +| CRDs/RBAC/VAP | `charts/seaweed-block/crds/`, `charts/seaweed-block/templates/` | +| CLI entry points | `cmd/sw-block/main.go` | -## Admission Boundary +## Phase History -The lifecycle-owner needs main-object patch because CRD finalizers are mutated -through the main object. Kubernetes RBAC alone cannot express "finalizers only" -for this CRD. The boundary is therefore: - -```text -RBAC permits lifecycle-owner main patch on SwBlockVolume -AND -ValidatingAdmissionPolicy denies any patch that changes spec, status, labels, -annotations, ownerReferences, foreign finalizers, or mixed fields -``` - -## Failure History Encoded In The Design - -Several live-only failures shaped the current design: - -| Failure | Lesson | +| Phase | What changed | |---|---| -| status writer payload passed mocks but failed CRD schema | tests must hit real schema or schema-aware conformance | -| CRD condition enum rejected live node facts | status vocabulary must be shared with CRD schema | -| finalizer `/finalizers` patch returned 404 | CRDs do not expose a generic finalizers subresource endpoint | -| main-object finalizer patch returned 403 with status-only RBAC | finalizer ownership needs a separate lifecycle-owner role | -| scripted action mode rejected by CRD enum | action vocabulary must match every surface | -| VAP optional-field CEL denied legitimate patch | admission policy needs live API proof, not only template rendering | +| 35 | introduced Kubernetes-native CRD status and Events; caught schema/casing issues | +| 36 | added productized operations actionability: node, support, cleanup visibility | +| 37 | hardened live node/CSI evidence so false node-ready no longer masked blockers | +| 38 | made action contracts executable and fail-closed | +| 39 | attempted finalizer path, discovered CRD finalizer/RBAC trap, pivoted to status-only delete-safety | +| 40 | hardened status API conformance and release-image checks | +| 41 | separated observer, lifecycle-owner, executor roles | +| 42 | proved lifecycle-owner admission boundary on real Kubernetes VAP | +| 43 | proved finalizer add/release as isolated gates | +| 44 | proved integrated PVC -> protected CR -> hold/release -> zero-residue path | -The operation layer is therefore not "more YAML". It is the product result of -schema, RBAC, admission, status, and lifecycle evidence failing in realistic -ways until the boundary became explicit. +## Failures That Shaped The Design + +| Failure | Design lesson | +|---|---| +| status writer payload passed mocks but failed live CRD schema | mock tests are insufficient for CRD writer paths | +| node condition enum rejected non-healthy node facts | schema vocabulary and product vocabulary must be shared | +| finalizer `/finalizers` patch returned 404 | CRD finalizers use main-object patch | +| main-object patch returned 403 under status-only RBAC | finalizer ownership needs a separate role | +| granting main patch is too broad | admission policy must confine the shape | +| CEL optional-field access denied valid patches | admission must be tested against a real API server | + +These failures explain why the operation layer took many phases. The hard part +was not adding code. The hard part was proving the control boundary. ## QA Evidence -| Phase | Evidence | +| Gate | What it proves | |---|---| -| 41 | lifecycle-owner foundation and dry-run decision model | -| 42 | real Kubernetes ValidatingAdmissionPolicy boundary | -| 43 | finalizer add/release as isolated gates | -| 44 | integrated PVC -> protected CR -> hold/release -> zero-residue path | +| Phase 42 D1-D4 | lifecycle-owner can only add/remove the approved finalizer shape on a real VAP-capable API server | +| Phase 42 D5-D6 | delete-safety decisions are per-volume and dry-run/status-only before mutation | +| Phase 43 D1-D2 | lifecycle-owner adds the protection finalizer idempotently | +| Phase 43 D3-D4 | lifecycle-owner holds missing/blocked/stale and releases clean evidence only | +| Phase 44 D2 | normal PVC path creates protected `SwBlockVolume` CR without manual stubs | +| Phase 44 D3-D4 | integrated delete hold/release works with live status projection | +| Phase 44 D5-D6 | multi-volume delete isolation and report/dashboard/explain agreement | ## Non-Claims +- Not production-ready. - No automatic cleanup execution. -- No PVC/PV/workload deletion by operator-status or lifecycle-owner. -- No rebuild, failback, backup, or upgrade execution. -- No production operator claim. +- No PVC/PV/workload deletion. +- No host repair, iSCSI repair, or multipath repair. +- No rebuild, failback, backup, restore, or upgrade execution. +- No broad operator automation. + +## Future Work + +The next lifecycle features should reuse this pattern: + +```text +fact owner +-> judgment owner +-> action owner +-> admission/RBAC boundary +-> user-visible evidence +-> QA gate +``` + +Returned-replica rebuild, failback, and cleanup execution should not bypass this +structure. diff --git a/seaweed-block/docs/wiki/deep-dives/template.md b/seaweed-block/docs/wiki/deep-dives/template.md new file mode 100644 index 0000000000..1585fd4afb --- /dev/null +++ b/seaweed-block/docs/wiki/deep-dives/template.md @@ -0,0 +1,83 @@ +# Deep-Dive Template + +Use this template for developer-facing pages. The target reader can read code +but may not know storage, CSI, iSCSI/NVMe, WAL, or Kubernetes operator +semantics. + +## Reader Orientation + +Explain what domain this page covers and why it matters. + +```text +This page explains ... +You need this before changing ... +``` + +## Domain Background + +Introduce the industry terms and standards involved. Keep it practical: + +- What is the external system or standard? +- What does it expect from us? +- What does it not care about? +- What failure does a user see when we get it wrong? + +## Product Problem + +State the Seaweed Block-specific delivery goal and the traps: + +```text +We need to deliver ... +The dangerous easy answer is ... +The correct answer must preserve ... +``` + +## Methodology + +Answer the four questions: + +```text +what facts do we observe? +what constraints must those facts satisfy? +who is allowed to decide? +where does the decision become real? +``` + +## State Machine / Protocol + +Use Mermaid: + +```mermaid +flowchart LR + Fact --> Judgment + Judgment --> Action + Action --> Evidence +``` + +## Implementation Map + +| Responsibility | Code / config | +|---|---| +| input facts | path | +| decision | path | +| execution | path | +| evidence | path | + +## Phase History + +| Phase | Contribution | +|---|---| +| Phase X | what changed | + +Include failures that shaped the design. + +## QA Evidence + +| Gate | What it proves | What would fail | +|---|---|---| +| gate | proof | failure | + +## Non-Claims + +Name what this does not deliver yet. + diff --git a/seaweed-block/docs/wiki/developer-guide.md b/seaweed-block/docs/wiki/developer-guide.md index 959dc7ea8b..7b0949e33e 100644 --- a/seaweed-block/docs/wiki/developer-guide.md +++ b/seaweed-block/docs/wiki/developer-guide.md @@ -28,9 +28,21 @@ What is still out of scope? Do not copy a finished plan into the wiki. Instead, write the explanation a new developer needs and link to the source evidence. +Assume the reader: + +- can read Go, YAML, and shell, +- understands basic Kubernetes objects, +- does not yet understand block storage, CSI, iSCSI/NVMe, authority, fencing, + WAL recovery, or why finalizers are dangerous, +- has not followed the phase history. + Good wiki content: - problem context, +- short domain primer, +- industry terms and standards involved, +- what Seaweed Block must deliver, +- why the problem is harder than it looks, - ownership boundary, - state transition, - package/function entry point, @@ -44,6 +56,43 @@ Bad wiki content: - claims that are not backed by QA, - TODO lists without an owner or phase. +## Deep-Dive Page Standard + +Each deep-dive page should use this shape: + +```text +1. Reader orientation + What domain is this? Why should a developer care? + +2. Domain background + Explain industry terms and standards at a practical level. + +3. Product problem + What does Seaweed Block need to deliver? What can go wrong? + +4. Methodology + What facts are observed? What constraints matter? Who decides? Where does + execution happen? What evidence closes the loop? + +5. State machine / protocol diagram + Mermaid first, prose second. + +6. Implementation map + Main packages, key structs/functions, commands, Helm/RBAC surfaces. + +7. Phase history + Which phases solved which part? Name the meaningful failures too. + +8. QA evidence + Which gates prove the behavior? What would fail the gate? + +9. Non-claims and future work + What is explicitly not delivered yet? +``` + +This standard matters because historical design notes can be stale. Use them as +source material for explanation and vocabulary, not as current release claims. + ## Local Preview Install MkDocs Material and serve the site: diff --git a/seaweed-block/mkdocs.yml b/seaweed-block/mkdocs.yml index 3f7f10d935..0422720ff7 100644 --- a/seaweed-block/mkdocs.yml +++ b/seaweed-block/mkdocs.yml @@ -41,6 +41,7 @@ nav: - Phase Map: wiki/phase-map.md - QA and TestOps Map: wiki/testops-map.md - Deep Dives: + - Template: wiki/deep-dives/template.md - CSI Lifecycle: wiki/deep-dives/csi-lifecycle.md - Operation Layer v0.5: wiki/deep-dives/operation-layer-v05.md - ManagedVolume Readiness: wiki/deep-dives/managed-volume-readiness.md