diff --git a/seaweed-block/cmd/sw-block/main.go b/seaweed-block/cmd/sw-block/main.go index fd672354de..a58592b302 100644 --- a/seaweed-block/cmd/sw-block/main.go +++ b/seaweed-block/cmd/sw-block/main.go @@ -167,6 +167,7 @@ func runOpsOperatorStatus(args []string, stdout, stderr io.Writer) int { var ( dryRun bool fromBundle string + cleanupSummary string namespace string masterAddr string masterAPIAddr string @@ -179,6 +180,7 @@ func runOpsOperatorStatus(args []string, stdout, stderr io.Writer) int { ) fs.BoolVar(&dryRun, "dry-run", false, "render the status projection without writing Kubernetes CRD status") fs.StringVar(&fromBundle, "from-bundle", "", "existing inventory/support bundle directory to project") + fs.StringVar(&cleanupSummary, "cleanup-summary", "", "cleanup-summary.txt evidence to project into delete-safety status") fs.StringVar(&namespace, "namespace", "default", "Kubernetes namespace for live read-only inventory") fs.StringVar(&masterAddr, "master", "", "optional blockmaster gRPC address for live per-replica status evidence") fs.StringVar(&masterAPIAddr, "master-api", "", "optional blockmaster gRPC address for ClusterEvidenceService read-only snapshot") @@ -219,9 +221,18 @@ func runOpsOperatorStatus(args []string, stdout, stderr io.Writer) int { if code != ops.VolumeStatusExitOK { return code } + if cleanupSummary != "" { + cleanup, err := ops.LoadCleanupEvidenceSummary(cleanupSummary) + if err != nil { + fmt.Fprintf(stderr, "sw-block ops operator-status: %v\n", err) + return ops.VolumeStatusExitInvalid + } + cluster.Cleanup = cleanup + } mode := "write_status" var writer ops.OperatorStatusWriter var events ops.OperatorEventSink + var volumes ops.OperatorSwBlockVolumeSource if dryRun { mode = "dry_run" writer = &operatorStatusDryRunWriter{} @@ -234,12 +245,14 @@ func runOpsOperatorStatus(args []string, stdout, stderr io.Writer) int { return ops.VolumeStatusExitInvalid } events, _ = writer.(ops.OperatorEventSink) + volumes, _ = writer.(ops.OperatorSwBlockVolumeSource) } result, err := (ops.OperatorStatusReconciler{ Namespace: namespace, ClusterName: clusterName, Source: operatorStatusClusterSource{cluster: cluster}, Writer: writer, + Volumes: volumes, EventSink: events, }).Reconcile(context.Background()) if err != nil { @@ -1540,7 +1553,7 @@ func usage(w io.Writer) { fmt.Fprintln(w, " sw-block ops dashboard --master-api [--listen 127.0.0.1:9334]") fmt.Fprintln(w, " sw-block ops generate-helm-values --out values.yaml [--target-node ] [--replication-factor ]") fmt.Fprintln(w, " [--restart-persistence ephemeral|hostpath] [--state-hostpath /var/lib/sw-block] [--timeout 10s]") - fmt.Fprintln(w, " sw-block ops operator-status --dry-run [--master-api |--from-bundle ] [--interval 30s]") + fmt.Fprintln(w, " sw-block ops operator-status --dry-run [--master-api |--from-bundle ] [--cleanup-summary ] [--interval 30s]") fmt.Fprintln(w, " sw-block ops lifecycle-owner [--dry-run] [--namespace ] [--interval 30s]") } diff --git a/seaweed-block/core/ops/cleanup_evidence.go b/seaweed-block/core/ops/cleanup_evidence.go index 07337f8cdc..3356104682 100644 --- a/seaweed-block/core/ops/cleanup_evidence.go +++ b/seaweed-block/core/ops/cleanup_evidence.go @@ -1,7 +1,9 @@ package ops import ( + "bufio" "fmt" + "os" "strconv" "strings" "time" @@ -60,6 +62,27 @@ func CleanupEvidenceFromSummary(summary map[string]string, evidencePath string) return cleanup } +func LoadCleanupEvidenceSummary(path string) (*CleanupEvidence, error) { + raw, err := os.Open(path) + if err != nil { + return nil, fmt.Errorf("read cleanup summary: %w", err) + } + defer raw.Close() + summary := map[string]string{} + scanner := bufio.NewScanner(raw) + for scanner.Scan() { + line := strings.TrimSpace(scanner.Text()) + key, value, ok := strings.Cut(line, "=") + if ok { + summary[strings.TrimSpace(key)] = strings.TrimSpace(value) + } + } + if err := scanner.Err(); err != nil { + return nil, fmt.Errorf("read cleanup summary: %w", err) + } + return CleanupEvidenceFromSummary(summary, path), nil +} + func (cleanup CleanupEvidence) ReportSummaryLines() []string { lines := []string{ fmt.Sprintf("%s=%s", CleanupSummaryStatusKey, emptyAsDash(cleanup.Status)), diff --git a/seaweed-block/core/ops/cleanup_evidence_test.go b/seaweed-block/core/ops/cleanup_evidence_test.go index d4124dbe80..6a7e37ea80 100644 --- a/seaweed-block/core/ops/cleanup_evidence_test.go +++ b/seaweed-block/core/ops/cleanup_evidence_test.go @@ -1,6 +1,8 @@ package ops import ( + "os" + "path/filepath" "strings" "testing" "time" @@ -73,6 +75,20 @@ func TestCleanupEvidenceProjectionMarksCleanStatusOK(t *testing.T) { } } +func TestLoadCleanupEvidenceSummary(t *testing.T) { + path := filepath.Join(t.TempDir(), "cleanup-summary.txt") + if err := os.WriteFile(path, []byte("cleanup_status=ok\ncleanup_observed_at=2026-06-16T10:05:00Z\ncleanup_evidence=cleanup-summary.txt\n"), 0o600); err != nil { + t.Fatal(err) + } + cleanup, err := LoadCleanupEvidenceSummary(path) + if err != nil { + t.Fatalf("load: %v", err) + } + if cleanup == nil || cleanup.Status != ObservationStatusOK || cleanup.EvidenceRef != path || cleanup.ObservedAt.IsZero() { + t.Fatalf("cleanup=%+v", cleanup) + } +} + func TestCleanupEvidenceRejectsNegativeCounters(t *testing.T) { cleanup := CleanupEvidenceFromSummary(map[string]string{ CleanupSummaryStatusKey: "failed", diff --git a/seaweed-block/core/ops/kubernetes_status_writer.go b/seaweed-block/core/ops/kubernetes_status_writer.go index 6e93dfbda9..17fd24f80a 100644 --- a/seaweed-block/core/ops/kubernetes_status_writer.go +++ b/seaweed-block/core/ops/kubernetes_status_writer.go @@ -113,6 +113,7 @@ func (c *KubernetesStatusClient) ListSwBlockVolumes(ctx context.Context, namespa }, Finalizers: append([]string(nil), item.Metadata.Finalizers...), DeletionTimestamp: item.Metadata.DeletionTimestamp, + Spec: item.Spec, Status: item.Status, }) } @@ -329,5 +330,6 @@ type kubernetesSwBlockVolumeList struct { type kubernetesSwBlockVolume struct { Metadata kubernetesMetadata `json:"metadata"` + Spec SwBlockVolumeSpec `json:"spec"` Status SwBlockVolumeCRDStatus `json:"status"` } diff --git a/seaweed-block/core/ops/kubernetes_status_writer_test.go b/seaweed-block/core/ops/kubernetes_status_writer_test.go index b7215e6d04..0b097d98cd 100644 --- a/seaweed-block/core/ops/kubernetes_status_writer_test.go +++ b/seaweed-block/core/ops/kubernetes_status_writer_test.go @@ -249,6 +249,7 @@ func TestKubernetesStatusClientListsSwBlockVolumesForLifecycleOwner(t *testing.T "items": [ { "metadata":{"name":"a","namespace":"kube-system","finalizers":["example.com/foreign"]}, + "spec":{"pvcName":"pvc-a","storageClass":"seaweed-block"}, "status":{"status":"ready","deleteSafety":{"state":"releasable","decision":"allowed","finalizerReleaseAllowed":true}} }, {"metadata":{"name":"b","deletionTimestamp":"` + deletingAt + `"}} @@ -271,6 +272,9 @@ func TestKubernetesStatusClientListsSwBlockVolumesForLifecycleOwner(t *testing.T !stringSliceContains(volumes[0].Finalizers, "example.com/foreign") { t.Fatalf("volume a=%+v", volumes[0]) } + if volumes[0].Spec.PVCName != "pvc-a" || volumes[0].Spec.StorageClass != "seaweed-block" { + t.Fatalf("volume a spec=%+v", volumes[0].Spec) + } if volumes[0].Status.DeleteSafety == nil || !volumes[0].Status.DeleteSafety.FinalizerReleaseAllowed { t.Fatalf("volume a status=%+v", volumes[0].Status) } diff --git a/seaweed-block/core/ops/lifecycle_owner_controller.go b/seaweed-block/core/ops/lifecycle_owner_controller.go index edcd005979..f205c58fcd 100644 --- a/seaweed-block/core/ops/lifecycle_owner_controller.go +++ b/seaweed-block/core/ops/lifecycle_owner_controller.go @@ -15,9 +15,15 @@ type SwBlockVolumeObject struct { Ref OperatorObjectRef `json:"ref"` Finalizers []string `json:"finalizers,omitempty"` DeletionTimestamp *time.Time `json:"deletionTimestamp,omitempty"` + Spec SwBlockVolumeSpec `json:"spec,omitempty"` Status SwBlockVolumeCRDStatus } +type SwBlockVolumeSpec struct { + PVCName string `json:"pvcName,omitempty"` + StorageClass string `json:"storageClass,omitempty"` +} + type LifecycleOwnerReconciler struct { Namespace string Client LifecycleOwnerClient diff --git a/seaweed-block/core/ops/observation_bundle.go b/seaweed-block/core/ops/observation_bundle.go index 5dbbae6fd2..44fb8a2be2 100644 --- a/seaweed-block/core/ops/observation_bundle.go +++ b/seaweed-block/core/ops/observation_bundle.go @@ -536,20 +536,35 @@ func applyUnsupportedLoopbackAttachSummary(cluster *ClusterEvidence, summary map } 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) + applyDeleteSafetyFacts(cluster, deleteSafetyProjectionFacts{ + 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), + EvidencePath: evidencePath, + }) +} + +type deleteSafetyProjectionFacts struct { + VolumeID string + PVCName string + PVName string + DeleteRequested bool + FinalizerPresent bool + EvidencePath string +} + +func applyDeleteSafetyFacts(cluster *ClusterEvidence, facts deleteSafetyProjectionFacts) { if len(cluster.ManagedVolumes) == 0 && len(cluster.Volumes) > 0 { *cluster = NormalizeObservationCluster(*cluster) } - idx := findManagedVolumeIndex(cluster.ManagedVolumes, volumeID, pvcName) + idx := findManagedVolumeIndex(cluster.ManagedVolumes, facts.VolumeID, facts.PVCName) if idx < 0 { cluster.ManagedVolumes = append(cluster.ManagedVolumes, ManagedVolumeProjection{ - VolumeID: volumeID, - PVCName: pvcName, - PVName: pvName, + VolumeID: facts.VolumeID, + PVCName: facts.PVCName, + PVName: facts.PVName, Status: ManagedVolumeStatusUnknown, ReasonCode: ReasonCleanupEvidenceMissing, States: ManagedVolumeStates{ @@ -565,31 +580,68 @@ func applyDeleteSafetySummary(cluster *ClusterEvidence, summary map[string]strin } managed := &cluster.ManagedVolumes[idx] if managed.VolumeID == "" { - managed.VolumeID = volumeID + managed.VolumeID = facts.VolumeID } if managed.PVCName == "" { - managed.PVCName = pvcName + managed.PVCName = facts.PVCName } if managed.PVName == "" { - managed.PVName = pvName + managed.PVName = facts.PVName } decision := EvaluateSwBlockVolumeDeleteSafety(SwBlockVolumeDeleteSafetyFacts{ - DeleteRequested: deleteRequested, - FinalizerPresent: finalizerPresent, + DeleteRequested: facts.DeleteRequested, + FinalizerPresent: facts.FinalizerPresent, Cleanup: cluster.Cleanup, ObservedAt: cluster.CapturedAt, MaxEvidenceAge: 15 * time.Minute, }) - if evidencePath != "" { - decision.EvidenceRefs = appendUniqueStrings(decision.EvidenceRefs, evidencePath) + if facts.EvidencePath != "" { + decision.EvidenceRefs = appendUniqueStrings(decision.EvidenceRefs, facts.EvidencePath) } managed.DeleteSafety = &decision managed.EvidenceRefs = appendUniqueStrings(managed.EvidenceRefs, decision.EvidenceRefs...) managed.Actions = ensureManagedVolumeAction(managed.Actions, managedVolumeActionFromDeleteSafety(decision)) switch decision.State { + case DeleteSafetyStateRequested: + if decision.Decision == ManagedVolumeActionDecisionUnknown { + managed.Status = ManagedVolumeStatusUnknown + managed.ReasonCode = decision.Reason + managed.Conditions = ensureCondition(removeConditionType(managed.Conditions, ConditionReady), ObservationCondition{ + Type: ConditionReady, + Status: "Unknown", + Reason: decision.Reason, + Severity: "warning", + Message: "delete is held until cleanup evidence is available and fresh", + EvidenceRefs: append([]string(nil), decision.EvidenceRefs...), + }) + managed.Conditions = ensureCondition(managed.Conditions, ObservationCondition{ + Type: ConditionEvidenceStale, + Status: "True", + Reason: decision.Reason, + Severity: "warning", + Message: "delete-safety evidence is missing or stale", + EvidenceRefs: append([]string(nil), decision.EvidenceRefs...), + }) + } case DeleteSafetyStateBlocked: managed.Status = ManagedVolumeStatusBlocked managed.ReasonCode = decision.Reason + managed.Conditions = ensureCondition(removeConditionType(managed.Conditions, ConditionReady), ObservationCondition{ + Type: ConditionReady, + Status: "False", + Reason: decision.Reason, + Severity: "warning", + Message: "delete is blocked until cleanup evidence is clean", + EvidenceRefs: append([]string(nil), decision.EvidenceRefs...), + }) + managed.Conditions = ensureCondition(managed.Conditions, ObservationCondition{ + Type: ConditionBlocked, + Status: "True", + Reason: decision.Reason, + Severity: "warning", + Message: "delete-safety evidence blocks finalizer release", + EvidenceRefs: append([]string(nil), decision.EvidenceRefs...), + }) managed.Conditions = ensureCondition(managed.Conditions, ObservationCondition{ Type: ConditionCleanupRequired, Status: "True", diff --git a/seaweed-block/core/ops/observation_bundle_test.go b/seaweed-block/core/ops/observation_bundle_test.go index 4fa7b3134d..b5e8142363 100644 --- a/seaweed-block/core/ops/observation_bundle_test.go +++ b/seaweed-block/core/ops/observation_bundle_test.go @@ -639,8 +639,8 @@ func TestObservationBundle_DeleteSafetyUnknownWithoutCleanupEvidence(t *testing. managed.DeleteSafety.FinalizerReleaseAllowed { t.Fatalf("managed=%+v delete=%+v", managed, managed.DeleteSafety) } - if managed.Status != ManagedVolumeStatusReady { - t.Fatalf("missing cleanup evidence must not falsify data-plane readiness: %+v", managed) + if managed.Status != ManagedVolumeStatusUnknown || managed.ReasonCode != ReasonCleanupEvidenceMissing { + t.Fatalf("missing cleanup evidence must not claim Ready: %+v", managed) } summary := RenderObservationReportSummary(cluster) diff --git a/seaweed-block/core/ops/operator_status_controller.go b/seaweed-block/core/ops/operator_status_controller.go index 7d3576c775..bb1746221d 100644 --- a/seaweed-block/core/ops/operator_status_controller.go +++ b/seaweed-block/core/ops/operator_status_controller.go @@ -23,6 +23,10 @@ type OperatorStatusWriter interface { WriteVolumeStatus(ctx context.Context, ref OperatorObjectRef, status SwBlockVolumeCRDStatus) error } +type OperatorSwBlockVolumeSource interface { + ListSwBlockVolumes(ctx context.Context, namespace string) ([]SwBlockVolumeObject, error) +} + type OperatorEventSink interface { EmitEvent(ctx context.Context, event OperatorKubernetesEvent) error } @@ -311,6 +315,7 @@ type OperatorStatusReconciler struct { ClusterName string Source OperatorStatusSource Writer OperatorStatusWriter + Volumes OperatorSwBlockVolumeSource EventSink OperatorEventSink Now func() time.Time } @@ -334,13 +339,19 @@ func (r OperatorStatusReconciler) Reconcile(ctx context.Context) (OperatorStatus return OperatorStatusReconcileResult{}, err } cluster = NormalizeObservationCluster(cluster) + namespace := defaultString(r.Namespace, "default") + if r.Volumes != nil { + if err := r.applyLiveDeleteSafety(ctx, namespace, &cluster); err != nil { + return OperatorStatusReconcileResult{}, err + } + cluster = NormalizeObservationCluster(cluster) + } snapshot := BuildOperatorFoundationSnapshot(cluster) observedAt := cluster.CapturedAt if observedAt.IsZero() { observedAt = r.now()() } - namespace := defaultString(r.Namespace, "default") clusterName := defaultString(r.ClusterName, DefaultSwBlockClusterName) clusterRef := OperatorObjectRef{ APIVersion: SwBlockVolumeAPIVersion, @@ -415,6 +426,28 @@ func (r OperatorStatusReconciler) Reconcile(ctx context.Context) (OperatorStatus return result, nil } +func (r OperatorStatusReconciler) applyLiveDeleteSafety(ctx context.Context, namespace string, cluster *ClusterEvidence) error { + volumes, err := r.Volumes.ListSwBlockVolumes(ctx, namespace) + if err != nil { + return err + } + for _, volume := range volumes { + if volume.DeletionTimestamp == nil { + continue + } + volumeID := volume.Status.VolumeID + pvcName := firstNonEmpty(volume.Status.PVCName, volume.Spec.PVCName, volume.Ref.Name) + applyDeleteSafetyFacts(cluster, deleteSafetyProjectionFacts{ + VolumeID: volumeID, + PVCName: pvcName, + DeleteRequested: true, + FinalizerPresent: lifecycleOwnerStringSliceContains(volume.Finalizers, SwBlockVolumeFinalizerName), + EvidencePath: "swblockvolume/" + volume.Ref.Namespace + "/" + volume.Ref.Name, + }) + } + return nil +} + func swBlockVolumeCRDDeleteSafety(decision *SwBlockVolumeDeleteSafetyDecision) *SwBlockVolumeCRDDeleteSafety { if decision == nil { return nil diff --git a/seaweed-block/core/ops/operator_status_controller_test.go b/seaweed-block/core/ops/operator_status_controller_test.go index 92e26890b4..2f7db71db1 100644 --- a/seaweed-block/core/ops/operator_status_controller_test.go +++ b/seaweed-block/core/ops/operator_status_controller_test.go @@ -841,6 +841,125 @@ func TestOperatorStatusReconcilerDeleteSafetyDoesNotContaminateOtherVolumes(t *t } } +func TestPhase44OperatorStatusReconcilerProjectsLiveDeletingVolumeHold(t *testing.T) { + deletingAt := time.Date(2026, 6, 16, 10, 0, 0, 0, time.UTC) + source := fakeOperatorStatusSource{cluster: ClusterEvidence{ + SchemaVersion: ObservationSchemaVersion, + CapturedAt: deletingAt, + Status: ObservationStatusOK, + ManagedVolumes: []ManagedVolumeProjection{{ + VolumeID: "pvc-live", + PVCName: "live-pvc", + Status: ManagedVolumeStatusReady, + ReasonCode: ReasonFirstVolumeVerified, + Conditions: []ObservationCondition{{ + Type: ConditionReady, + Status: "True", + Reason: ReasonFirstVolumeVerified, + Severity: "info", + }}, + }}, + }} + writer := &fakeOperatorStatusWriter{} + result, err := (OperatorStatusReconciler{ + Namespace: "kube-system", + Source: source, + Writer: writer, + Volumes: fakeOperatorSwBlockVolumeSource{volumes: []SwBlockVolumeObject{{ + Ref: OperatorObjectRef{ + Namespace: "kube-system", + Name: "live-pvc", + }, + Finalizers: []string{SwBlockVolumeFinalizerName}, + DeletionTimestamp: &deletingAt, + Spec: SwBlockVolumeSpec{PVCName: "live-pvc"}, + Status: SwBlockVolumeCRDStatus{ + VolumeID: "pvc-live", + PVCName: "live-pvc", + }, + }}}, + }).Reconcile(context.Background()) + if err != nil { + t.Fatalf("reconcile: %v", err) + } + if result.FinalizerPatchCount != 0 { + t.Fatalf("operator-status must not patch finalizers: %d", result.FinalizerPatchCount) + } + if len(writer.volumes) != 1 { + t.Fatalf("volume writes=%+v", writer.volumes) + } + got := writer.volumes[0].status + if got.Status != ManagedVolumeStatusUnknown || got.ReasonCode != ReasonCleanupEvidenceMissing { + t.Fatalf("deleting volume with missing evidence must not stay ready: %+v", got) + } + if got.DeleteSafety == nil || + got.DeleteSafety.Decision != ManagedVolumeActionDecisionUnknown || + got.DeleteSafety.State != DeleteSafetyStateRequested || + got.DeleteSafety.Reason != ReasonCleanupEvidenceMissing { + t.Fatalf("delete safety=%+v", got.DeleteSafety) + } + action := findCRDAction(got.AllowedActions, SwBlockVolumeDeleteActionReleaseFinalizer) + if action == nil || + action.Decision != ManagedVolumeActionDecisionUnknown || + action.MutationAllowed || + action.Mode != ManagedVolumeActionModeDryRun { + t.Fatalf("release action=%+v", action) + } +} + +func TestPhase44OperatorStatusReconcilerProjectsLiveDeletingVolumeRelease(t *testing.T) { + observedAt := time.Date(2026, 6, 16, 10, 5, 0, 0, time.UTC) + source := fakeOperatorStatusSource{cluster: ClusterEvidence{ + SchemaVersion: ObservationSchemaVersion, + CapturedAt: observedAt, + Status: ObservationStatusOK, + Cleanup: &CleanupEvidence{ + Status: ObservationStatusOK, + EvidenceRef: "cleanup-summary.txt", + ObservedAt: observedAt, + }, + ManagedVolumes: []ManagedVolumeProjection{{ + VolumeID: "pvc-clean", + PVCName: "clean-pvc", + Status: ManagedVolumeStatusReady, + ReasonCode: ReasonFirstVolumeVerified, + }}, + }} + writer := &fakeOperatorStatusWriter{} + _, err := (OperatorStatusReconciler{ + Namespace: "kube-system", + Source: source, + Writer: writer, + Volumes: fakeOperatorSwBlockVolumeSource{volumes: []SwBlockVolumeObject{{ + Ref: OperatorObjectRef{ + Namespace: "kube-system", + Name: "clean-pvc", + }, + Finalizers: []string{"example.com/foreign", SwBlockVolumeFinalizerName}, + DeletionTimestamp: &observedAt, + Spec: SwBlockVolumeSpec{PVCName: "clean-pvc"}, + Status: SwBlockVolumeCRDStatus{ + VolumeID: "pvc-clean", + PVCName: "clean-pvc", + }, + }}}, + }).Reconcile(context.Background()) + if err != nil { + t.Fatalf("reconcile: %v", err) + } + got := writer.volumes[0].status + if got.DeleteSafety == nil || + !got.DeleteSafety.FinalizerReleaseAllowed || + got.DeleteSafety.Decision != ManagedVolumeActionDecisionAllowed || + got.DeleteSafety.State != DeleteSafetyStateReleasable { + t.Fatalf("delete safety=%+v", got.DeleteSafety) + } + action := findCRDAction(got.AllowedActions, SwBlockVolumeDeleteActionReleaseFinalizer) + if action == nil || action.Decision != ManagedVolumeActionDecisionAllowed || action.MutationAllowed { + t.Fatalf("release action=%+v", action) + } +} + func TestPhase40D2VolumeStatusClearsStaleDeleteSafety(t *testing.T) { status := SwBlockVolumeCRDStatus{ VolumeID: "pvc-ready", @@ -881,6 +1000,14 @@ func (f fakeOperatorStatusSource) ClusterEvidence(context.Context) (ClusterEvide return f.cluster, nil } +type fakeOperatorSwBlockVolumeSource struct { + volumes []SwBlockVolumeObject +} + +func (f fakeOperatorSwBlockVolumeSource) ListSwBlockVolumes(context.Context, string) ([]SwBlockVolumeObject, error) { + return append([]SwBlockVolumeObject(nil), f.volumes...), nil +} + type fakeOperatorStatusWriter struct { cluster OperatorStatusWriterClusterRecord volumes []OperatorStatusWriterVolumeRecord diff --git a/seaweed-block/internal/docs/current-plan.md b/seaweed-block/internal/docs/current-plan.md index 180fc9509c..a8e7adf601 100644 --- a/seaweed-block/internal/docs/current-plan.md +++ b/seaweed-block/internal/docs/current-plan.md @@ -1,6 +1,6 @@ # Current Plan: Phase 44 - Delete Lifecycle Close Gate -Status: open, 0% complete. Started on 2026-06-15. +Status: open, D2 PASS; D3/D4 implementation ready for QA. Started on 2026-06-15. Branch: `phase41-lifecycle-owner-foundation` @@ -107,6 +107,14 @@ Acceptance: Fail if unsafe evidence releases the finalizer. +Implementation note: + +```text +operator-status now lists live SwBlockVolume objects and projects deleteSafety +for objects with deletionTimestamp. Cleanup remains external evidence: pass the +verifier output with --cleanup-summary; operator-status reads it, never runs it. +``` + ## D4: Clean Evidence Releases And Deletion Completes Goal: clean, fresh evidence releases only the Seaweed Block finalizer. @@ -173,14 +181,22 @@ Phase 44 can close only if: ## Current Progress -- D2 implementation started: normal CSI CreateVolume now registers the +- D2 implementation landed in `e56b844`: normal CSI CreateVolume registers the SwBlockVolume identity CR when operator-status or lifecycle-owner surfaces are enabled. -- Local checks pass for the D2 implementation: +- D2 QA PASS: + `internal/docs/qa-assignments/phase44-d2-integrated-swblockvolume-cr-qa-signoff.md`. +- D3/D4 implementation added: operator-status consumes live deleting + SwBlockVolume objects plus externally generated `cleanup-summary.txt` + evidence to publish deleteSafety hold/release status. It still does not patch + finalizers, run cleanup, or mutate PVC/PV/workloads/storage. +- Local checks pass: `go test ./core/csi ./cmd/blockcsi`, `go test ./core/ops ./cmd/sw-block`, and `helm lint charts/seaweed-block`. - D2 QA assignment prepared: `internal/docs/qa-assignments/phase44-d2-integrated-swblockvolume-cr-qa.md`. +- D3/D4 QA assignment prepared: + `internal/docs/qa-assignments/phase44-d3-d4-delete-lifecycle-close-gate-qa.md`. - Phase 43 already proved add and release as separate live gates. - Phase 44 must prove the integrated path and release wording. @@ -196,8 +212,8 @@ Phase 44 can close only if: ## Next Step -Build or publish a candidate image from the current branch, then author/run the -D1-D4 integrated live scenario: +Build fresh `sw-block` and `sw-block-csi` candidate images from this branch, then +run the D3/D4 integrated live scenario: ```text install with operatorStatus + lifecycleOwner @@ -205,6 +221,6 @@ create first PVC observe protection finalizer request delete prove hold under unsafe evidence -patch/provide clean delete-safety evidence +provide clean delete-safety evidence via --cleanup-summary prove finalizer release and object deletion ``` diff --git a/seaweed-block/internal/docs/qa-assignments/phase44-d2-integrated-swblockvolume-cr-qa-signoff.md b/seaweed-block/internal/docs/qa-assignments/phase44-d2-integrated-swblockvolume-cr-qa-signoff.md new file mode 100644 index 0000000000..8207f5fde2 --- /dev/null +++ b/seaweed-block/internal/docs/qa-assignments/phase44-d2-integrated-swblockvolume-cr-qa-signoff.md @@ -0,0 +1,130 @@ +# QA Sign-off — Phase 44 D2 Integrated SwBlockVolume Creation And Protection + +Verdict: **PASS.** The normal Day-1 PVC path now automatically produces the +Kubernetes object the bounded delete lifecycle needs, end-to-end and with no +manual stub creation: + +```text +CSI CreateVolume -> SwBlockVolume CR exists (CSI owns identity/spec) + -> lifecycle-owner adds the protection finalizer + -> operator-status writes Ready=True / first_volume_verified + Events +``` + +The three-way ownership split holds (CSI = metadata/spec identity, operator-status += `.status`, lifecycle-owner = the protection finalizer), default installs stay +backward-compatible, and cleanup is zero-residue. Validated live on a real +VAP-capable cluster with fresh candidate images. + +Date: 2026-06-16 +Source: branch `phase41-lifecycle-owner-foundation` @ `e56b844 phase44: register +swblockvolume from csi create` +Images: fresh `sw-block:local` **and** `sw-block-csi:local` built from `e56b844` +(the CSI image now carries `--swblockvolume-cr-namespace`; older CSI images do +not), imported to m01+m02. +Environment: m02 k3s **v1.34.4+k3s1** (ValidatingAdmissionPolicy enforced). +Install: `--set operatorStatus.create=true --set operatorStatus.dryRun=false +--set lifecycleOwner.create=true --set lifecycleOwner.dryRun=false`. + +## G1 — Local Contract — PASS + +- `go test ./core/csi ./cmd/blockcsi ./core/ops ./cmd/sw-block` → `ok` (all). +- `helm lint` → 0 failed. +- Default render does **not** include `--swblockvolume-cr-namespace` (count 0). +- Enabled render includes `--swblockvolume-cr-namespace=kube-system`. +- Enabled render grants the CSI controller ClusterRole + (`sw-block-seaweed-block-csi-controller`, bound to SA + `sw-block-seaweed-block-csi`) `swblockvolumes [get,list,watch,create,update,patch]` + — and **no** `swblockvolumes/status` or `swblockvolumes/finalizers`. + +## G2 — Live Install And First Volume — PASS + +Install succeeded; `csi-controller (3/3)`, `csi-node (2/2)`, `blockmaster (1/1)`, +`operator-status (1/1)`, `lifecycle-owner (1/1)` Running. First-volume: +`first_volume_status=ok`, `writer_verified=true`, `reader_verified=true` (PVC +`sw-block-example-pvc`, volume `pvc-9ea507bd-...`). + +## G3 — SwBlockVolume CR Exists — PASS + +```text +count: 1 +NAME=sw-block-example-pvc .spec.pvcName=sw-block-example-pvc +.metadata.finalizers=[block.seaweedfs.com/swblockvolume-protection] (exactly one) +``` + +Exactly one `SwBlockVolume` for the PVC, named per the operator-status convention +(PVC name), `.spec.pvcName` matches, exactly one protection finalizer, no foreign +finalizer. CSI created the CR; the lifecycle-owner protected it within its +interval — no manual stub was needed (the gap that existed through Phase 43). + +## G4 — Status And Event Agreement — PASS + +```text +status=ready reasonCode=first_volume_verified Ready=True deleteSafety= +Event: Normal finalizer_added swblockvolume/sw-block-example-pvc +Event: Normal first_volume_verified swblockvolume/sw-block-example-pvc +``` + +operator-status wrote status for the CSI-created CR; `deleteSafety` is absent for +the normal non-deleting volume; both bounded Normal Events are present. + +## G5 — Boundary — PASS + +`kubectl auth can-i` across the three service accounts: + +```text +operator-status (sw-block-seaweed-block-operator-status): + patch swblockvolumes/status=yes create events=yes + patch swblockvolumes(main)=no /finalizers=no pvc=no +lifecycle-owner (sw-block-seaweed-block-lifecycle-owner): + patch swblockvolumes(main)=yes (VAP-confined to finalizers) patch /status=no pods=no +CSI controller (sw-block-seaweed-block-csi): + create swblockvolumes(main)=yes patch swblockvolumes(main)=yes + patch /status=no patch /finalizers=no delete pvc=no +``` + +No overlap: CSI holds only spec-object verbs (identity/spec), operator-status only +`/status` + Events, lifecycle-owner only the VAP-admitted finalizer patch. (The +VAP forbidden-mutation matrix is unchanged from Phase 43 D1/D2 and remains in +force.) + +## G6 — Cleanup — PASS + +```text +helm uninstall: release uninstalled +verify-helm-cleanup.sh: cleanup_status=ok cleanup_observed_at=2026-06-16T08:42:05Z +swblockvolumes=0 pvc=0 pods=0 helm=0 lifecycle-owner VAP=0 +``` + +No stuck `SwBlockVolume`, PVC/PV, pods, helm release, VAP, iSCSI, multipath, or +dmsetup residue. (The CR's protection finalizer was cleared by admin for teardown, +since release-on-delete is D3/D4 scope, not D2.) + +## Blocking Findings + +None. The CR is created by the normal CSI path, protected by the lifecycle-owner, +and status-published by operator-status; no surface gained out-of-scope mutation +power; PVC/PV/workload/storage were not mutated by operator-status or +lifecycle-owner. + +## Non-Blocking Findings + +1. **CSI controller SA name ≠ ClusterRole name.** The pod runs as + `sw-block-seaweed-block-csi`, while the swblockvolumes ClusterRole is + `sw-block-seaweed-block-csi-controller` (bound to that SA). Correct, but a + `can-i` against the `-controller` name misleads — note the SA for future + boundary checks. +2. The new CSI CR-registration requires a candidate `seaweed-block-csi` image + (the `--swblockvolume-cr-namespace` flag is new in `e56b844`); publish both + images together before any release that enables the operator/lifecycle + surfaces. +3. tp01 `NotReady` — unrelated to this single-node gate. + +## Recommendation + +**Phase 44 D2 passes.** The integrated Day-1 path is real-API-proven: a normal PVC +now yields a CSI-created `SwBlockVolume` CR, protected by the lifecycle-owner and +status-published by operator-status, with a clean three-way ownership boundary and +zero residue — and it is off by default. This closes the "CR must exist before the +delete lifecycle can act" gap. The natural next step is the end-to-end delete +close gate: PVC delete → CSI DeleteVolume → delete-safety projection → gated +finalizer release → uninstall zero-residue as one user path. diff --git a/seaweed-block/internal/docs/qa-assignments/phase44-d3-d4-delete-lifecycle-close-gate-qa.md b/seaweed-block/internal/docs/qa-assignments/phase44-d3-d4-delete-lifecycle-close-gate-qa.md new file mode 100644 index 0000000000..a46da2b772 --- /dev/null +++ b/seaweed-block/internal/docs/qa-assignments/phase44-d3-d4-delete-lifecycle-close-gate-qa.md @@ -0,0 +1,185 @@ +# QA Assignment — Phase 44 D3/D4 Delete Lifecycle Close Gate + +Goal: validate the integrated delete lifecycle after D2 proved that a normal PVC +creates a protected `SwBlockVolume` CR. + +This gate must use a VAP-capable cluster. It must run with fresh `sw-block` and +`sw-block-csi` images from the candidate branch because both the CSI CR creation +path and the operator-status delete-safety bridge are new. + +## Scope + +Validate this product path: + +```text +Helm install with operatorStatus + lifecycleOwner +-> first PVC writer/reader +-> SwBlockVolume exists with protection finalizer +-> delete requested +-> unsafe or missing cleanup evidence holds the finalizer +-> clean cleanup-summary evidence makes deleteSafety releasable +-> lifecycle-owner releases only the protection finalizer +-> SwBlockVolume deletion completes +-> uninstall leaves zero residue +``` + +Out of scope: automatic cleanup execution, PVC/PV/workload mutation by +operator-status or lifecycle-owner, rebuild/failback/backup/NVMe. + +## Required Setup + +Install with both controllers enabled: + +```text +--set operatorStatus.create=true +--set operatorStatus.dryRun=false +--set lifecycleOwner.create=true +--set lifecycleOwner.dryRun=false +``` + +Confirm the ownership split before delete testing: + +```text +CSI service account: + can create/patch swblockvolumes main object + cannot patch swblockvolumes/status + cannot patch swblockvolumes/finalizers + +operator-status service account: + can patch swblockvolumes/status and create events + cannot patch swblockvolumes main object or finalizers + +lifecycle-owner service account: + can patch swblockvolumes main object + VAP confines the patch to block.seaweedfs.com/swblockvolume-protection + cannot patch swblockvolumes/status +``` + +## G1 — Day-1 Baseline + +1. Install the chart. +2. Create the first PVC with the standard basic-app path. +3. Verify writer and reader both pass. +4. Verify exactly one `SwBlockVolume` exists for the PVC. +5. Verify the protection finalizer exists exactly once. +6. Verify operator-status writes: + +```text +status=ready +reasonCode=first_volume_verified +Ready=True +deleteSafety=null +``` + +## G2 — Missing Evidence Holds + +Request deletion of the `SwBlockVolume` while the protection finalizer is present +and before providing cleanup evidence. + +Expected: + +```text +SwBlockVolume remains Terminating +status.deleteSafety.decision=unknown +status.deleteSafety.state=requested +status.deleteSafety.reason=cleanup_evidence_missing +status.status=unknown +status.reasonCode=cleanup_evidence_missing +lifecycle-owner finalizer_held > 0 +finalizer_released = 0 +``` + +Fail if the finalizer is released or any surface claims Ready=True for the +deleting object with missing cleanup evidence. + +## G3 — Blocked Residue Holds + +Provide a verifier summary with residue, for example an iSCSI node DB record, and +run operator-status with: + +```text +sw-block ops operator-status --namespace kube-system \ + --master-api \ + --cleanup-summary +``` + +Expected: + +```text +status.deleteSafety.decision=rejected +status.deleteSafety.state=blocked +CleanupRequired=True +allowedActions includes observe.verify_cleanup mode=scripted mutationAllowed=false +lifecycle-owner holds the protection finalizer +no cleanup is executed by either controller +``` + +Fail if blocked residue releases the finalizer. + +## G4 — Clean Evidence Releases + +Clear residue with the documented cleanup path, then produce a fresh +`cleanup-summary.txt` from `scripts/verify-helm-cleanup.sh`. Run operator-status +with `--cleanup-summary` again. + +Expected: + +```text +status.deleteSafety.decision=allowed +status.deleteSafety.state=releasable +status.deleteSafety.finalizerReleaseAllowed=true +CleanupRequired=False +lifecycle-owner removes only block.seaweedfs.com/swblockvolume-protection +foreign finalizers, if present, are preserved +SwBlockVolume deletion completes +``` + +Fail if lifecycle-owner changes `.spec`, `.status`, labels, annotations, owner +references, PVCs, PVs, pods, storage classes, or any finalizer other than the +Seaweed Block protection finalizer. + +## G5 — Surface Agreement + +For G2/G3/G4, compare: + +```text +kubectl get/describe SwBlockVolume +sw-block ops report +sw-block ops explain +sw-block ops dashboard /operator-snapshot.json +Kubernetes Events +``` + +Required: + +```text +same status +same reasonCode +same deleteSafety decision/state/reason +same safe action mode and mutationAllowed=false +no false Ready=True in missing/stale/blocked delete states +``` + +## G6 — Cleanup + +Uninstall the chart and run the cleanup verifier. + +Required: + +```text +cleanup_status=ok +k8s_residue_count=0 +iscsi_residue_count=0 +multipath_residue_count=0 +process_residue_count=0 +hostpath_residue_count=0 +failure_count=0 +``` + +The lab must have no stuck `SwBlockVolume`, PVC/PV, pod, helm, VAP, iSCSI, +multipath, dmsetup, or per-host process residue. + +## Verdict + +D3/D4 pass only if unsafe evidence holds the finalizer, clean fresh evidence +releases it, all user surfaces agree, and the final cleanup verifier is clean.