phase36: project support evidence pointers

This commit is contained in:
pingqiu committed 2026-06-05 02:38:14 -07:00
1 parent 74ec2f5083
commit cb7889ba42
8 files changed
+392 -15

No files matched your search

@@ -59,6 +59,18 @@ func RenderObservationReportSummary(cluster ClusterEvidence) string {
fmt.Fprintf(&b, "%s\n", line)
}
}
supportRefs := supportBundleRefsFromCluster(cluster)
for _, ref := range supportRefs {
fmt.Fprintf(&b, "support_bundle_ref=%s\n", ref)
}
for _, step := range safeNextStepsFromCluster(cluster, supportRefs) {
fmt.Fprintf(&b, "safe_next_step=%s mode=%s mutation_allowed=%t command=%q reason=%s\n",
emptyAsDash(step.Type),
emptyAsDash(step.Mode),
step.MutationAllowed,
step.Command,
emptyAsDash(step.ReasonCode))
}
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),
@@ -144,6 +156,23 @@ func RenderObservationReportHTML(cluster ClusterEvidence) string {
b.WriteString("</tbody></table></section>")
}
supportRefs := supportBundleRefsFromCluster(cluster)
if len(supportRefs) > 0 {
b.WriteString("<section><h2>Support Evidence</h2><table><thead><tr><th>Evidence Ref</th></tr></thead><tbody>")
for _, ref := range supportRefs {
fmt.Fprintf(&b, "<tr><td><code>%s</code></td></tr>", esc(ref))
}
b.WriteString("</tbody></table></section>")
}
if steps := safeNextStepsFromCluster(cluster, supportRefs); len(steps) > 0 {
b.WriteString("<section><h2>Safe Next Steps</h2><table><thead><tr><th>Type</th><th>Mode</th><th>Mutation</th><th>Reason</th><th>Command</th></tr></thead><tbody>")
for _, step := range steps {
fmt.Fprintf(&b, "<tr><td>%s</td><td>%s</td><td>%t</td><td>%s</td><td><code>%s</code></td></tr>",
esc(step.Type), esc(step.Mode), step.MutationAllowed, esc(emptyAsDash(step.ReasonCode)), esc(step.Command))
}
b.WriteString("</tbody></table></section>")
}
b.WriteString("<section><h2>Managed Volumes</h2><table><thead><tr><th>Volume</th><th>Status</th><th>Reason</th><th>Conditions</th><th>Safe Actions</th></tr></thead><tbody>")
for _, managed := range cluster.ManagedVolumes {
class := "ok"
@@ -97,6 +97,7 @@ func TestObservationReportHTML_IncludesManagedVolumeConditions(t *testing.T) {
KubernetesResidueCount: 1,
MultipathResidueCount: 2,
FailureCount: 2,
ReasonCodes: []string{"multipath_residue_present"},
EvidenceRef: "cleanup-summary.txt",
}
cluster.Volumes = []VolumeEvidence{{
@@ -120,9 +121,12 @@ func TestObservationReportHTML_IncludesManagedVolumeConditions(t *testing.T) {
html := RenderObservationReportHTML(cluster)
for _, want := range []string{
"Lifecycle Cleanup",
"Support Evidence",
"Safe Next Steps",
"Managed Volumes",
"Managed Volume Conditions",
"cleanup-summary.txt",
"collect-helm-support-bundle.sh",
"pvc-loopback",
"publish_target_loopback_cross_node",
"safe_k8s.reinstall_external_iscsi",
@@ -133,6 +137,38 @@ func TestObservationReportHTML_IncludesManagedVolumeConditions(t *testing.T) {
}
}
func TestObservationReportSummary_IncludesSupportBundlePointers(t *testing.T) {
cluster := NewClusterEvidence(time.Date(2026, 6, 5, 18, 45, 0, 0, time.UTC))
cluster.Status = ObservationStatusBlocked
cluster.Volumes = []VolumeEvidence{{
VolumeID: "pvc-blocked",
Namespace: "default",
PVCName: "blocked-pvc",
Status: ObservationStatusBlocked,
Reason: ReasonCSINodeImagePullFailed,
SupportBundleHint: "support/bundle",
}}
cluster.ManagedVolumes = []ManagedVolumeProjection{ProjectManagedVolume(ManagedVolumeFacts{
VolumeID: "pvc-blocked",
PVCName: "blocked-pvc",
ProductStatus: ObservationStatusBlocked,
ProductReason: ReasonCSINodeImagePullFailed,
EvidenceRefs: []string{"support/bundle/replayed-report/summary.txt"},
})}
summary := RenderObservationReportSummary(cluster)
for _, want := range []string{
"support_bundle_ref=support/bundle",
"support_bundle_ref=support/bundle/replayed-report/summary.txt",
"safe_next_step=observe.collect_bundle mode=read_only mutation_allowed=false",
"collect-helm-support-bundle.sh",
} {
if !strings.Contains(summary, want) {
t.Fatalf("summary missing %q:\n%s", want, summary)
}
}
}
func TestObservationReportArtifacts_JSONIncludesManagedVolumeProjection(t *testing.T) {
dir := t.TempDir()
cluster := NewClusterEvidence(time.Date(2026, 5, 20, 12, 0, 0, 0, time.UTC))
+38 -6
View File
@@ -29,6 +29,8 @@ type OperatorClusterStatus struct {
BlockedVolumeCount int `json:"blocked_volume_count"`
StaleVolumeCount int `json:"stale_volume_count"`
Cleanup *CleanupEvidence `json:"cleanup,omitempty"`
SupportBundleRefs []string `json:"support_bundle_refs,omitempty"`
SafeNextSteps []OperatorSafeNextStep `json:"safe_next_steps,omitempty"`
Conditions []ObservationCondition `json:"conditions,omitempty"`
NonClaims []string `json:"non_claims,omitempty"`
}
@@ -49,8 +51,18 @@ type OperatorNodeStatus struct {
EvidenceRefs []string `json:"evidence_refs,omitempty"`
}
type OperatorSafeNextStep struct {
Type string `json:"type"`
Mode string `json:"mode"`
Command string `json:"command,omitempty"`
ReasonCode string `json:"reason_code,omitempty"`
MutationAllowed bool `json:"mutation_allowed"`
EvidenceRefs []string `json:"evidence_refs,omitempty"`
}
func BuildOperatorFoundationSnapshot(cluster ClusterEvidence) OperatorFoundationSnapshot {
cluster = NormalizeObservationCluster(cluster)
supportRefs := supportBundleRefsFromCluster(cluster)
snapshot := OperatorFoundationSnapshot{
APIVersion: SwBlockVolumeAPIVersion,
Kind: "ReadOnlyOperatorFoundationSnapshot",
@@ -72,12 +84,14 @@ func BuildOperatorFoundationSnapshot(cluster ClusterEvidence) OperatorFoundation
},
CRDContract: ManagedVolumeCRDContractDefinition(),
Cluster: OperatorClusterStatus{
Status: cluster.Status,
NodeCount: len(cluster.Nodes),
Nodes: operatorNodeStatuses(cluster.Nodes),
Cleanup: cluster.Cleanup,
Conditions: append([]ObservationCondition(nil), cluster.Conditions...),
NonClaims: append([]string(nil), cluster.NonClaims...),
Status: cluster.Status,
NodeCount: len(cluster.Nodes),
Nodes: operatorNodeStatuses(cluster.Nodes),
Cleanup: cluster.Cleanup,
SupportBundleRefs: supportRefs,
SafeNextSteps: operatorSafeNextSteps(safeNextStepsFromCluster(cluster, supportRefs)),
Conditions: append([]ObservationCondition(nil), cluster.Conditions...),
NonClaims: append([]string(nil), cluster.NonClaims...),
},
}
@@ -107,6 +121,24 @@ func BuildOperatorFoundationSnapshot(cluster ClusterEvidence) OperatorFoundation
return snapshot
}
func operatorSafeNextSteps(steps []SwBlockSafeNextStep) []OperatorSafeNextStep {
if len(steps) == 0 {
return nil
}
out := make([]OperatorSafeNextStep, 0, len(steps))
for _, step := range steps {
out = append(out, OperatorSafeNextStep{
Type: step.Type,
Mode: step.Mode,
Command: step.Command,
ReasonCode: step.ReasonCode,
MutationAllowed: step.MutationAllowed,
EvidenceRefs: append([]string(nil), step.EvidenceRefs...),
})
}
return out
}
func operatorNodeStatuses(nodes []NodeEvidence) []OperatorNodeStatus {
if len(nodes) == 0 {
return nil
@@ -147,3 +147,41 @@ func TestOperatorFoundationSnapshot_IncludesNodeReadiness(t *testing.T) {
t.Fatalf("blocked missing images=%+v", blocked)
}
}
func TestOperatorFoundationSnapshot_IncludesSupportBundlePointers(t *testing.T) {
cluster := NewClusterEvidence(time.Date(2026, 6, 5, 18, 30, 0, 0, time.UTC))
cluster.Status = ObservationStatusBlocked
cluster.Volumes = []VolumeEvidence{{
VolumeID: "pvc-blocked",
Namespace: "default",
PVCName: "blocked-pvc",
Status: ObservationStatusBlocked,
Reason: ReasonCSINodeImagePullFailed,
SupportBundleHint: "support/bundle",
Replicas: []ReplicaEvidence{{
ReplicaID: "r1",
SupportBundlePath: "support/bundle/volumes/pvc-blocked/r1",
}},
}}
cluster.ManagedVolumes = []ManagedVolumeProjection{ProjectManagedVolume(ManagedVolumeFacts{
VolumeID: "pvc-blocked",
PVCName: "blocked-pvc",
ProductStatus: ObservationStatusBlocked,
ProductReason: ReasonCSINodeImagePullFailed,
EvidenceRefs: []string{"support/bundle/replayed-report/summary.txt"},
})}
snapshot := BuildOperatorFoundationSnapshot(cluster)
for _, want := range []string{"support/bundle", "support/bundle/volumes/pvc-blocked/r1"} {
if !stringSliceContains(snapshot.Cluster.SupportBundleRefs, want) {
t.Fatalf("support refs missing %q: %+v", want, snapshot.Cluster.SupportBundleRefs)
}
}
if len(snapshot.Cluster.SafeNextSteps) == 0 {
t.Fatalf("missing safe next steps: %+v", snapshot.Cluster)
}
step := snapshot.Cluster.SafeNextSteps[0]
if step.Type != ManagedVolumeActionCollectBundle || step.Mode != ManagedVolumeActionModeReadOnly || step.MutationAllowed {
t.Fatalf("safe next step=%+v", step)
}
}
@@ -105,6 +105,89 @@ func swBlockCleanupStatus(cleanup *CleanupEvidence) *SwBlockCleanupStatus {
}
}
func supportBundleRefsFromCluster(cluster ClusterEvidence) []string {
seen := map[string]struct{}{}
var refs []string
add := func(ref string) {
ref = strings.TrimSpace(ref)
if ref == "" {
return
}
if _, ok := seen[ref]; ok {
return
}
seen[ref] = struct{}{}
refs = append(refs, ref)
}
if cluster.Cleanup != nil {
add(cluster.Cleanup.EvidenceRef)
}
for _, volume := range cluster.Volumes {
add(volume.SupportBundleHint)
for _, condition := range volume.Conditions {
for _, ref := range condition.EvidenceRefs {
add(ref)
}
}
for _, replica := range volume.Replicas {
add(replica.SupportBundlePath)
for _, condition := range replica.Conditions {
for _, ref := range condition.EvidenceRefs {
add(ref)
}
}
}
}
for _, managed := range cluster.ManagedVolumes {
for _, ref := range managed.EvidenceRefs {
add(ref)
}
for _, condition := range managed.Conditions {
for _, ref := range condition.EvidenceRefs {
add(ref)
}
}
for _, action := range managed.Actions {
for _, ref := range action.EvidenceRefs {
add(ref)
}
}
}
for _, node := range cluster.Nodes {
for _, ref := range nodeEvidenceRefs(node) {
add(ref)
}
}
return refs
}
func safeNextStepsFromCluster(cluster ClusterEvidence, evidenceRefs []string) []SwBlockSafeNextStep {
if len(evidenceRefs) == 0 && cluster.Status == ObservationStatusOK && cluster.Cleanup == nil {
return nil
}
return []SwBlockSafeNextStep{{
Type: ManagedVolumeActionCollectBundle,
Mode: ManagedVolumeActionModeReadOnly,
Command: `bash scripts/collect-helm-support-bundle.sh "$PWD"`,
ReasonCode: supportBundleReason(cluster),
MutationAllowed: false,
EvidenceRefs: append([]string(nil), evidenceRefs...),
}}
}
func supportBundleReason(cluster ClusterEvidence) string {
if cluster.Cleanup != nil && cluster.Cleanup.Status != "" && cluster.Cleanup.Status != "ok" {
if len(cluster.Cleanup.ReasonCodes) > 0 {
return cluster.Cleanup.ReasonCodes[0]
}
return ConditionCleanupRequired
}
if cluster.Status != "" && cluster.Status != ObservationStatusOK {
return cluster.Status
}
return "support_evidence_available"
}
type SwBlockVolumeCRDStatus struct {
VolumeID string `json:"volumeID,omitempty"`
PVCName string `json:"pvcName,omitempty"`
@@ -191,6 +274,8 @@ func (r OperatorStatusReconciler) Reconcile(ctx context.Context) (OperatorStatus
AllowedActionModes: append([]string(nil), snapshot.Mutation.AllowedModes...),
NonClaims: append([]string(nil), snapshot.Mutation.NonClaims...),
}
clusterStatus.SupportBundleRefs = supportBundleRefsFromCluster(cluster)
clusterStatus.SafeNextSteps = safeNextStepsFromCluster(cluster, clusterStatus.SupportBundleRefs)
if snapshot.Cluster.Cleanup != nil && snapshot.Cluster.Cleanup.EvidenceRef != "" {
clusterStatus.EvidenceRefs = append(clusterStatus.EvidenceRefs, snapshot.Cluster.Cleanup.EvidenceRef)
}
@@ -422,6 +422,60 @@ func TestOperatorStatusReconcilerCleanupStatusUsesCRDFieldNames(t *testing.T) {
}
}
func TestOperatorStatusReconcilerProjectsSupportBundlePointers(t *testing.T) {
source := fakeOperatorStatusSource{cluster: ClusterEvidence{
SchemaVersion: ObservationSchemaVersion,
CapturedAt: time.Date(2026, 6, 5, 18, 0, 0, 0, time.UTC),
Status: ObservationStatusBlocked,
Volumes: []VolumeEvidence{{
VolumeID: "pvc-blocked",
Namespace: "default",
PVCName: "blocked-pvc",
Status: ObservationStatusBlocked,
Reason: ReasonCSINodeImagePullFailed,
SupportBundleHint: "support/bundle",
Replicas: []ReplicaEvidence{{
ReplicaID: "r1",
SupportBundlePath: "support/bundle/volumes/pvc-blocked/r1",
}},
}},
ManagedVolumes: []ManagedVolumeProjection{ProjectManagedVolume(ManagedVolumeFacts{
VolumeID: "pvc-blocked",
PVCName: "blocked-pvc",
ProductStatus: ObservationStatusBlocked,
ProductReason: ReasonCSINodeImagePullFailed,
EvidenceRefs: []string{"support/bundle/replayed-report/summary.txt"},
})},
}}
writer := &fakeOperatorStatusWriter{}
_, err := (OperatorStatusReconciler{
Source: source,
Writer: writer,
}).Reconcile(context.Background())
if err != nil {
t.Fatalf("reconcile: %v", err)
}
for _, want := range []string{
"support/bundle",
"support/bundle/volumes/pvc-blocked/r1",
} {
if !stringSliceContains(writer.cluster.SupportBundleRefs, want) {
t.Fatalf("cluster support refs missing %q: %+v", want, writer.cluster.SupportBundleRefs)
}
}
if len(writer.cluster.SafeNextSteps) == 0 {
t.Fatalf("missing safe next steps: %+v", writer.cluster)
}
step := writer.cluster.SafeNextSteps[0]
if step.Type != ManagedVolumeActionCollectBundle || step.Mode != ManagedVolumeActionModeReadOnly || step.MutationAllowed {
t.Fatalf("support next step=%+v", step)
}
if step.Command == "" || !strings.Contains(step.Command, "collect-helm-support-bundle.sh") {
t.Fatalf("support next step command=%+v", step)
}
}
func TestOperatorStatusReconcilerEventFailureDoesNotBlockLaterStatusWrites(t *testing.T) {
source := fakeOperatorStatusSource{cluster: ClusterEvidence{
SchemaVersion: ObservationSchemaVersion,
+16 -9
View File
@@ -1,6 +1,6 @@
# Current Plan: Phase 36 - Productized Operations Actionability
Status: active, 34% complete. Started on 2026-06-05.
Status: active, 48% complete. Started on 2026-06-05.
Branch: `phase33-testops-failure-hardening`
@@ -132,7 +132,7 @@ QA rerun on 1-node and 3-node lab if code reaches live status
Goal: make blocked/unknown status self-explaining through evidence references.
Status: pending.
Status: LOCAL PASS; QA pending.
Deliverables:
@@ -144,11 +144,12 @@ Deliverables:
Acceptance:
```text
[ ] blocked status includes evidence_ref
[ ] unknown/stale status includes evidence_ref or missing-evidence reason
[ ] support-bundle command is suggested as read-only/scripted next step
[ ] from-bundle report/dashboard/operator-snapshot agree with live report
[ ] cold-reader bundle can explain a blocker without SSH/log spelunking
[done-local] blocked status includes evidence_ref
[done-local] unknown/stale status includes evidence_ref or missing-evidence reason
[done-local] support-bundle command is suggested as read-only/scripted next step
[done-local] report summary, HTML, operator-snapshot, and CRD status expose support refs
[pending-qa] from-bundle report/dashboard/operator-snapshot agree with live report
[pending-qa] cold-reader bundle can explain a blocker without SSH/log spelunking
```
Verification:
@@ -285,8 +286,14 @@ PM wording review if README/release note changes
hardcodes `Ready=true`, `Schedulable=true`, and omits `MissingImages`.
Follow-up: populate live `NodeEvidence` from real Kubernetes node readiness
and image-presence facts so negative node reasons are reachable live.
- 48%: D3 local support evidence projection landed. Cluster-level support refs
and a read-only `observe.collect_bundle` safe next step now project into
`SwBlockCluster.status.supportBundleRefs[]`,
`SwBlockCluster.status.safeNextSteps[]`, `operator-snapshot.json`,
`summary.txt`, and the report HTML. Live/from-bundle QA remains pending.
## Next Step
Continue D3 support-bundle pointers and evidence refs. Track the live negative
node-evidence follow-up; do not add mutating controller behavior.
Ask QA to run the D3 support-bundle/from-bundle agreement gate, then continue
D4 cleanup visibility. Track the live negative node-evidence follow-up; do not
add mutating controller behavior.
@@ -0,0 +1,96 @@
# Phase 36 D3 QA Assignment - Support Evidence Pointers
Status: ready for QA.
Source scope:
- `SwBlockCluster.status.supportBundleRefs[]`
- `SwBlockCluster.status.safeNextSteps[]`
- `operator-snapshot.json.cluster.support_bundle_refs[]`
- `operator-snapshot.json.cluster.safe_next_steps[]`
- report `summary.txt`
- report `index.html`
- from-bundle replay
## Goal
Verify that blocked or unknown operational status points users to support
evidence and safe collection/replay commands without mutating the cluster.
## Required Checks
### G1: Live Blocked Or Support-Bundle Path
Use an existing blocked path such as CSI image pull failure, or another
controlled support-bundle scenario.
Expected:
```text
SwBlockCluster.status.supportBundleRefs has at least one support/evidence ref
SwBlockCluster.status.safeNextSteps has type=observe.collect_bundle
safeNextSteps[0].mode=read_only
safeNextSteps[0].mutationAllowed=false
safeNextSteps[0].command mentions collect-helm-support-bundle.sh
```
### G2: Report Agreement
Run `sw-block ops report` on the same evidence.
Expected:
```text
summary.txt includes support_bundle_ref=...
summary.txt includes safe_next_step=observe.collect_bundle mode=read_only
index.html includes Support Evidence
index.html includes Safe Next Steps
operator-snapshot.json cluster.support_bundle_refs agrees with CRD status
operator-snapshot.json cluster.safe_next_steps agrees with CRD status
```
### G3: From-Bundle Replay
Replay the generated bundle away from the live cluster:
```text
sw-block ops report --from-bundle <bundle> --out <out>
sw-block ops explain volume --from-bundle <bundle> <volume>
sw-block ops dashboard --from-bundle <bundle> --listen 127.0.0.1:<port>
```
Expected:
```text
from-bundle summary keeps support_bundle_ref
from-bundle operator-snapshot keeps support_bundle_refs
from-bundle dashboard /operator-snapshot.json returns the same refs
ops explain names the same reason code and evidence refs
```
### G4: Boundary
Verify no new mutation power:
```text
operator-status may patch CRD status and create Events only
support collection command is only suggested, not executed by operator-status
no PVC/PV/pod/deployment/secret/storageclass mutation
```
## Pass Criteria
```text
G1 PASS
G2 PASS
G3 PASS
G4 PASS
cleanup residue clean
```
## Non-Claims
- No automatic support-bundle upload.
- No automatic cleanup.
- No automatic image import or repair.
- No mutating operator action.