From 7cfac5eee983fd48e9998258de3f651546013334 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 28 Nov 2026 13:34:19 -0800 Subject: [PATCH] fix: require timestamps for age-bounded cleanup evidence --- .../core/ops/delete_safety_contract.go | 9 ++++-- .../delete_safety_untimed_regression_test.go | 29 ++++++++++++++++--- .../core/ops/observation_bundle_test.go | 3 +- seaweed-block/docs/kubernetes-status.md | 12 +++++++- 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/seaweed-block/core/ops/delete_safety_contract.go b/seaweed-block/core/ops/delete_safety_contract.go index 83810012fe..f556c64916 100644 --- a/seaweed-block/core/ops/delete_safety_contract.go +++ b/seaweed-block/core/ops/delete_safety_contract.go @@ -158,8 +158,13 @@ func EvaluateSwBlockVolumeDeleteSafety(facts SwBlockVolumeDeleteSafetyFacts) SwB } func cleanupEvidenceStale(facts SwBlockVolumeDeleteSafetyFacts) bool { - if facts.Cleanup == nil || facts.Cleanup.ObservedAt.IsZero() || - facts.ObservedAt.IsZero() || facts.MaxEvidenceAge <= 0 { + if facts.Cleanup == nil || facts.MaxEvidenceAge <= 0 { + return false + } + if facts.Cleanup.ObservedAt.IsZero() { + return true // An enabled age bound requires a timestamp to prove freshness. + } + if facts.ObservedAt.IsZero() { return false } return facts.Cleanup.ObservedAt.Add(facts.MaxEvidenceAge).Before(facts.ObservedAt) diff --git a/seaweed-block/core/ops/delete_safety_untimed_regression_test.go b/seaweed-block/core/ops/delete_safety_untimed_regression_test.go index 319c8d7eb9..7eab644614 100644 --- a/seaweed-block/core/ops/delete_safety_untimed_regression_test.go +++ b/seaweed-block/core/ops/delete_safety_untimed_regression_test.go @@ -1,15 +1,12 @@ package ops import ( - "os" + "path/filepath" "testing" "time" ) func TestDeleteSafety_UntimedCleanupCannotProveFreshness(t *testing.T) { - if os.Getenv("SEAWEED_KNOWN_BUGS") != "1" { - t.Skip("known bug #188 (open): reproduction runs with SEAWEED_KNOWN_BUGS=1; the fix PR removes this skip") - } decision := EvaluateSwBlockVolumeDeleteSafety(SwBlockVolumeDeleteSafetyFacts{ DeleteRequested: true, FinalizerPresent: true, ObservedAt: time.Date(2026, 11, 17, 0, 0, 0, 0, time.UTC), MaxEvidenceAge: 15 * time.Minute, @@ -18,4 +15,28 @@ func TestDeleteSafety_UntimedCleanupCannotProveFreshness(t *testing.T) { if decision.FinalizerReleaseAllowed || decision.Decision != ManagedVolumeActionDecisionUnknown { t.Fatalf("untimed cleanup accepted as fresh: %+v; require UNKNOWN and no finalizer release", decision) } + if decision.Reason != ReasonCleanupEvidenceStale || !stringSliceContains(decision.MissingFacts, "cleanup.freshness") || decision.SafeNextAction != ManagedVolumeActionVerifyCleanup { + t.Fatalf("missing freshness must request cleanup verification: %+v", decision) + } +} + +// Exercise the bundle reader used by the Kubernetes status projection, not just +// the evaluator: an absent timestamp must survive parsing as unknown freshness. +func TestObservationBundle_UntimedCleanupCannotReportReleasable(t *testing.T) { + dir := t.TempDir() + writeProductClusterEvidence(t, dir, []VolumeEvidence{{VolumeID: "pvc-untimed", Status: ObservationStatusOK}}) + mustWrite(t, filepath.Join(dir, ObservationCleanupSummaryArtifact), "cleanup_status=ok") + mustWrite(t, filepath.Join(dir, ObservationDeleteSafetyArtifact), "volume_id=pvc-untimed\ndelete_requested=true\nfinalizer_present=true") + cluster, err := BuildObservationFromBundle(ObservationBundleOptions{Dir: dir, VolumeID: "pvc-untimed"}) + if err != nil { + t.Fatal(err) + } + managed := managedProjectionForVolume(cluster.ManagedVolumes, "pvc-untimed") + if managed.DeleteSafety == nil || managed.DeleteSafety.FinalizerReleaseAllowed || managed.DeleteSafety.Decision != ManagedVolumeActionDecisionUnknown || managed.ReasonCode != ReasonCleanupEvidenceStale { + t.Fatalf("untimed cleanup must project UNKNOWN, not releasable: %+v", managed) + } + snapshot := BuildOperatorFoundationSnapshot(cluster) + if len(snapshot.Volumes) != 1 || snapshot.Volumes[0].Status.DeleteSafety == nil || snapshot.Volumes[0].Status.DeleteSafety.Decision != ManagedVolumeActionDecisionUnknown || snapshot.Volumes[0].Status.DeleteSafety.FinalizerReleaseAllowed { + t.Fatalf("Kubernetes snapshot must retain UNKNOWN delete safety: %+v", snapshot.Volumes) + } } diff --git a/seaweed-block/core/ops/observation_bundle_test.go b/seaweed-block/core/ops/observation_bundle_test.go index 2dc208d2e8..e43219d6d3 100644 --- a/seaweed-block/core/ops/observation_bundle_test.go +++ b/seaweed-block/core/ops/observation_bundle_test.go @@ -707,6 +707,7 @@ func TestObservationBundle_DeleteSafetyBlocksWithResidue(t *testing.T) { }}) mustWrite(t, filepath.Join(dir, ObservationCleanupSummaryArtifact), strings.Join([]string{ "cleanup_status=failed", + "cleanup_observed_at=2026-05-27T12:00:00Z", "iscsi_residue_count=1", "reason_codes=iscsi_node_records_present", }, "\n")) @@ -921,7 +922,7 @@ func TestObservationBundle_DeleteSafetyReleasableWithCleanCleanupEvidence(t *tes FrontendAddr: "192.168.1.181:3260", }}, }}) - mustWrite(t, filepath.Join(dir, ObservationCleanupSummaryArtifact), "cleanup_status=ok") + mustWrite(t, filepath.Join(dir, ObservationCleanupSummaryArtifact), "cleanup_status=ok\ncleanup_observed_at=2026-05-27T12:00:00Z") mustWrite(t, filepath.Join(dir, ObservationDeleteSafetyArtifact), strings.Join([]string{ "delete_requested=true", "finalizer_present=true", diff --git a/seaweed-block/docs/kubernetes-status.md b/seaweed-block/docs/kubernetes-status.md index 2ba34dbb81..c68d1edd80 100644 --- a/seaweed-block/docs/kubernetes-status.md +++ b/seaweed-block/docs/kubernetes-status.md @@ -120,7 +120,17 @@ These are narrow alpha claims tied to documented gates. See - Upgrade or rollback execution. The status layer can report install drift, but it does not run Helm or kubectl mutations. -## Release images +## Known issues + +- In v1.0.0, cleanup evidence without `cleanup_observed_at` can incorrectly + report a `SwBlockVolume` deletion as releasable despite the status projection's + 15-minute evidence age bound ([#188](https://github.com/seaweedfs/seaweed-block/issues/188)). + Supply a real observation timestamp in the cleanup summary. The v1.0.1 fix + reports UNKNOWN with missing `cleanup.freshness` when that timestamp is absent; + the next action is to verify cleanup again. This is a Kubernetes status + projection defect; no product delete acts on this decision. + +## Release images Current validated published quickstart image tag: `sha-dc2972d0059b`.