diff --git a/seaweed-block/charts/seaweed-block/crds/swblockvolumes.block.seaweedfs.com.yaml b/seaweed-block/charts/seaweed-block/crds/swblockvolumes.block.seaweedfs.com.yaml index aff25e789c..b37f47fb78 100644 --- a/seaweed-block/charts/seaweed-block/crds/swblockvolumes.block.seaweedfs.com.yaml +++ b/seaweed-block/charts/seaweed-block/crds/swblockvolumes.block.seaweedfs.com.yaml @@ -108,6 +108,38 @@ spec: type: array items: type: string + deleteSafety: + type: object + properties: + actionType: + type: string + decision: + type: string + enum: + - allowed + - rejected + state: + type: string + enum: + - not_requested + - requested + - blocked + - releasable + - released + reason: + type: string + finalizerReleaseAllowed: + type: boolean + missingFacts: + type: array + items: + type: string + evidenceRefs: + type: array + items: + type: string + safeNextAction: + type: string nonClaims: type: array items: diff --git a/seaweed-block/core/ops/kubernetes_crd_manifests_test.go b/seaweed-block/core/ops/kubernetes_crd_manifests_test.go index 2f19f30f11..ec2c2f0b37 100644 --- a/seaweed-block/core/ops/kubernetes_crd_manifests_test.go +++ b/seaweed-block/core/ops/kubernetes_crd_manifests_test.go @@ -163,6 +163,22 @@ func TestPhase38D3SwBlockVolumeAllowedActionEvaluationSchema(t *testing.T) { } } +func TestPhase39D2SwBlockVolumeDeleteSafetySchema(t *testing.T) { + doc := readYAMLMap(t, "charts/seaweed-block/crds/swblockvolumes.block.seaweedfs.com.yaml") + statusProperties := crdStatusProperties(t, doc) + deleteSafetyProperties := yamlMap(t, yamlMap(t, statusProperties, "deleteSafety"), "properties") + for _, want := range []string{"actionType", "decision", "state", "reason", "finalizerReleaseAllowed", "missingFacts", "evidenceRefs", "safeNextAction"} { + if _, ok := deleteSafetyProperties[want]; !ok { + t.Fatalf("SwBlockVolume.status.deleteSafety schema missing %s", want) + } + } + for _, forbidden := range []string{"action_type", "finalizer_release_allowed", "safe_next_action"} { + if _, ok := deleteSafetyProperties[forbidden]; ok { + t.Fatalf("SwBlockVolume.status.deleteSafety schema leaked snake_case %s", forbidden) + } + } +} + func TestPhase35D1OperatorStatusRBACIsStatusOnly(t *testing.T) { raw := readRepoFile(t, "charts/seaweed-block/templates/operator-status-rbac.yaml") required := []string{ diff --git a/seaweed-block/core/ops/kubernetes_status_writer_test.go b/seaweed-block/core/ops/kubernetes_status_writer_test.go index 5e56184ebc..35e01d8487 100644 --- a/seaweed-block/core/ops/kubernetes_status_writer_test.go +++ b/seaweed-block/core/ops/kubernetes_status_writer_test.go @@ -57,6 +57,14 @@ func TestKubernetesStatusClientPatchesOnlyStatusSubresources(t *testing.T) { Status: ManagedVolumeStatusReady, ReasonCode: ReasonFirstVolumeVerified, ObservedAt: observedAt, + DeleteSafety: &SwBlockVolumeCRDDeleteSafety{ + ActionType: SwBlockVolumeDeleteActionReleaseFinalizer, + Decision: ManagedVolumeActionDecisionAllowed, + State: DeleteSafetyStateReleasable, + Reason: ReasonDeleteFinalizerReleasable, + FinalizerReleaseAllowed: true, + EvidenceRefs: []string{"cleanup-summary.txt"}, + }, AllowedActions: []SwBlockVolumeCRDAction{{ Type: "observe.collect_bundle", Mode: "read_only", @@ -116,6 +124,18 @@ func TestKubernetesStatusClientPatchesOnlyStatusSubresources(t *testing.T) { if _, ok := action["evidence_required"]; ok { t.Fatalf("volume action leaked snake_case evidence_required: %+v", action) } + deleteSafety := volumeStatus["deleteSafety"].(map[string]any) + if _, ok := deleteSafety["finalizerReleaseAllowed"]; !ok { + t.Fatalf("deleteSafety missing camelCase finalizerReleaseAllowed: %+v", deleteSafety) + } + if _, ok := deleteSafety["actionType"]; !ok { + t.Fatalf("deleteSafety missing camelCase actionType: %+v", deleteSafety) + } + for _, forbidden := range []string{"finalizer_release_allowed", "action_type", "safe_next_action"} { + if _, ok := deleteSafety[forbidden]; ok { + t.Fatalf("deleteSafety leaked snake_case %s: %+v", forbidden, deleteSafety) + } + } } func TestKubernetesStatusClientCreatesCoreEvents(t *testing.T) { diff --git a/seaweed-block/core/ops/managed_volume_model.go b/seaweed-block/core/ops/managed_volume_model.go index 235b5c25e8..eb253eed09 100644 --- a/seaweed-block/core/ops/managed_volume_model.go +++ b/seaweed-block/core/ops/managed_volume_model.go @@ -197,21 +197,22 @@ type WorkloadCheckFact struct { } type ManagedVolumeProjection struct { - VolumeID string `json:"volume_id,omitempty"` - Namespace string `json:"namespace,omitempty"` - PVCName string `json:"pvc_name,omitempty"` - PVName string `json:"pv_name,omitempty"` - StorageClass string `json:"storage_class,omitempty"` - ReplicationFactor int `json:"replication_factor,omitempty"` - AckProfile string `json:"ack_profile,omitempty"` - ClaimProfile string `json:"claim_profile,omitempty"` - Status string `json:"status"` - ReasonCode string `json:"reason_code,omitempty"` - States ManagedVolumeStates `json:"states"` - Actions []ManagedVolumeAction `json:"actions,omitempty"` - Conditions []ObservationCondition `json:"conditions,omitempty"` - NonClaims []string `json:"non_claims,omitempty"` - EvidenceRefs []string `json:"evidence_refs,omitempty"` + VolumeID string `json:"volume_id,omitempty"` + Namespace string `json:"namespace,omitempty"` + PVCName string `json:"pvc_name,omitempty"` + PVName string `json:"pv_name,omitempty"` + StorageClass string `json:"storage_class,omitempty"` + ReplicationFactor int `json:"replication_factor,omitempty"` + AckProfile string `json:"ack_profile,omitempty"` + ClaimProfile string `json:"claim_profile,omitempty"` + Status string `json:"status"` + ReasonCode string `json:"reason_code,omitempty"` + States ManagedVolumeStates `json:"states"` + Actions []ManagedVolumeAction `json:"actions,omitempty"` + Conditions []ObservationCondition `json:"conditions,omitempty"` + DeleteSafety *SwBlockVolumeDeleteSafetyDecision `json:"delete_safety,omitempty"` + NonClaims []string `json:"non_claims,omitempty"` + EvidenceRefs []string `json:"evidence_refs,omitempty"` } type ManagedVolumeStates struct { @@ -264,6 +265,20 @@ func RenderManagedVolumeProjectionText(projection ManagedVolumeProjection) strin emptyAsDash(projection.States.HostPath), emptyAsDash(projection.States.Recovery), emptyAsDash(projection.States.Workload)) + if projection.DeleteSafety != nil { + fmt.Fprintf(&b, "managed_volume_delete_safety state=%s decision=%s reason=%s release_allowed=%t action=%s\n", + emptyAsDash(projection.DeleteSafety.State), + emptyAsDash(projection.DeleteSafety.Decision), + emptyAsDash(projection.DeleteSafety.Reason), + projection.DeleteSafety.FinalizerReleaseAllowed, + emptyAsDash(projection.DeleteSafety.ActionType)) + if projection.DeleteSafety.SafeNextAction != "" { + fmt.Fprintf(&b, "managed_volume_delete_safety_safe_next_action %s\n", projection.DeleteSafety.SafeNextAction) + } + if len(projection.DeleteSafety.EvidenceRefs) > 0 { + fmt.Fprintf(&b, "managed_volume_delete_safety_evidence %s\n", strings.Join(projection.DeleteSafety.EvidenceRefs, ",")) + } + } for _, condition := range projection.Conditions { fmt.Fprintf(&b, "managed_volume_condition %s status=%s reason=%s severity=%s", emptyAsDash(condition.Type), diff --git a/seaweed-block/core/ops/managed_volume_operator_contract.go b/seaweed-block/core/ops/managed_volume_operator_contract.go index ae85134116..3e52c3b27b 100644 --- a/seaweed-block/core/ops/managed_volume_operator_contract.go +++ b/seaweed-block/core/ops/managed_volume_operator_contract.go @@ -9,13 +9,14 @@ type ManagedVolumeOperatorContract struct { } type ManagedVolumeOperatorStatus struct { - VolumeID string `json:"volume_id,omitempty"` - PVCName string `json:"pvc_name,omitempty"` - Status string `json:"status"` - ReasonCode string `json:"reason_code,omitempty"` - Conditions []ObservationCondition `json:"conditions,omitempty"` - NonClaims []string `json:"non_claims,omitempty"` - EvidenceRefs []string `json:"evidence_refs,omitempty"` + VolumeID string `json:"volume_id,omitempty"` + PVCName string `json:"pvc_name,omitempty"` + Status string `json:"status"` + ReasonCode string `json:"reason_code,omitempty"` + Conditions []ObservationCondition `json:"conditions,omitempty"` + DeleteSafety *SwBlockVolumeDeleteSafetyDecision `json:"delete_safety,omitempty"` + NonClaims []string `json:"non_claims,omitempty"` + EvidenceRefs []string `json:"evidence_refs,omitempty"` } type ManagedVolumeOperatorEvent struct { @@ -50,6 +51,7 @@ func ManagedVolumeOperatorContractFromProjection(projection ManagedVolumeProject Status: projection.Status, ReasonCode: projection.ReasonCode, Conditions: append([]ObservationCondition(nil), projection.Conditions...), + DeleteSafety: cloneSwBlockVolumeDeleteSafetyDecision(projection.DeleteSafety), NonClaims: append([]string(nil), projection.NonClaims...), EvidenceRefs: append([]string(nil), projection.EvidenceRefs...), }, @@ -76,6 +78,16 @@ func ManagedVolumeOperatorContractFromProjection(projection ManagedVolumeProject return contract } +func cloneSwBlockVolumeDeleteSafetyDecision(in *SwBlockVolumeDeleteSafetyDecision) *SwBlockVolumeDeleteSafetyDecision { + if in == nil { + return nil + } + out := *in + out.MissingFacts = append([]string(nil), in.MissingFacts...) + out.EvidenceRefs = append([]string(nil), in.EvidenceRefs...) + return &out +} + func managedVolumeOperatorEventFromCondition(condition ObservationCondition) ManagedVolumeOperatorEvent { eventType := "Normal" if condition.Severity == "warning" { diff --git a/seaweed-block/core/ops/observation_bundle.go b/seaweed-block/core/ops/observation_bundle.go index fff0af26db..2e436e3c3c 100644 --- a/seaweed-block/core/ops/observation_bundle.go +++ b/seaweed-block/core/ops/observation_bundle.go @@ -22,6 +22,7 @@ const ( ObservationCleanupSummaryArtifact = "cleanup-summary.txt" ObservationHostPrereqArtifact = "host-prereq-summary.txt" ObservationLoopbackAttachArtifact = "unsupported-cross-node-loopback-attach.txt" + ObservationDeleteSafetyArtifact = "swblockvolume-delete-summary.txt" NodeLossRecoverySummaryArtifact = "node-loss-recovery-summary.txt" PrimaryFailureRecoveryArtifact = "primary-failure-recovery.txt" @@ -91,6 +92,10 @@ func BuildObservationFromBundle(opts ObservationBundleOptions) (ClusterEvidence, applyUnsupportedLoopbackAttachSummary(&cluster, loopbackAttach, loopbackAttachPath) sourceLoaded = true } + deleteSafety, deleteSafetyPath, _ := loadKeyValueArtifact(opts.Dir, ObservationDeleteSafetyArtifact) + if len(deleteSafety) > 0 { + sourceLoaded = true + } if blocked, blockedVolume := buildImagePullBlockedEvidence(opts.Dir); blocked { cluster.Status = ObservationStatusBlocked sourceLoaded = true @@ -114,6 +119,9 @@ func BuildObservationFromBundle(opts ObservationBundleOptions) (ClusterEvidence, NodeLoss: summary, PrimaryFailure: primaryFailure, }) + if len(deleteSafety) > 0 { + applyDeleteSafetySummary(&cluster, deleteSafety, deleteSafetyPath) + } return cluster, nil } @@ -521,6 +529,121 @@ func applyUnsupportedLoopbackAttachSummary(cluster *ClusterEvidence, summary map cluster.Status = ObservationStatusBlocked } +func applyDeleteSafetySummary(cluster *ClusterEvidence, summary map[string]string, evidencePath string) { + volumeID := strings.TrimSpace(summary["volume_id"]) + pvcName := strings.TrimSpace(summary["pvc_name"]) + pvName := strings.TrimSpace(summary["pv_name"]) + deleteRequested := boolFromSummaryDefault(summary, "delete_requested", true) + finalizerPresent := boolFromSummaryDefault(summary, "finalizer_present", true) + if len(cluster.ManagedVolumes) == 0 && len(cluster.Volumes) > 0 { + *cluster = NormalizeObservationCluster(*cluster) + } + idx := findManagedVolumeIndex(cluster.ManagedVolumes, volumeID, pvcName) + if idx < 0 { + cluster.ManagedVolumes = append(cluster.ManagedVolumes, ManagedVolumeProjection{ + VolumeID: volumeID, + PVCName: pvcName, + PVName: pvName, + Status: ManagedVolumeStatusUnknown, + ReasonCode: ReasonCleanupEvidenceMissing, + States: ManagedVolumeStates{ + Kubernetes: ManagedVolumeKubernetesUnknown, + Authority: ManagedVolumeAuthorityUnknown, + CSI: ManagedVolumeCSIUnknown, + HostPath: ManagedVolumeHostPathUnknown, + Recovery: ManagedVolumeRecoveryNone, + Workload: ManagedVolumeWorkloadUnknown, + }, + }) + idx = len(cluster.ManagedVolumes) - 1 + } + managed := &cluster.ManagedVolumes[idx] + if managed.VolumeID == "" { + managed.VolumeID = volumeID + } + if managed.PVCName == "" { + managed.PVCName = pvcName + } + if managed.PVName == "" { + managed.PVName = pvName + } + decision := EvaluateSwBlockVolumeDeleteSafety(SwBlockVolumeDeleteSafetyFacts{ + DeleteRequested: deleteRequested, + FinalizerPresent: finalizerPresent, + Cleanup: cluster.Cleanup, + }) + if evidencePath != "" { + decision.EvidenceRefs = appendUniqueStrings(decision.EvidenceRefs, evidencePath) + } + managed.DeleteSafety = &decision + managed.EvidenceRefs = appendUniqueStrings(managed.EvidenceRefs, decision.EvidenceRefs...) + switch decision.State { + case DeleteSafetyStateBlocked: + managed.Status = ManagedVolumeStatusBlocked + managed.ReasonCode = decision.Reason + managed.Conditions = ensureCondition(managed.Conditions, ObservationCondition{ + Type: ConditionCleanupRequired, + Status: "True", + Reason: decision.Reason, + Severity: "warning", + Message: "delete is blocked until cleanup evidence is clean", + EvidenceRefs: append([]string(nil), decision.EvidenceRefs...), + }) + managed.Actions = ensureManagedVolumeAction(managed.Actions, ManagedVolumeAction{ + Type: ManagedVolumeActionVerifyCleanup, + Mode: ManagedVolumeActionModeScripted, + SideEffectClass: ManagedVolumeSideEffectObserve, + OwnerExecutor: "ops", + Decision: ManagedVolumeActionDecisionAllowed, + EvidenceRequired: "cleanup-summary.txt", + EvidenceRefs: append([]string(nil), decision.EvidenceRefs...), + }) + case DeleteSafetyStateReleasable: + managed.Conditions = ensureCondition(managed.Conditions, ObservationCondition{ + Type: ConditionCleanupRequired, + Status: "False", + Reason: ReasonCleanupVerified, + Severity: "info", + Message: "delete finalizer is releasable; cleanup evidence is clean", + EvidenceRefs: append([]string(nil), decision.EvidenceRefs...), + }) + } +} + +func findManagedVolumeIndex(volumes []ManagedVolumeProjection, volumeID, pvcName string) int { + for i := range volumes { + if volumeID != "" && volumes[i].VolumeID == volumeID { + return i + } + if pvcName != "" && volumes[i].PVCName == pvcName { + return i + } + } + return -1 +} + +func boolFromSummaryDefault(summary map[string]string, key string, defaultValue bool) bool { + value := strings.TrimSpace(summary[key]) + if value == "" { + return defaultValue + } + parsed, err := strconv.ParseBool(value) + if err != nil { + return defaultValue + } + return parsed +} + +func ensureManagedVolumeAction(actions []ManagedVolumeAction, action ManagedVolumeAction) []ManagedVolumeAction { + for i := range actions { + if actions[i].Type == action.Type { + actions[i] = action + return actions + } + } + return append(actions, action) +} + func ensureObservationNode(cluster *ClusterEvidence, nodeName string) int { for i, node := range cluster.Nodes { if node.NodeName == nodeName || node.KubernetesNode == nodeName || node.PhysicalHost == nodeName { diff --git a/seaweed-block/core/ops/observation_bundle_test.go b/seaweed-block/core/ops/observation_bundle_test.go index 36ce342586..a7feca0c5a 100644 --- a/seaweed-block/core/ops/observation_bundle_test.go +++ b/seaweed-block/core/ops/observation_bundle_test.go @@ -478,6 +478,147 @@ func TestObservationBundle_CarriesUnsupportedLoopbackAttachIntoManagedStatus(t * assertDashboardEndpointContains(t, server.URL+"/"+ObservationReportTextArtifact, "managed_volume=pvc-loopback status=blocked reason=publish_target_loopback_cross_node") } +func TestObservationBundle_DeleteSafetyBlocksWithResidue(t *testing.T) { + dir := t.TempDir() + writeProductClusterEvidence(t, dir, []VolumeEvidence{{ + VolumeID: "pvc-delete", + Namespace: "default", + PVCName: "delete-pvc", + PVName: "pv-delete", + ReplicationFactor: 1, + Status: ObservationStatusOK, + PrimaryReplica: "r1", + PrimaryNode: "m01", + PublishTarget: "192.168.1.181:3260", + Replicas: []ReplicaEvidence{{ + ReplicaID: "r1", + KubernetesNode: "m01", + Observed: true, + Role: "primary", + FrontendAddr: "192.168.1.181:3260", + }}, + }}) + mustWrite(t, filepath.Join(dir, ObservationCleanupSummaryArtifact), strings.Join([]string{ + "cleanup_status=failed", + "iscsi_residue_count=1", + "reason_codes=iscsi_node_records_present", + }, "\n")) + mustWrite(t, filepath.Join(dir, ObservationDeleteSafetyArtifact), strings.Join([]string{ + "delete_requested=true", + "finalizer_present=true", + "volume_id=pvc-delete", + "pvc_name=delete-pvc", + "pv_name=pv-delete", + }, "\n")) + + cluster, err := BuildObservationFromBundle(ObservationBundleOptions{Dir: dir, VolumeID: "pvc-delete"}) + if err != nil { + t.Fatal(err) + } + managed := managedProjectionForVolume(cluster.ManagedVolumes, "pvc-delete") + if managed.DeleteSafety == nil { + t.Fatalf("missing delete safety: %+v", managed) + } + if managed.Status != ManagedVolumeStatusBlocked || + managed.ReasonCode != "iscsi_node_records_present" || + managed.DeleteSafety.State != DeleteSafetyStateBlocked || + managed.DeleteSafety.Decision != ManagedVolumeActionDecisionRejected || + managed.DeleteSafety.FinalizerReleaseAllowed { + t.Fatalf("managed=%+v delete=%+v", managed, managed.DeleteSafety) + } + if !hasManagedVolumeAction(managed.Actions, ManagedVolumeActionVerifyCleanup) { + t.Fatalf("missing verify cleanup action: %+v", managed.Actions) + } + if condition := findObservationCondition(managed.Conditions, ConditionCleanupRequired); condition == nil || + condition.Status != "True" || + condition.Reason != "iscsi_node_records_present" { + t.Fatalf("cleanup condition=%+v", condition) + } + + summary := RenderObservationReportSummary(cluster) + 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", + } { + if !strings.Contains(summary, want) { + t.Fatalf("summary missing %q:\n%s", want, summary) + } + } + explain := RenderObservationExplainText(cluster) + if !strings.Contains(explain, "managed_volume_delete_safety state=blocked decision=rejected reason=iscsi_node_records_present release_allowed=false action=safe_k8s.release_swblockvolume_finalizer") { + t.Fatalf("explain missing delete safety:\n%s", explain) + } + snapshot := BuildOperatorFoundationSnapshot(cluster) + if snapshot.Volumes[0].Status.DeleteSafety == nil || + snapshot.Volumes[0].Status.DeleteSafety.State != DeleteSafetyStateBlocked { + t.Fatalf("snapshot delete safety=%+v", snapshot.Volumes[0].Status.DeleteSafety) + } + server := httptest.NewServer(NewObservationDashboardHandler(cluster)) + defer server.Close() + assertDashboardEndpointContains(t, server.URL+"/"+ObservationOperatorSnapshotArtifact, `"delete_safety": {`) + assertDashboardEndpointContains(t, server.URL+"/"+ObservationOperatorSnapshotArtifact, `"state": "blocked"`) + assertDashboardEndpointContains(t, server.URL+"/"+ObservationOperatorSnapshotArtifact, `"reason": "iscsi_node_records_present"`) +} + +func TestObservationBundle_DeleteSafetyReleasableWithCleanCleanupEvidence(t *testing.T) { + dir := t.TempDir() + writeProductClusterEvidence(t, dir, []VolumeEvidence{{ + VolumeID: "pvc-clean-delete", + Namespace: "default", + PVCName: "clean-pvc", + PVName: "pv-clean", + ReplicationFactor: 1, + Status: ObservationStatusOK, + PrimaryReplica: "r1", + PrimaryNode: "m01", + PublishTarget: "192.168.1.181:3260", + Replicas: []ReplicaEvidence{{ + ReplicaID: "r1", + KubernetesNode: "m01", + Observed: true, + Role: "primary", + FrontendAddr: "192.168.1.181:3260", + }}, + }}) + mustWrite(t, filepath.Join(dir, ObservationCleanupSummaryArtifact), "cleanup_status=ok") + mustWrite(t, filepath.Join(dir, ObservationDeleteSafetyArtifact), strings.Join([]string{ + "delete_requested=true", + "finalizer_present=true", + "volume_id=pvc-clean-delete", + "pvc_name=clean-pvc", + "pv_name=pv-clean", + }, "\n")) + + cluster, err := BuildObservationFromBundle(ObservationBundleOptions{Dir: dir, VolumeID: "pvc-clean-delete"}) + if err != nil { + t.Fatal(err) + } + managed := managedProjectionForVolume(cluster.ManagedVolumes, "pvc-clean-delete") + if managed.DeleteSafety == nil || + managed.DeleteSafety.State != DeleteSafetyStateReleasable || + managed.DeleteSafety.Decision != ManagedVolumeActionDecisionAllowed || + !managed.DeleteSafety.FinalizerReleaseAllowed { + t.Fatalf("managed=%+v delete=%+v", managed, managed.DeleteSafety) + } + if managed.Status == ManagedVolumeStatusBlocked { + t.Fatalf("clean delete evidence must not block managed volume: %+v", managed) + } + if condition := findObservationCondition(managed.Conditions, ConditionCleanupRequired); condition == nil || + condition.Status != "False" || + condition.Reason != ReasonCleanupVerified { + t.Fatalf("cleanup condition=%+v", condition) + } + summary := RenderObservationReportSummary(cluster) + 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) + } + snapshot := BuildOperatorFoundationSnapshot(cluster) + if snapshot.Volumes[0].Status.DeleteSafety == nil || + !snapshot.Volumes[0].Status.DeleteSafety.FinalizerReleaseAllowed { + t.Fatalf("snapshot delete safety=%+v", snapshot.Volumes[0].Status.DeleteSafety) + } +} + func TestObservationBundle_LoopbackAttachTargetsNamedVolume(t *testing.T) { dir := t.TempDir() writeProductClusterEvidence(t, dir, []VolumeEvidence{ diff --git a/seaweed-block/core/ops/observation_report.go b/seaweed-block/core/ops/observation_report.go index e641052ee3..dbaf06c3f2 100644 --- a/seaweed-block/core/ops/observation_report.go +++ b/seaweed-block/core/ops/observation_report.go @@ -127,6 +127,20 @@ func renderManagedProjectionSummary(b *strings.Builder, managed ManagedVolumePro emptyAsDash(condition.Reason), emptyAsDash(condition.Severity)) } + if managed.DeleteSafety != nil { + fmt.Fprintf(b, "managed_volume_delete_safety=%s state=%s decision=%s reason=%s release_allowed=%t action=%s\n", + emptyAsDash(managed.VolumeID), + emptyAsDash(managed.DeleteSafety.State), + emptyAsDash(managed.DeleteSafety.Decision), + emptyAsDash(managed.DeleteSafety.Reason), + managed.DeleteSafety.FinalizerReleaseAllowed, + emptyAsDash(managed.DeleteSafety.ActionType)) + if managed.DeleteSafety.SafeNextAction != "" { + fmt.Fprintf(b, "managed_volume_delete_safety_safe_next_action=%s %s\n", + emptyAsDash(managed.VolumeID), + managed.DeleteSafety.SafeNextAction) + } + } for _, action := range managed.Actions { fmt.Fprintf(b, "managed_volume_action=%s mode=%s side_effect=%s executor=%s decision=%s", emptyAsDash(action.Type), diff --git a/seaweed-block/core/ops/operator_status_controller.go b/seaweed-block/core/ops/operator_status_controller.go index acff2dbe2e..c12ffdce76 100644 --- a/seaweed-block/core/ops/operator_status_controller.go +++ b/seaweed-block/core/ops/operator_status_controller.go @@ -216,15 +216,27 @@ func supportBundleReason(cluster ClusterEvidence) string { } type SwBlockVolumeCRDStatus struct { - VolumeID string `json:"volumeID,omitempty"` - PVCName string `json:"pvcName,omitempty"` - Status string `json:"status"` - ReasonCode string `json:"reasonCode,omitempty"` - ObservedAt time.Time `json:"observedAt,omitempty"` - Conditions []ObservationCondition `json:"conditions,omitempty"` - NonClaims []string `json:"nonClaims,omitempty"` - EvidenceRefs []string `json:"evidenceRefs,omitempty"` - AllowedActions []SwBlockVolumeCRDAction `json:"allowedActions,omitempty"` + VolumeID string `json:"volumeID,omitempty"` + PVCName string `json:"pvcName,omitempty"` + Status string `json:"status"` + ReasonCode string `json:"reasonCode,omitempty"` + ObservedAt time.Time `json:"observedAt,omitempty"` + Conditions []ObservationCondition `json:"conditions,omitempty"` + DeleteSafety *SwBlockVolumeCRDDeleteSafety `json:"deleteSafety,omitempty"` + NonClaims []string `json:"nonClaims,omitempty"` + EvidenceRefs []string `json:"evidenceRefs,omitempty"` + AllowedActions []SwBlockVolumeCRDAction `json:"allowedActions,omitempty"` +} + +type SwBlockVolumeCRDDeleteSafety struct { + ActionType string `json:"actionType,omitempty"` + Decision string `json:"decision,omitempty"` + State string `json:"state,omitempty"` + Reason string `json:"reason,omitempty"` + FinalizerReleaseAllowed bool `json:"finalizerReleaseAllowed"` + MissingFacts []string `json:"missingFacts,omitempty"` + EvidenceRefs []string `json:"evidenceRefs,omitempty"` + SafeNextAction string `json:"safeNextAction,omitempty"` } type SwBlockVolumeCRDAction struct { @@ -330,6 +342,7 @@ func (r OperatorStatusReconciler) Reconcile(ctx context.Context) (OperatorStatus ReasonCode: volume.Status.ReasonCode, ObservedAt: observedAt, Conditions: append([]ObservationCondition(nil), volume.Status.Conditions...), + DeleteSafety: swBlockVolumeCRDDeleteSafety(volume.Status.DeleteSafety), NonClaims: append([]string(nil), volume.Status.NonClaims...), EvidenceRefs: append([]string(nil), volume.Status.EvidenceRefs...), AllowedActions: swBlockVolumeCRDActions(volume.AllowedActions), @@ -357,6 +370,22 @@ func (r OperatorStatusReconciler) Reconcile(ctx context.Context) (OperatorStatus return result, nil } +func swBlockVolumeCRDDeleteSafety(decision *SwBlockVolumeDeleteSafetyDecision) *SwBlockVolumeCRDDeleteSafety { + if decision == nil { + return nil + } + return &SwBlockVolumeCRDDeleteSafety{ + ActionType: decision.ActionType, + Decision: decision.Decision, + State: decision.State, + Reason: decision.Reason, + FinalizerReleaseAllowed: decision.FinalizerReleaseAllowed, + MissingFacts: append([]string(nil), decision.MissingFacts...), + EvidenceRefs: append([]string(nil), decision.EvidenceRefs...), + SafeNextAction: decision.SafeNextAction, + } +} + func swBlockVolumeCRDActions(actions []ManagedVolumeOperatorAction) []SwBlockVolumeCRDAction { if len(actions) == 0 { return nil diff --git a/seaweed-block/internal/docs/current-plan.md b/seaweed-block/internal/docs/current-plan.md index d27a35f61c..fa0b029d7a 100644 --- a/seaweed-block/internal/docs/current-plan.md +++ b/seaweed-block/internal/docs/current-plan.md @@ -1,6 +1,6 @@ # Current Plan: Phase 39 - Finalizer / Delete Safety -Status: active, 14% complete. Started on 2026-06-10. +Status: active, 28% complete. Started on 2026-06-10. Branch: `phase33-testops-failure-hardening` @@ -82,16 +82,16 @@ internal review of finalizer/delete contract doc Goal: before adding finalizer mutation, prove delete-requested and delete-blocked states project correctly from evidence. -Status: pending. +Status: dev-complete; QA/internal review pending. Acceptance: ```text -[ ] deletionTimestamp-like evidence projects DeletionRequested/Blocked status -[ ] residue evidence projects CleanupRequired=True and reason=cleanup_required -[ ] clean evidence projects delete releasable, not false blocked -[ ] report, explain, dashboard, operator-snapshot, and CRD status agree -[ ] no finalizer mutation is enabled yet +[x] deletionTimestamp-like evidence projects DeletionRequested/Blocked status +[x] residue evidence projects CleanupRequired=True and reason=cleanup_required +[x] clean evidence projects delete releasable, not false blocked +[x] report, explain, dashboard, operator-snapshot, and CRD status agree +[x] no finalizer mutation is enabled yet ``` Verification: @@ -233,6 +233,13 @@ QA strict rerun from clean lab owned mutation scope, required cleanup/identity facts, delete states, non-claims, and a pure decision function that blocks missing/residue evidence and marks clean evidence as releasable without performing mutation. +- 28%: D2 dev-complete. Bundle replay can carry + `swblockvolume-delete-summary.txt` plus cleanup evidence into + ManagedVolume delete-safety status. Residue/missing cleanup evidence projects + blocked/rejected with `CleanupRequired=True`; clean evidence projects + releasable/allowed without falsely blocking the volume. Summary, explain, + operator-snapshot, dashboard JSON, and `SwBlockVolume.status.deleteSafety` + use the same vocabulary. ## Prerequisites / Risks @@ -245,6 +252,5 @@ QA strict rerun from clean lab ## Next Step -Run D1 review/QA, then start D2: project delete-requested, delete-blocked, and -delete-releasable states through status surfaces before enabling finalizer -mutation. +Run D1/D2 review, then start D3: add the minimum finalizer metadata mutation +boundary and RBAC without storage/workload mutation.