From cb76f972925cab97866fc27fe1b3078cc76480de Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 5 Jun 2026 17:13:12 -0700 Subject: [PATCH] phase36: add surface agreement gate --- seaweed-block/core/ops/observation_bundle.go | 11 +- seaweed-block/core/ops/observation_report.go | 68 +++++-- .../core/ops/phase36_status_surface_test.go | 177 ++++++++++++++++++ seaweed-block/internal/docs/current-plan.md | 27 ++- .../internal/docs/product-roadmap.md | 12 +- ...se36-d5-surface-agreement-qa-assignment.md | 140 ++++++++++++++ 6 files changed, 403 insertions(+), 32 deletions(-) create mode 100644 seaweed-block/core/ops/phase36_status_surface_test.go create mode 100644 seaweed-block/internal/docs/qa-assignments/phase36-d5-surface-agreement-qa-assignment.md diff --git a/seaweed-block/core/ops/observation_bundle.go b/seaweed-block/core/ops/observation_bundle.go index 607534a32f..77cee073f5 100644 --- a/seaweed-block/core/ops/observation_bundle.go +++ b/seaweed-block/core/ops/observation_bundle.go @@ -129,8 +129,17 @@ func RenderObservationExplainText(cluster ClusterEvidence) string { cluster = NormalizeObservationCluster(cluster) var b strings.Builder b.WriteString(RenderClusterEvidenceText(cluster)) + renderedManaged := map[string]bool{} for _, volume := range cluster.Volumes { - b.WriteString(RenderManagedVolumeProjectionText(managedProjectionForVolume(cluster.ManagedVolumes, volume.VolumeID))) + managed := managedProjectionForVolume(cluster.ManagedVolumes, volume.VolumeID) + b.WriteString(RenderManagedVolumeProjectionText(managed)) + renderedManaged[managedProjectionKey(managed)] = true + } + for _, managed := range cluster.ManagedVolumes { + if renderedManaged[managedProjectionKey(managed)] { + continue + } + b.WriteString(RenderManagedVolumeProjectionText(managed)) } if len(cluster.Events) > 0 { b.WriteString("timeline:\n") diff --git a/seaweed-block/core/ops/observation_report.go b/seaweed-block/core/ops/observation_report.go index 4b0d7884a3..e4dd6703ad 100644 --- a/seaweed-block/core/ops/observation_report.go +++ b/seaweed-block/core/ops/observation_report.go @@ -71,6 +71,25 @@ func RenderObservationReportSummary(cluster ClusterEvidence) string { step.Command, emptyAsDash(step.ReasonCode)) } + operatorSnapshot := BuildOperatorFoundationSnapshot(cluster) + for _, condition := range operatorSnapshot.Cluster.Conditions { + fmt.Fprintf(&b, "cluster_condition=%s status=%s reason=%s severity=%s\n", + emptyAsDash(condition.Type), + emptyAsDash(condition.Status), + emptyAsDash(condition.Reason), + emptyAsDash(condition.Severity)) + } + for _, node := range operatorSnapshot.Cluster.Nodes { + fmt.Fprintf(&b, "node=%s k8s=%s status=%s reason=%s ready=%t schedulable=%t missing_images=%s\n", + emptyAsDash(node.Name), + emptyAsDash(node.KubernetesNode), + emptyAsDash(node.Status), + emptyAsDash(node.ReasonCode), + node.Ready, + node.Schedulable, + emptyAsDash(strings.Join(node.MissingImages, ","))) + } + renderedManaged := map[string]bool{} for _, volume := range cluster.Volumes { fmt.Fprintf(&b, "volume=%s status=%s pvc=%s/%s primary=%s@%s frontend=%s rf=%d ack=%s\n", emptyAsDash(volume.VolumeID), @@ -83,29 +102,44 @@ func RenderObservationReportSummary(cluster ClusterEvidence) string { volume.ReplicationFactor, emptyAsDash(volume.AckProfile)) managed := managedProjectionForVolume(cluster.ManagedVolumes, volume.VolumeID) - fmt.Fprintf(&b, "managed_volume=%s status=%s reason=%s\n", - emptyAsDash(managed.VolumeID), - emptyAsDash(managed.Status), - emptyAsDash(managed.ReasonCode)) - for _, condition := range managed.Conditions { - fmt.Fprintf(&b, "managed_volume_condition=%s status=%s reason=%s severity=%s\n", - emptyAsDash(condition.Type), - emptyAsDash(condition.Status), - emptyAsDash(condition.Reason), - emptyAsDash(condition.Severity)) - } - for _, action := range managed.Actions { - fmt.Fprintf(&b, "managed_volume_action=%s mode=%s side_effect=%s executor=%s\n", - emptyAsDash(action.Type), - emptyAsDash(action.Mode), - emptyAsDash(action.SideEffectClass), - emptyAsDash(action.OwnerExecutor)) + renderManagedProjectionSummary(&b, managed) + renderedManaged[managedProjectionKey(managed)] = true + } + for _, managed := range cluster.ManagedVolumes { + if renderedManaged[managedProjectionKey(managed)] { + continue } + renderManagedProjectionSummary(&b, managed) } fmt.Fprintf(&b, "read_only=true\n") return b.String() } +func renderManagedProjectionSummary(b *strings.Builder, managed ManagedVolumeProjection) { + fmt.Fprintf(b, "managed_volume=%s status=%s reason=%s\n", + emptyAsDash(managed.VolumeID), + emptyAsDash(managed.Status), + emptyAsDash(managed.ReasonCode)) + for _, condition := range managed.Conditions { + fmt.Fprintf(b, "managed_volume_condition=%s status=%s reason=%s severity=%s\n", + emptyAsDash(condition.Type), + emptyAsDash(condition.Status), + emptyAsDash(condition.Reason), + emptyAsDash(condition.Severity)) + } + for _, action := range managed.Actions { + fmt.Fprintf(b, "managed_volume_action=%s mode=%s side_effect=%s executor=%s\n", + emptyAsDash(action.Type), + emptyAsDash(action.Mode), + emptyAsDash(action.SideEffectClass), + emptyAsDash(action.OwnerExecutor)) + } +} + +func managedProjectionKey(managed ManagedVolumeProjection) string { + return defaultString(managed.VolumeID, managed.PVCName) +} + func RenderObservationReportHTML(cluster ClusterEvidence) string { cluster = NormalizeObservationCluster(cluster) events := append([]ClusterEvent(nil), cluster.Events...) diff --git a/seaweed-block/core/ops/phase36_status_surface_test.go b/seaweed-block/core/ops/phase36_status_surface_test.go new file mode 100644 index 0000000000..fc211d5b5a --- /dev/null +++ b/seaweed-block/core/ops/phase36_status_surface_test.go @@ -0,0 +1,177 @@ +package ops + +import ( + "encoding/json" + "net/http" + "net/http/httptest" + "strings" + "testing" + "time" +) + +func TestPhase36D5NodeStatusSurfacesAgree(t *testing.T) { + cluster := NewClusterEvidence(time.Date(2026, 6, 5, 20, 0, 0, 0, time.UTC)) + cluster.Nodes = []NodeEvidence{{ + NodeName: "m02", + KubernetesNode: "m02", + InternalIP: "192.168.1.184", + Schedulable: true, + Ready: true, + RequiredImages: []string{"sw-block:local"}, + MissingImages: []string{"sw-block-csi:local"}, + }} + + summary := RenderObservationReportSummary(cluster) + for _, want := range []string{ + "node=m02 k8s=m02 status=blocked reason=image_missing_on_node ready=true schedulable=true missing_images=sw-block-csi:local", + } { + if !strings.Contains(summary, want) { + t.Fatalf("summary missing %q:\n%s", want, summary) + } + } + + snapshot := BuildOperatorFoundationSnapshot(cluster) + if snapshot.Cluster.NodeCount != 1 || len(snapshot.Cluster.Nodes) != 1 { + t.Fatalf("snapshot nodes=%+v", snapshot.Cluster) + } + node := snapshot.Cluster.Nodes[0] + if node.Status != ManagedVolumeStatusBlocked || node.ReasonCode != ReasonImageMissingOnNode { + t.Fatalf("node status=%+v", node) + } + + dashboard := phase36DashboardSnapshot(t, cluster) + if dashboard.Cluster.Nodes[0].Status != ManagedVolumeStatusBlocked || + dashboard.Cluster.Nodes[0].ReasonCode != ReasonImageMissingOnNode { + t.Fatalf("dashboard node=%+v", dashboard.Cluster.Nodes[0]) + } +} + +func TestPhase36D5CleanupRequiredSurfacesAgree(t *testing.T) { + cluster := NewClusterEvidence(time.Date(2026, 6, 5, 20, 5, 0, 0, time.UTC)) + cluster.Cleanup = &CleanupEvidence{ + Status: "failed", + ISCSIResidueCount: 1, + FailureCount: 1, + EvidenceRef: "cleanup-summary.txt", + } + + summary := RenderObservationReportSummary(cluster) + for _, want := range []string{ + "cleanup_status=failed", + "iscsi_residue_count=1", + "cluster_condition=CleanupRequired status=True reason=cleanup_required severity=warning", + "safe_next_step=observe.verify_cleanup mode=scripted mutation_allowed=false", + } { + if !strings.Contains(summary, want) { + t.Fatalf("summary missing %q:\n%s", want, summary) + } + } + + snapshot := BuildOperatorFoundationSnapshot(cluster) + if snapshot.Cluster.Cleanup == nil || snapshot.Cluster.Cleanup.ISCSIResidueCount != 1 { + t.Fatalf("snapshot cleanup=%+v", snapshot.Cluster.Cleanup) + } + if !phase36HasClusterCondition(snapshot, ConditionCleanupRequired, "True", ReasonCleanupRequired) { + t.Fatalf("snapshot conditions=%+v", snapshot.Cluster.Conditions) + } + verifyStep := false + for _, step := range snapshot.Cluster.SafeNextSteps { + if step.Type == ManagedVolumeActionVerifyCleanup { + verifyStep = true + if step.Mode != ManagedVolumeActionModeScripted || step.MutationAllowed { + t.Fatalf("cleanup step=%+v", step) + } + } + } + if !verifyStep { + t.Fatalf("missing cleanup step: %+v", snapshot.Cluster.SafeNextSteps) + } + + dashboard := phase36DashboardSnapshot(t, cluster) + if dashboard.Cluster.Cleanup == nil || dashboard.Cluster.Cleanup.ISCSIResidueCount != 1 { + t.Fatalf("dashboard cleanup=%+v", dashboard.Cluster.Cleanup) + } + if !phase36HasClusterCondition(dashboard, ConditionCleanupRequired, "True", ReasonCleanupRequired) { + t.Fatalf("dashboard conditions=%+v", dashboard.Cluster.Conditions) + } +} + +func TestPhase36D5StaleEvidenceSurfacesDoNotClaimReady(t *testing.T) { + cluster := NewClusterEvidence(time.Date(2026, 6, 5, 20, 10, 0, 0, time.UTC)) + cluster.Status = ObservationStatusUnavailable + cluster.ManagedVolumes = []ManagedVolumeProjection{ProjectManagedVolume(ManagedVolumeFacts{ + VolumeID: "pvc-unreachable", + PVCName: "status-unreachable-pvc", + ProductStatus: ObservationStatusUnavailable, + ProductReason: ReasonStatusEndpointUnreachable, + EvidenceRefs: []string{"diagnostics/status-endpoint-unreachable.txt"}, + })} + + summary := RenderObservationReportSummary(cluster) + for _, want := range []string{ + "managed_volume=pvc-unreachable status=unknown reason=status_endpoint_unreachable", + "managed_volume_condition=Ready status=Unknown reason=status_endpoint_unreachable severity=warning", + "managed_volume_condition=EvidenceStale status=True reason=status_endpoint_unreachable severity=warning", + "cluster_condition=EvidenceStale status=True reason=evidence_stale severity=warning", + } { + if !strings.Contains(summary, want) { + t.Fatalf("summary missing %q:\n%s", want, summary) + } + } + if strings.Contains(summary, "managed_volume_condition=Ready status=True") { + t.Fatalf("stale summary must not claim Ready=True:\n%s", summary) + } + + explain := RenderObservationExplainText(cluster) + if !strings.Contains(explain, "managed_volume pvc-unreachable status=unknown reason=status_endpoint_unreachable") || + !strings.Contains(explain, "managed_volume_condition EvidenceStale status=True reason=status_endpoint_unreachable") { + t.Fatalf("explain missing stale reason:\n%s", explain) + } + + snapshot := BuildOperatorFoundationSnapshot(cluster) + if snapshot.Cluster.ReadyVolumeCount != 0 || snapshot.Cluster.StaleVolumeCount != 1 { + t.Fatalf("snapshot cluster=%+v", snapshot.Cluster) + } + volume := snapshot.Volumes[0] + if volume.Status.Status != ManagedVolumeStatusUnknown || volume.Status.ReasonCode != ReasonStatusEndpointUnreachable { + t.Fatalf("snapshot volume=%+v", volume.Status) + } + if operatorContractHasCondition(volume, ConditionReady, "True", "") { + t.Fatalf("snapshot stale volume must not be Ready=True: %+v", volume.Status.Conditions) + } + + dashboard := phase36DashboardSnapshot(t, cluster) + if dashboard.Cluster.ReadyVolumeCount != 0 || dashboard.Cluster.StaleVolumeCount != 1 { + t.Fatalf("dashboard cluster=%+v", dashboard.Cluster) + } + if dashboard.Volumes[0].Status.Status != ManagedVolumeStatusUnknown || + dashboard.Volumes[0].Status.ReasonCode != ReasonStatusEndpointUnreachable { + t.Fatalf("dashboard volume=%+v", dashboard.Volumes[0].Status) + } +} + +func phase36DashboardSnapshot(t *testing.T, cluster ClusterEvidence) OperatorFoundationSnapshot { + t.Helper() + recorder := httptest.NewRecorder() + NewObservationDashboardHandler(cluster).ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/operator-snapshot.json", nil)) + if recorder.Code != http.StatusOK { + t.Fatalf("dashboard code=%d body=%s", recorder.Code, recorder.Body.String()) + } + var snapshot OperatorFoundationSnapshot + if err := json.Unmarshal(recorder.Body.Bytes(), &snapshot); err != nil { + t.Fatalf("decode dashboard snapshot: %v\n%s", err, recorder.Body.String()) + } + if !snapshot.ReadOnly || snapshot.Mutation.MutationAllowed { + t.Fatalf("dashboard mutation boundary=%+v", snapshot.Mutation) + } + return snapshot +} + +func phase36HasClusterCondition(snapshot OperatorFoundationSnapshot, typ, status, reason string) bool { + for _, condition := range snapshot.Cluster.Conditions { + if condition.Type == typ && condition.Status == status && condition.Reason == reason { + return true + } + } + return false +} diff --git a/seaweed-block/internal/docs/current-plan.md b/seaweed-block/internal/docs/current-plan.md index 57274925b6..35dadf17cc 100644 --- a/seaweed-block/internal/docs/current-plan.md +++ b/seaweed-block/internal/docs/current-plan.md @@ -1,6 +1,6 @@ # Current Plan: Phase 36 - Productized Operations Actionability -Status: active, 78% complete. Started on 2026-06-05. +Status: active, 86% complete. Started on 2026-06-05. Branch: `phase33-testops-failure-hardening` @@ -204,7 +204,7 @@ QA verifies no operator cleanup mutation occurred Goal: prove CRD status, report, dashboard, operator-snapshot, explain, and Events agree on the same operational truth. -Status: pending. +Status: local PASS; QA pending. Scenarios: @@ -217,12 +217,14 @@ Scenarios: Acceptance: ```text -[ ] no blocked/unknown/cleanup-required path shows false Ready=True -[ ] CRD status agrees with report summary -[ ] CRD status agrees with operator-snapshot.json -[ ] dashboard /operator-snapshot.json agrees with CRD status -[ ] explain names the same reason code and evidence refs -[ ] Kubernetes Events use stable bounded identity +[done] no blocked/unknown/cleanup-required path shows false Ready=True locally +[done] CRD status agrees with report summary locally +[done] CRD status agrees with operator-snapshot.json locally +[done] dashboard /operator-snapshot.json agrees with CRD status locally +[done] explain names the same reason code and evidence refs locally +[done] managed-only stale evidence is rendered in report summary and explain +[ ] Kubernetes Events use stable bounded identity in QA gate +[ ] QA strict rerun covers healthy, blocked, stale, cleanup-required, and multi-volume paths ``` Verification: @@ -311,8 +313,13 @@ PM wording review if README/release note changes evidence projects `CleanupRequired=True`, residue counters, and scripted `observe.verify_cleanup`. CRD status, operator-snapshot, summary, and HTML agree. QA verified the controller never runs cleanup or gains mutation power. +- 86%: D5 local surface-agreement tests landed. `summary.txt`, `ops explain`, + `operator-snapshot.json`, and dashboard now agree for node blockers, + cleanup-required evidence, and stale/unreachable evidence. Managed-only + stale evidence now appears in `summary.txt` and `ops explain` even when the + bundle has no raw `volumes[]` row. QA strict surface gate remains pending. ## Next Step -Continue D5 surface agreement and negative-first gates. Track the live -negative node-evidence follow-up; do not add mutating controller behavior. +Run D5 QA surface-agreement gates. Track the live negative node-evidence +follow-up; do not add mutating controller behavior. diff --git a/seaweed-block/internal/docs/product-roadmap.md b/seaweed-block/internal/docs/product-roadmap.md index fd9b957449..174506b264 100644 --- a/seaweed-block/internal/docs/product-roadmap.md +++ b/seaweed-block/internal/docs/product-roadmap.md @@ -411,16 +411,20 @@ phases rather than being mixed into the closed foundation. 6. Cleanup visibility: `CleanupRequired=True`, residue type, and safe next step. Do not automate cleanup yet. Status: active in Phase 36; D4 QA passed. +7. Surface agreement: + CRD status, Events, report, dashboard, operator-snapshot, and explain must + agree on healthy, blocked, stale, cleanup-required, and multi-volume paths. + Status: active in Phase 36; local D5 contract landed, QA pending. ### P2: Enter Mutating Lifecycle Carefully -7. Finalizers and delete safety for PVC/CRD lifecycle. -8. Upgrade/rollback status and drift reporting before upgrade execution. +8. Finalizers and delete safety for PVC/CRD lifecycle. +9. Upgrade/rollback status and drift reporting before upgrade execution. ### P3: Advanced Day-2 Features -9. Rebuild, reintegration, and failback. -10. Backup, snapshot, and restore. +10. Rebuild, reintegration, and failback. +11. Backup, snapshot, and restore. NVMe ANA parity is important, but it should not be the next plan. It should reuse the Phase 35 status foundation so protocol-specific path state does not diff --git a/seaweed-block/internal/docs/qa-assignments/phase36-d5-surface-agreement-qa-assignment.md b/seaweed-block/internal/docs/qa-assignments/phase36-d5-surface-agreement-qa-assignment.md new file mode 100644 index 0000000000..15795bc717 --- /dev/null +++ b/seaweed-block/internal/docs/qa-assignments/phase36-d5-surface-agreement-qa-assignment.md @@ -0,0 +1,140 @@ +# Phase 36 D5 QA Assignment - Surface Agreement And Negative-First Gates + +Status: ready for QA. + +Source scope: + +- `SwBlockCluster.status` +- `SwBlockVolume.status` +- Kubernetes Events emitted by operator-status +- `summary.txt` +- `index.html` +- `operator-snapshot.json` +- dashboard `/operator-snapshot.json` +- `sw-block ops explain` + +## Goal + +Verify that the user-facing status surfaces agree on the same operational truth +for healthy, blocked, unknown/stale, cleanup-required, and multi-volume paths. + +This gate must preserve the negative-first rule: blocked, unknown, stale, or +cleanup-required evidence must never be shown as false `Ready=True`. + +## Required Gates + +### G1: Healthy First Volume + +Use the Helm first-volume path with operator-status write mode enabled. + +Expected: + +```text +SwBlockVolume.status.status=ready +SwBlockVolume.status.reasonCode=first_volume_verified +Ready=True reason=first_volume_verified +SwBlockCluster.status.readyVolumeCount=1 +summary.txt managed_volume line matches the CRD +operator-snapshot.json matches the CRD +dashboard /operator-snapshot.json matches the CRD +Kubernetes Event is Normal / first_volume_verified +``` + +### G2: Blocked Path + +Use the existing CSI image-pull blocked bundle or another controlled blocked +path. + +Expected: + +```text +SwBlockVolume.status.status=blocked +Ready=False +Blocked=True +reasonCode=csi_node_image_pull_failed or the controlled blocker reason +no Ready=True anywhere in CRD/report/dashboard/operator-snapshot/explain +safe next steps are read_only or dry_run, mutationAllowed=false +Kubernetes Event is Warning with the same reason +``` + +### G3: Unknown / Stale Evidence + +Use the live or replay status-endpoint-unreachable gate. + +Expected: + +```text +SwBlockVolume.status.status=unknown +Ready=Unknown +EvidenceStale=True +reasonCode=status_endpoint_unreachable +no Ready=True anywhere +no inappropriate Blocked=True for pure unreachable evidence +summary.txt includes managed_volume and managed_volume_condition lines even if + the bundle has managed_volumes without raw volumes[] +ops explain names the same status_endpoint_unreachable reason +dashboard /operator-snapshot.json agrees +``` + +### G4: Cleanup Required + +Use Phase 36 D4 residue evidence. + +Expected: + +```text +SwBlockCluster.status.cleanup.status=failed +CleanupRequired=True +reason=cleanup_required or verifier reason when present +safeNextSteps has observe.verify_cleanup mode=scripted mutationAllowed=false +summary.txt / operator-snapshot.json / index.html / dashboard agree +operator-status does not execute cleanup +``` + +### G5: Multi-Volume Sanity + +Use the existing multi-volume RF3 smoke/readiness path or a replayed equivalent. + +Expected: + +```text +volumeCount=3 +readyVolumeCount=3 when all are healthy +three distinct SwBlockVolume identities +three distinct volume_id/pvc_name entries in operator-snapshot.json +no duplicate publish target for distinct volumes +no cross-volume reason/status mix-up +summary.txt includes one managed_volume line per volume +``` + +### G6: Event Identity And Boundary + +Across G1-G4: + +```text +Events use stable bounded identity; repeated reconcile does not mint unbounded + duplicates for the same object/type/reason +operator-status ServiceAccount can patch /status and create Events only +no spec, pod, PVC, PV, secret, deployment, storageclass, iSCSI, multipath, or +hostPath mutation power +``` + +## Pass Criteria + +```text +G1 PASS +G2 PASS +G3 PASS +G4 PASS +G5 PASS +G6 PASS +final cleanup verifier returns cleanup_status=ok +``` + +## Non-Claims + +- No mutating lifecycle. +- No automatic cleanup. +- No automatic support-bundle collection or upload. +- No repair/rebuild/failback/promote/delete execution. +- No finalizer/delete safety.