phase41: tighten delete safety preconditions

This commit is contained in:
pingqiu committed 2026-06-14 09:47:34 -07:00
1 parent 63d9d64749
commit 2c4d024a4e
6 files changed
+86 -11

No files matched your search

@@ -118,6 +118,7 @@ spec:
enum:
- allowed
- rejected
- unknown
state:
type: string
enum:
@@ -174,6 +175,7 @@ spec:
enum:
- allowed
- rejected
- unknown
decisionReason:
type: string
missingFacts:
@@ -114,8 +114,8 @@ func EvaluateSwBlockVolumeDeleteSafety(facts SwBlockVolumeDeleteSafetyFacts) SwB
if facts.Cleanup == nil {
return SwBlockVolumeDeleteSafetyDecision{
ActionType: SwBlockVolumeDeleteActionReleaseFinalizer,
Decision: ManagedVolumeActionDecisionRejected,
State: DeleteSafetyStateBlocked,
Decision: ManagedVolumeActionDecisionUnknown,
State: DeleteSafetyStateRequested,
Reason: ReasonCleanupEvidenceMissing,
MissingFacts: []string{"cleanup.status"},
SafeNextAction: ManagedVolumeActionVerifyCleanup,
@@ -83,13 +83,13 @@ func TestEvaluateSwBlockVolumeDeleteSafety_NotRequested(t *testing.T) {
}
}
func TestEvaluateSwBlockVolumeDeleteSafety_BlocksWithoutCleanupEvidence(t *testing.T) {
func TestEvaluateSwBlockVolumeDeleteSafety_UnknownWithoutCleanupEvidence(t *testing.T) {
decision := EvaluateSwBlockVolumeDeleteSafety(SwBlockVolumeDeleteSafetyFacts{
DeleteRequested: true,
FinalizerPresent: true,
})
if decision.State != DeleteSafetyStateBlocked ||
decision.Decision != ManagedVolumeActionDecisionRejected ||
if decision.State != DeleteSafetyStateRequested ||
decision.Decision != ManagedVolumeActionDecisionUnknown ||
decision.Reason != ReasonCleanupEvidenceMissing ||
decision.FinalizerReleaseAllowed ||
decision.SafeNextAction != ManagedVolumeActionVerifyCleanup {
@@ -8,6 +8,7 @@ import (
const (
ManagedVolumeActionDecisionAllowed = "allowed"
ManagedVolumeActionDecisionRejected = "rejected"
ManagedVolumeActionDecisionUnknown = "unknown"
ManagedVolumeActionRejectUnknownAction = "unknown_action"
ManagedVolumeActionRejectDisabled = "policy_disabled"
@@ -597,6 +597,66 @@ func TestObservationBundle_DeleteSafetyBlocksWithResidue(t *testing.T) {
assertDashboardEndpointContains(t, server.URL+"/"+ObservationOperatorSnapshotArtifact, `"reason": "iscsi_node_records_present"`)
}
func TestObservationBundle_DeleteSafetyUnknownWithoutCleanupEvidence(t *testing.T) {
dir := t.TempDir()
writeProductClusterEvidence(t, dir, []VolumeEvidence{{
VolumeID: "pvc-missing-cleanup",
Namespace: "default",
PVCName: "missing-cleanup-pvc",
PVName: "pv-missing-cleanup",
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, ObservationDeleteSafetyArtifact), strings.Join([]string{
"delete_requested=true",
"finalizer_present=true",
"volume_id=pvc-missing-cleanup",
"pvc_name=missing-cleanup-pvc",
"pv_name=pv-missing-cleanup",
}, "\n"))
cluster, err := BuildObservationFromBundle(ObservationBundleOptions{Dir: dir, VolumeID: "pvc-missing-cleanup"})
if err != nil {
t.Fatal(err)
}
managed := managedProjectionForVolume(cluster.ManagedVolumes, "pvc-missing-cleanup")
if managed.DeleteSafety == nil ||
managed.DeleteSafety.State != DeleteSafetyStateRequested ||
managed.DeleteSafety.Decision != ManagedVolumeActionDecisionUnknown ||
managed.DeleteSafety.Reason != ReasonCleanupEvidenceMissing ||
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)
}
summary := RenderObservationReportSummary(cluster)
if !strings.Contains(summary, "managed_volume_delete_safety=pvc-missing-cleanup state=requested decision=unknown reason=cleanup_evidence_missing release_allowed=false action=safe_k8s.release_swblockvolume_finalizer") {
t.Fatalf("summary missing unknown delete safety:\n%s", summary)
}
snapshot := BuildOperatorFoundationSnapshot(cluster)
if snapshot.Volumes[0].Status.DeleteSafety == nil ||
snapshot.Volumes[0].Status.DeleteSafety.Decision != ManagedVolumeActionDecisionUnknown ||
snapshot.Volumes[0].Status.DeleteSafety.State != DeleteSafetyStateRequested {
t.Fatalf("snapshot delete safety=%+v", snapshot.Volumes[0].Status.DeleteSafety)
}
server := httptest.NewServer(NewObservationDashboardHandler(cluster))
defer server.Close()
assertDashboardEndpointContains(t, server.URL+"/"+ObservationOperatorSnapshotArtifact, `"decision": "unknown"`)
assertDashboardEndpointContains(t, server.URL+"/"+ObservationOperatorSnapshotArtifact, `"reason": "cleanup_evidence_missing"`)
}
func TestObservationBundle_DeleteSafetyReleasableWithCleanCleanupEvidence(t *testing.T) {
dir := t.TempDir()
writeProductClusterEvidence(t, dir, []VolumeEvidence{{
+18 -6
View File
@@ -123,15 +123,20 @@ negative tests for forbidden spec/storage/workload mutation
Goal: convert Phase 39 delete-safety status into executable preconditions
without executing cleanup.
Status: in progress. Clean, blocked, missing-evidence, and multi-volume
isolation are covered; stale cleanup evidence needs an explicit freshness fact
source before it can be gated honestly.
Acceptance:
```text
[ ] blocked delete evidence rejects lifecycle release with stable reason
[ ] clean delete evidence permits release intent
[ ] missing or stale evidence produces Unknown/EvidenceStale, not allowed
[ ] cleanup-required evidence suggests scripted verification only
[ ] CRD/report/dashboard/operator-snapshot agree on decision and evidence
[ ] multi-volume evidence stays isolated per volume
[x] blocked delete evidence rejects lifecycle release with stable reason
[x] clean delete evidence permits release intent
[x] missing evidence produces decision=unknown and release_allowed=false
[ ] stale evidence produces decision=unknown from an explicit freshness fact
[x] cleanup-required evidence suggests scripted verification only
[x] CRD/report/dashboard/operator-snapshot agree on decision and evidence
[x] multi-volume evidence stays isolated per volume
```
Verification:
@@ -259,6 +264,13 @@ git diff --check
finalizer-shaped main-object patch, and spec/unrelated metadata/fake
`/finalizers` endpoint mutation is rejected. A true live-apiserver/envtest
execution path remains open before D2 can be called fully closed.
- 36%: D3 precondition semantics partially complete. Delete-safety now uses
`decision=unknown` for missing cleanup evidence instead of treating missing
evidence as confirmed blocked residue. From-bundle tests prove blocked
residue rejects release, clean evidence allows release, missing evidence keeps
data-plane readiness separate from lifecycle release, and the surfaces carry
the same delete-safety decision. Stale cleanup evidence still needs an
explicit freshness field before it can be gated without self-certifying.
## Prerequisites / Risks