From b9d95a0ea3619ac3bb74527a159db550bddc4f90 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 7 Jun 2026 15:47:41 -0700 Subject: [PATCH] phase37: make live node evidence crd safe --- seaweed-block/cmd/sw-block/main.go | 36 +++++++-------- seaweed-block/cmd/sw-block/main_test.go | 46 +++++++++++++++++++ .../core/ops/kubernetes_node_evidence.go | 12 ++--- .../core/ops/kubernetes_node_evidence_test.go | 21 +++++++++ seaweed-block/internal/docs/current-plan.md | 12 +++-- 5 files changed, 99 insertions(+), 28 deletions(-) diff --git a/seaweed-block/cmd/sw-block/main.go b/seaweed-block/cmd/sw-block/main.go index 4fe43cc580..fdb6283fb1 100644 --- a/seaweed-block/cmd/sw-block/main.go +++ b/seaweed-block/cmd/sw-block/main.go @@ -28,10 +28,10 @@ func main() { } var ( - opsStatusRunCommand = ops.DefaultRunCommand - opsInventoryRunCommand = ops.DefaultRunCommand - opsGenerateHelmValuesRunCommand = ops.DefaultRunCommand - opsOperatorStatusNodeEvidenceFactory = func() (ops.OperatorNodeEvidenceEnricher, error) { + opsStatusRunCommand = ops.DefaultRunCommand + opsInventoryRunCommand = ops.DefaultRunCommand + opsGenerateHelmValuesRunCommand = ops.DefaultRunCommand + opsNodeEvidenceEnricherFactory = func() (ops.OperatorNodeEvidenceEnricher, error) { return ops.NewInClusterKubernetesStatusClient() } opsOperatorStatusWriterFactory = func() (ops.OperatorStatusWriter, error) { @@ -146,20 +146,6 @@ func runOpsOperatorStatus(args []string, stdout, stderr io.Writer) int { if code != ops.VolumeStatusExitOK { return code } - if fromBundle == "" && os.Getenv("KUBERNETES_SERVICE_HOST") != "" { - enricher, err := opsOperatorStatusNodeEvidenceFactory() - if err != nil { - fmt.Fprintf(stderr, "sw-block ops operator-status: %v\n", err) - return ops.VolumeStatusExitInvalid - } - ctx, cancel := context.WithTimeout(context.Background(), timeout) - defer cancel() - cluster, err = enricher.EnrichNodeEvidence(ctx, namespace, cluster) - if err != nil { - fmt.Fprintf(stderr, "sw-block ops operator-status: enrich node evidence: %v\n", err) - return ops.VolumeStatusExitInvalid - } - } mode := "write_status" var writer ops.OperatorStatusWriter var events ops.OperatorEventSink @@ -473,6 +459,20 @@ func loadObservationCluster(command string, args []string, stderr io.Writer) (op fmt.Fprintf(stderr, "%s: %v\n", command, err) return ops.ClusterEvidence{}, "", ops.VolumeStatusExitInvalid } + if fromBundle == "" && os.Getenv("KUBERNETES_SERVICE_HOST") != "" { + enricher, enrichErr := opsNodeEvidenceEnricherFactory() + if enrichErr != nil { + fmt.Fprintf(stderr, "%s: %v\n", command, enrichErr) + return ops.ClusterEvidence{}, "", ops.VolumeStatusExitInvalid + } + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + cluster, enrichErr = enricher.EnrichNodeEvidence(ctx, namespace, cluster) + if enrichErr != nil { + fmt.Fprintf(stderr, "%s: enrich node evidence: %v\n", command, enrichErr) + return ops.ClusterEvidence{}, "", ops.VolumeStatusExitInvalid + } + } return ops.NormalizeObservationCluster(cluster), out, ops.VolumeStatusExitOK } diff --git a/seaweed-block/cmd/sw-block/main_test.go b/seaweed-block/cmd/sw-block/main_test.go index 6754a1835e..c8c5561b77 100644 --- a/seaweed-block/cmd/sw-block/main_test.go +++ b/seaweed-block/cmd/sw-block/main_test.go @@ -347,6 +347,52 @@ func TestOpsOperatorStatusWritesCRDStatusWhenDryRunDisabled(t *testing.T) { } } +func TestOpsClusterMasterAPIUsesSharedInClusterNodeEvidenceEnrichment(t *testing.T) { + masterAddr, closeMaster := startCmdFakeMaster(t) + defer closeMaster() + oldFactory := opsNodeEvidenceEnricherFactory + opsNodeEvidenceEnricherFactory = func() (ops.OperatorNodeEvidenceEnricher, error) { + return fakeNodeEvidenceEnricher{}, nil + } + t.Cleanup(func() { opsNodeEvidenceEnricherFactory = oldFactory }) + t.Setenv("KUBERNETES_SERVICE_HOST", "10.0.0.1") + + var stdout, stderr bytes.Buffer + code := run([]string{"ops", "cluster", "--master-api", masterAddr, "-o", "json"}, &stdout, &stderr) + if code != ops.VolumeStatusExitOK { + t.Fatalf("exit=%d stderr=%s stdout=%s", code, stderr.String(), stdout.String()) + } + out := stdout.String() + for _, want := range []string{ + `"kubernetes_node": "m02"`, + `"ready": false`, + `"reason": "node_not_ready"`, + } { + if !strings.Contains(out, want) { + t.Fatalf("stdout missing %q:\n%s", want, out) + } + } +} + +type fakeNodeEvidenceEnricher struct{} + +func (fakeNodeEvidenceEnricher) EnrichNodeEvidence(_ context.Context, _ string, cluster ops.ClusterEvidence) (ops.ClusterEvidence, error) { + cluster.Nodes = []ops.NodeEvidence{{ + NodeName: "m02", + KubernetesNode: "m02", + Ready: false, + Schedulable: true, + Conditions: []ops.ObservationCondition{{ + Type: ops.ConditionReady, + Status: "Unknown", + Reason: ops.ReasonNodeNotReady, + Severity: "warning", + Message: "Kubernetes node Ready condition is not True", + }}, + }} + return cluster, nil +} + type operatorStatusTestWriter struct { cluster ops.SwBlockClusterCRDStatus volumes []operatorStatusTestVolumeWrite diff --git a/seaweed-block/core/ops/kubernetes_node_evidence.go b/seaweed-block/core/ops/kubernetes_node_evidence.go index 317525ef53..734a23eb31 100644 --- a/seaweed-block/core/ops/kubernetes_node_evidence.go +++ b/seaweed-block/core/ops/kubernetes_node_evidence.go @@ -168,8 +168,8 @@ func mergeLiveNodeEvidence(namespace string, cluster ClusterEvidence, nodes []ku func mergeNodeKubernetesConditions(conditions []ObservationCondition, fact kubernetesNodeFact) []ObservationCondition { if !fact.Ready { conditions = append(conditions, ObservationCondition{ - Type: "KubernetesNodeReady", - Status: "False", + Type: ConditionReady, + Status: "Unknown", Reason: ReasonNodeNotReady, Severity: "warning", Message: "Kubernetes node Ready condition is not True", @@ -178,8 +178,8 @@ func mergeNodeKubernetesConditions(conditions []ObservationCondition, fact kuber } if !fact.Schedulable { conditions = append(conditions, ObservationCondition{ - Type: "KubernetesNodeSchedulable", - Status: "False", + Type: ConditionBlocked, + Status: "True", Reason: ReasonNodeSchedulingDisabled, Severity: "warning", Message: "Kubernetes node is marked unschedulable", @@ -192,7 +192,7 @@ func mergeNodeKubernetesConditions(conditions []ObservationCondition, fact kuber func mergeNodeCSIEvidence(conditions []ObservationCondition, namespace, nodeName string, pod kubernetesPodFact, driverExists, registered bool) []ObservationCondition { if !driverExists || !registered { conditions = append(conditions, ObservationCondition{ - Type: "CSIDriverRegistered", + Type: ConditionReady, Status: "False", Reason: ReasonCSIDriverNotRegistered, Severity: "warning", @@ -202,7 +202,7 @@ func mergeNodeCSIEvidence(conditions []ObservationCondition, namespace, nodeName } if !pod.Ready { conditions = append(conditions, ObservationCondition{ - Type: "CSINodePodReady", + Type: ConditionReady, Status: "False", Reason: ReasonCSINodePodNotReady, Severity: "warning", diff --git a/seaweed-block/core/ops/kubernetes_node_evidence_test.go b/seaweed-block/core/ops/kubernetes_node_evidence_test.go index 69f7296dad..5fa5fb2d65 100644 --- a/seaweed-block/core/ops/kubernetes_node_evidence_test.go +++ b/seaweed-block/core/ops/kubernetes_node_evidence_test.go @@ -75,6 +75,7 @@ func TestPhase37D2KubernetesNodeEvidenceEnrichesReadyAndBlockedNodes(t *testing. if !conditionReason(m02.Conditions, ReasonNodeNotReady) || !conditionReason(m02.Conditions, ReasonNodeSchedulingDisabled) { t.Fatalf("m02 conditions=%+v", m02.Conditions) } + assertCRDSafeNodeConditions(t, m02.Conditions) } func TestPhase37D2KubernetesNodeEvidenceProjectsCSIRegistrationBlockers(t *testing.T) { @@ -125,6 +126,7 @@ func TestPhase37D2KubernetesNodeEvidenceProjectsCSIRegistrationBlockers(t *testi if len(crd.EvidenceRefs) == 0 || !strings.Contains(strings.Join(crd.EvidenceRefs, ","), "kubernetes/csinode/m02") { t.Fatalf("missing CRD evidence refs: %+v", crd.EvidenceRefs) } + assertCRDSafeNodeConditions(t, crd.Conditions) } func TestPhase37D2KubernetesNodeEvidenceProjectsMissingCSIDriver(t *testing.T) { @@ -153,6 +155,25 @@ func TestPhase37D2KubernetesNodeEvidenceProjectsMissingCSIDriver(t *testing.T) { if status, reason := classifyNodeReadiness(m01); status != ManagedVolumeStatusBlocked || reason != ReasonCSIDriverNotRegistered { t.Fatalf("m01 status=%s reason=%s conditions=%+v", status, reason, m01.Conditions) } + assertCRDSafeNodeConditions(t, m01.Conditions) +} + +func assertCRDSafeNodeConditions(t *testing.T, conditions []ObservationCondition) { + t.Helper() + allowed := map[string]bool{ + ConditionReady: true, + ConditionRecovered: true, + ConditionRecovering: true, + ConditionBlocked: true, + ConditionInvalid: true, + ConditionCleanupRequired: true, + ConditionEvidenceStale: true, + } + for _, condition := range conditions { + if !allowed[condition.Type] { + t.Fatalf("condition type %q is not CRD-safe: %+v", condition.Type, conditions) + } + } } func nodeByKubernetesName(t *testing.T, nodes []NodeEvidence, name string) NodeEvidence { diff --git a/seaweed-block/internal/docs/current-plan.md b/seaweed-block/internal/docs/current-plan.md index 7ce37759d3..70a7959a35 100644 --- a/seaweed-block/internal/docs/current-plan.md +++ b/seaweed-block/internal/docs/current-plan.md @@ -1,6 +1,6 @@ # Current Plan: Phase 37 - Live Node Evidence Hardening -Status: active, 28% complete. Started on 2026-06-06. +Status: active, 30% complete. Started on 2026-06-06. Branch: `phase33-testops-failure-hardening` @@ -93,7 +93,7 @@ internal review against control-structure-effectiveness-review.md Goal: populate live node readiness from Kubernetes API facts, not replay-only fixtures. -Status: dev-complete; QA pending. +Status: reworked after QA blocker; QA revalidation pending. Acceptance: @@ -242,9 +242,13 @@ QA strict rerun from clean lab evidence from in-cluster read-only Kubernetes facts for Nodes, CSI node pods, CSIDriver, and CSINode driver registration. Chart RBAC adds only get/list/watch for those resources. Live QA remains pending. +- 30%: D2 QA blocker reworked. Live node enrichment now emits only CRD-enum-safe + `Ready`/`Blocked` condition types with node reason codes, and enrichment moved + into the shared live observation loader so report/dashboard/explain can see + the same in-cluster Kubernetes node facts as operator-status. ## Next Step -Assign QA to run D2 live node-readiness and CSI-registration gates from a clean -lab. Do not implement finalizers, cleanup automation, rebuild/failback, +Ask QA to re-run D2 G2/G3/G4 plus the shared surface agreement checks from a +clean lab. Do not implement finalizers, cleanup automation, rebuild/failback, backup/restore, or NVMe ANA parity in this phase.