From 6a9db1ff3529647fdfbc4c976a87df1105c0449c Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 14 Jun 2026 10:09:40 -0700 Subject: [PATCH] phase41: choose finalizer strategy and dry-run action --- .../ops/managed_volume_operator_contract.go | 29 ++++++ seaweed-block/core/ops/observation_bundle.go | 17 ++++ .../core/ops/observation_bundle_test.go | 8 ++ .../ops/operator_status_controller_test.go | 17 ++++ seaweed-block/internal/docs/current-plan.md | 39 +++++--- .../finalizer-delete-safety-contract.md | 22 +++-- .../ref/lifecycle-owner-finalizer-strategy.md | 97 +++++++++++++++++++ 7 files changed, 212 insertions(+), 17 deletions(-) create mode 100644 seaweed-block/internal/docs/ref/lifecycle-owner-finalizer-strategy.md diff --git a/seaweed-block/core/ops/managed_volume_operator_contract.go b/seaweed-block/core/ops/managed_volume_operator_contract.go index 3e52c3b27b..863559eb7f 100644 --- a/seaweed-block/core/ops/managed_volume_operator_contract.go +++ b/seaweed-block/core/ops/managed_volume_operator_contract.go @@ -75,9 +75,38 @@ func ManagedVolumeOperatorContractFromProjection(projection ManagedVolumeProject EvidenceRefs: append([]string(nil), action.EvidenceRefs...), }) } + if projection.DeleteSafety != nil && !hasManagedVolumeOperatorAction(contract.AllowedActions, projection.DeleteSafety.ActionType) { + contract.AllowedActions = append(contract.AllowedActions, managedVolumeOperatorActionFromDeleteSafety(*projection.DeleteSafety)) + } return contract } +func managedVolumeOperatorActionFromDeleteSafety(decision SwBlockVolumeDeleteSafetyDecision) ManagedVolumeOperatorAction { + return ManagedVolumeOperatorAction{ + Type: decision.ActionType, + Mode: ManagedVolumeActionModeDryRun, + SideEffectClass: ManagedVolumeSideEffectSafeK8S, + OwnerExecutor: "lifecycle_owner", + Decision: decision.Decision, + DecisionReason: decision.Reason, + MissingFacts: append([]string(nil), decision.MissingFacts...), + MutationAllowed: false, + Preconditions: []string{"delete_safety_evidence_current", "cleanup_residue_absent"}, + InvariantRefs: []string{"INV-LIFECYCLE-FINALIZER-001"}, + EvidenceRequired: "cleanup-summary.txt", + EvidenceRefs: append([]string(nil), decision.EvidenceRefs...), + } +} + +func hasManagedVolumeOperatorAction(actions []ManagedVolumeOperatorAction, actionType string) bool { + for _, action := range actions { + if action.Type == actionType { + return true + } + } + return false +} + func cloneSwBlockVolumeDeleteSafetyDecision(in *SwBlockVolumeDeleteSafetyDecision) *SwBlockVolumeDeleteSafetyDecision { if in == nil { return nil diff --git a/seaweed-block/core/ops/observation_bundle.go b/seaweed-block/core/ops/observation_bundle.go index 6cbdf3b02d..5dbbae6fd2 100644 --- a/seaweed-block/core/ops/observation_bundle.go +++ b/seaweed-block/core/ops/observation_bundle.go @@ -585,6 +585,7 @@ func applyDeleteSafetySummary(cluster *ClusterEvidence, summary map[string]strin } managed.DeleteSafety = &decision managed.EvidenceRefs = appendUniqueStrings(managed.EvidenceRefs, decision.EvidenceRefs...) + managed.Actions = ensureManagedVolumeAction(managed.Actions, managedVolumeActionFromDeleteSafety(decision)) switch decision.State { case DeleteSafetyStateBlocked: managed.Status = ManagedVolumeStatusBlocked @@ -618,6 +619,22 @@ func applyDeleteSafetySummary(cluster *ClusterEvidence, summary map[string]strin } } +func managedVolumeActionFromDeleteSafety(decision SwBlockVolumeDeleteSafetyDecision) ManagedVolumeAction { + return ManagedVolumeAction{ + Type: decision.ActionType, + Mode: ManagedVolumeActionModeDryRun, + SideEffectClass: ManagedVolumeSideEffectSafeK8S, + OwnerExecutor: "lifecycle_owner", + Decision: decision.Decision, + DecisionReason: decision.Reason, + MissingFacts: append([]string(nil), decision.MissingFacts...), + Preconditions: []string{"delete_safety_evidence_current", "cleanup_residue_absent"}, + InvariantRefs: []string{"INV-LIFECYCLE-FINALIZER-001"}, + EvidenceRequired: "cleanup-summary.txt", + EvidenceRefs: append([]string(nil), decision.EvidenceRefs...), + } +} + func findManagedVolumeIndex(volumes []ManagedVolumeProjection, volumeID, pvcName string) int { for i := range volumes { if volumeID != "" && volumes[i].VolumeID == volumeID { diff --git a/seaweed-block/core/ops/observation_bundle_test.go b/seaweed-block/core/ops/observation_bundle_test.go index 58a399de53..4fa7b3134d 100644 --- a/seaweed-block/core/ops/observation_bundle_test.go +++ b/seaweed-block/core/ops/observation_bundle_test.go @@ -576,6 +576,8 @@ func TestObservationBundle_DeleteSafetyBlocksWithResidue(t *testing.T) { for _, want := range []string{ "managed_volume_delete_safety=pvc-delete state=blocked decision=rejected reason=iscsi_node_records_present release_allowed=false action=safe_k8s.release_swblockvolume_finalizer", "managed_volume_delete_safety_safe_next_action=pvc-delete observe.verify_cleanup", + "managed_volume_action=safe_k8s.release_swblockvolume_finalizer mode=dry_run side_effect=safe_k8s executor=lifecycle_owner decision=rejected reason=iscsi_node_records_present", + "managed_volume_action_evidence_required=safe_k8s.release_swblockvolume_finalizer cleanup-summary.txt", } { if !strings.Contains(summary, want) { t.Fatalf("summary missing %q:\n%s", want, summary) @@ -645,6 +647,9 @@ func TestObservationBundle_DeleteSafetyUnknownWithoutCleanupEvidence(t *testing. if !strings.Contains(summary, "managed_volume_delete_safety=pvc-missing-cleanup state=requested decision=unknown reason=cleanup_evidence_missing release_allowed=false action=safe_k8s.release_swblockvolume_finalizer") { t.Fatalf("summary missing unknown delete safety:\n%s", summary) } + if !strings.Contains(summary, "managed_volume_action=safe_k8s.release_swblockvolume_finalizer mode=dry_run side_effect=safe_k8s executor=lifecycle_owner decision=unknown reason=cleanup_evidence_missing") { + t.Fatalf("summary missing unknown lifecycle-owner action:\n%s", summary) + } snapshot := BuildOperatorFoundationSnapshot(cluster) if snapshot.Volumes[0].Status.DeleteSafety == nil || snapshot.Volumes[0].Status.DeleteSafety.Decision != ManagedVolumeActionDecisionUnknown || @@ -778,6 +783,9 @@ func TestObservationBundle_DeleteSafetyReleasableWithCleanCleanupEvidence(t *tes if !strings.Contains(summary, "managed_volume_delete_safety=pvc-clean-delete state=releasable decision=allowed reason=finalizer_releasable release_allowed=true action=safe_k8s.release_swblockvolume_finalizer") { t.Fatalf("summary missing releasable delete safety:\n%s", summary) } + if !strings.Contains(summary, "managed_volume_action=safe_k8s.release_swblockvolume_finalizer mode=dry_run side_effect=safe_k8s executor=lifecycle_owner decision=allowed reason=finalizer_releasable") { + t.Fatalf("summary missing releasable lifecycle-owner action:\n%s", summary) + } snapshot := BuildOperatorFoundationSnapshot(cluster) if snapshot.Volumes[0].Status.DeleteSafety == nil || !snapshot.Volumes[0].Status.DeleteSafety.FinalizerReleaseAllowed { diff --git a/seaweed-block/core/ops/operator_status_controller_test.go b/seaweed-block/core/ops/operator_status_controller_test.go index 2ac0b588bf..48364c09d5 100644 --- a/seaweed-block/core/ops/operator_status_controller_test.go +++ b/seaweed-block/core/ops/operator_status_controller_test.go @@ -679,12 +679,29 @@ func TestOperatorStatusReconcilerProjectsDeleteSafetyWithoutFinalizerMutation(t writer.volumes[0].status.DeleteSafety.Decision != ManagedVolumeActionDecisionRejected { t.Fatalf("delete safety status=%+v", writer.volumes[0].status.DeleteSafety) } + action := findCRDAction(writer.volumes[0].status.AllowedActions, SwBlockVolumeDeleteActionReleaseFinalizer) + if action == nil || + action.Mode != ManagedVolumeActionModeDryRun || + action.OwnerExecutor != "lifecycle_owner" || + action.MutationAllowed || + action.Decision != ManagedVolumeActionDecisionRejected { + t.Fatalf("lifecycle-owner dry-run action=%+v", action) + } if events.countByReason(ReasonDeleteFinalizerAdded) != 0 || events.countByReason(ReasonDeleteFinalizerReleased) != 0 { t.Fatalf("operator-status must not emit finalizer mutation events: %+v", events.events) } } +func findCRDAction(actions []SwBlockVolumeCRDAction, typ string) *SwBlockVolumeCRDAction { + for i := range actions { + if actions[i].Type == typ { + return &actions[i] + } + } + return nil +} + func TestOperatorStatusReconcilerDeleteSafetyDoesNotContaminateOtherVolumes(t *testing.T) { source := fakeOperatorStatusSource{cluster: ClusterEvidence{ SchemaVersion: ObservationSchemaVersion, diff --git a/seaweed-block/internal/docs/current-plan.md b/seaweed-block/internal/docs/current-plan.md index 4d029b8f81..33167fc2ad 100644 --- a/seaweed-block/internal/docs/current-plan.md +++ b/seaweed-block/internal/docs/current-plan.md @@ -149,16 +149,19 @@ operator-status remains status/events-only Goal: decide whether Phase 41 lands a finalizer mutation or stops at a documented design block. +Status: dev-complete, awaiting review. Phase 41 defers finalizer mutation and +continues with a dry-run/status lifecycle-owner path. + Acceptance: ```text -[ ] explicitly choose one strategy: +[x] explicitly choose one strategy: - lifecycle-owner owns finalizer mutation with main-object patch RBAC, or - finalizer mutation is deferred to a future CSI/lifecycle controller -[ ] if lifecycle-owner owns it, add admission/code/RBAC proof that spec and +[x] if lifecycle-owner owns it, add admission/code/RBAC proof that spec and storage mutation stay forbidden -[ ] if deferred, document the exact future owner and release non-claim -[ ] user-facing impact is documented for PVC/CR deletion +[x] if deferred, document the exact future owner and release non-claim +[x] user-facing impact is documented for PVC/CR deletion ``` Verification: @@ -174,16 +177,19 @@ envtest/live-apiserver proof for the chosen strategy Goal: if D4 approves mutation, implement only finalizer add/remove. If D4 defers mutation, implement the dry-run lifecycle-owner status path instead. +Status: dev-complete, awaiting QA/review. D4 deferred mutation, so D5 shipped +the dry-run lifecycle-owner status path. + Acceptance: ```text -[ ] disabled by default or explicitly beta-gated -[ ] no storage/workload/host cleanup is executed -[ ] clean volume: finalizer release is allowed and audited -[ ] blocked volume: finalizer release is rejected and audited -[ ] repeated reconciles are idempotent -[ ] Events are bounded and stable -[ ] operator-status RBAC remains unchanged +[x] disabled by default or explicitly beta-gated +[x] no storage/workload/host cleanup is executed +[x] clean volume: finalizer release is allowed and audited +[x] blocked volume: finalizer release is rejected and audited +[x] repeated reconciles are idempotent +[x] Events are bounded and stable +[x] operator-status RBAC remains unchanged ``` Verification: @@ -271,6 +277,17 @@ git diff --check `cleanup_observed_at`, and stale cleanup evidence produces `decision=unknown reason=cleanup_evidence_stale` instead of allowing finalizer release. +- 56%: D4 strategy dev-complete. Added + `internal/docs/ref/lifecycle-owner-finalizer-strategy.md`. Phase 41 will not + ship finalizer add/remove because the future lifecycle owner still lacks a + real API/admission proof for main-object patch confinement. The release + non-claim remains: delete-safety is status-only guidance, not Kubernetes + deletion protection. +- 70%: D5 dev-complete. Delete-safety decisions now project a dry-run + `safe_k8s.release_swblockvolume_finalizer` lifecycle-owner action across + report, operator-snapshot, and CRD allowedActions. Clean evidence produces + `decision=allowed`, residue produces `decision=rejected`, and missing/stale + evidence produces `decision=unknown`; all carry `mutationAllowed=false`. ## Prerequisites / Risks diff --git a/seaweed-block/internal/docs/protocol/finalizer-delete-safety-contract.md b/seaweed-block/internal/docs/protocol/finalizer-delete-safety-contract.md index 8f699ffc76..6fb3951d58 100644 --- a/seaweed-block/internal/docs/protocol/finalizer-delete-safety-contract.md +++ b/seaweed-block/internal/docs/protocol/finalizer-delete-safety-contract.md @@ -38,11 +38,12 @@ vocabulary: ```text action_type=safe_k8s.release_swblockvolume_finalizer -decision=allowed|rejected +decision=allowed|rejected|unknown ``` -The action is allowed only when the delete state is `releasable`. Missing -cleanup evidence, residue, or no active delete request rejects the action. +The action is allowed only when the delete state is `releasable`. Residue or no +active delete request rejects the action. Missing or stale cleanup evidence is +`unknown`, not allowed. ## Delete States @@ -50,7 +51,7 @@ cleanup evidence, residue, or no active delete request rejects the action. |---|---| | `not_requested` | No delete request is active. | | `requested` | Delete request exists; evidence has not yet been classified. | -| `blocked` | Delete was requested, but cleanup/evidence is missing or unsafe. | +| `blocked` | Delete was requested, and cleanup evidence proves residue or unsafe state. | | `releasable` | Delete was requested and cleanup evidence is clean. The operator may remove the finalizer. | | `released` | Finalizer removal has been observed or emitted as an event. | @@ -74,12 +75,21 @@ cleanup.hostpath_residue_count If cleanup evidence is missing, the safe decision is: ```text -state=blocked -decision=rejected +state=requested +decision=unknown reason=cleanup_evidence_missing safe_next_action=observe.verify_cleanup ``` +If cleanup evidence is stale, the safe decision is: + +```text +state=requested +decision=unknown +reason=cleanup_evidence_stale +safe_next_action=observe.verify_cleanup +``` + If residue evidence exists, the safe decision is: ```text diff --git a/seaweed-block/internal/docs/ref/lifecycle-owner-finalizer-strategy.md b/seaweed-block/internal/docs/ref/lifecycle-owner-finalizer-strategy.md new file mode 100644 index 0000000000..0fa1d73b95 --- /dev/null +++ b/seaweed-block/internal/docs/ref/lifecycle-owner-finalizer-strategy.md @@ -0,0 +1,97 @@ +# Lifecycle Owner Finalizer Strategy + +Status: Phase 41 D4 strategy decision. + +## Decision + +Phase 41 does **not** ship `SwBlockVolume` finalizer add/remove. + +The selected strategy is: + +```text +defer finalizer mutation until a lifecycle-owner component has real +Kubernetes API/RBAC/admission proof. +``` + +Phase 41 may continue building the lifecycle-owner decision model and dry-run +status path, but no component gains production `patch swblockvolumes` on the +main CRD object in this slice. + +The dry-run status path is represented as: + +```text +action=safe_k8s.release_swblockvolume_finalizer +mode=dry_run +executor=lifecycle_owner +mutation_allowed=false +decision=allowed|rejected|unknown +``` + +This is an executable contract shape for future lifecycle-owner work. It is not +finalizer execution. + +## Why + +Phase 39 live QA proved two Kubernetes facts: + +1. CRDs do not expose a usable HTTP `/finalizers` endpoint. +2. Changing `metadata.finalizers` on a CRD requires main-object + `patch swblockvolumes`. + +That permission is too broad for the released `operator-status` component. The +whole v0.4 beta claim is that `operator-status` is status/events-only. Giving it +main-object patch would invalidate that boundary. + +Phase 41 D2 adds a schema-aware boundary gate showing what a future lifecycle +owner must prove: + +- observer/status writer cannot patch the main object, +- lifecycle owner can only issue a finalizer-shaped patch, +- spec and unrelated metadata patches are rejected, +- fake `/finalizers` endpoint is rejected. + +However, D2 is not yet a full live-apiserver/admission gate. Until that exists, +shipping actual finalizer mutation would be a code-enforced promise, not a +Kubernetes-enforced product boundary. + +## User Impact + +Current user-facing behavior remains: + +- `SwBlockVolume.status.deleteSafety` says whether finalizer release would be + allowed, rejected, or unknown. +- Cleanup residue and stale/missing evidence are visible with stable reasons. +- `operator-status` creates Events and writes status only. +- Seaweed Block does not yet hold Kubernetes deletion with its own finalizer. + +This is safer than a weak finalizer controller. Users get accurate visibility +without a controller that can patch the whole CR object. + +## Release Non-Claim + +Until the future lifecycle-owner gate passes, releases must keep this visible +non-claim: + +```text +No SwBlockVolume finalizer ownership or finalizer add/remove. +Delete-safety is status-only guidance, not Kubernetes deletion protection. +``` + +## Future Path To Enable Finalizers + +A later phase may choose Path A from +`internal/docs/ref/lifecycle-owner-control-contract.md` if it can prove all of: + +```text +1. a separate lifecycle-owner component or mode exists, +2. it has minimal main-object patch permission, +3. admission or equivalent enforcement admits only metadata.finalizers patches, +4. spec and unrelated metadata patches fail against a real API server, +5. clean delete-safety permits finalizer release, +6. blocked, missing, or stale delete-safety prevents release, +7. multi-volume isolation holds, +8. cleanup verifier ends clean after the gate. +``` + +If those proofs are not available, the product should keep finalizer mutation +deferred.