phase36: project node readiness status

This commit is contained in:
pingqiu committed 2026-06-05 00:00:00 -07:00
1 parent 77053e0dbf
commit 0c4ef0074e
8 files changed
+421 -9

No files matched your search

+3
View File
@@ -26,6 +26,9 @@ const (
ReasonStatusEndpointUnreachable = "status_endpoint_unreachable"
ReasonCSINodeImagePullFailed = "csi_node_image_pull_failed"
ReasonImageMissingOnNode = "image_missing_on_node"
ReasonNodeReady = "node_ready"
ReasonNodeNotReady = "node_not_ready"
ReasonNodeSchedulingDisabled = "node_scheduling_disabled"
ReasonGeneratedDeploymentMissing = "generated_deployment_missing"
ReasonObservedReplicasBelowDesired = "observed_replicas_below_desired"
ReasonLoopbackFrontendRejected = "loopback_frontend_rejected"
@@ -1,5 +1,7 @@
package ops
import "time"
const ObservationOperatorSnapshotArtifact = "operator-snapshot.json"
type OperatorFoundationSnapshot struct {
@@ -20,6 +22,8 @@ type OperatorMutationBoundary struct {
type OperatorClusterStatus struct {
Status string `json:"status"`
NodeCount int `json:"node_count"`
Nodes []OperatorNodeStatus `json:"nodes,omitempty"`
VolumeCount int `json:"volume_count"`
ReadyVolumeCount int `json:"ready_volume_count"`
BlockedVolumeCount int `json:"blocked_volume_count"`
@@ -29,6 +33,22 @@ type OperatorClusterStatus struct {
NonClaims []string `json:"non_claims,omitempty"`
}
type OperatorNodeStatus struct {
Name string `json:"name"`
KubernetesNode string `json:"kubernetes_node,omitempty"`
InternalIP string `json:"internal_ip,omitempty"`
Schedulable bool `json:"schedulable"`
Ready bool `json:"ready"`
Status string `json:"status,omitempty"`
ReasonCode string `json:"reason_code,omitempty"`
LastHeartbeatAt time.Time `json:"last_heartbeat_at,omitempty"`
ReplicaCount int `json:"replica_count,omitempty"`
RequiredImages []string `json:"required_images,omitempty"`
MissingImages []string `json:"missing_images,omitempty"`
Conditions []ObservationCondition `json:"conditions,omitempty"`
EvidenceRefs []string `json:"evidence_refs,omitempty"`
}
func BuildOperatorFoundationSnapshot(cluster ClusterEvidence) OperatorFoundationSnapshot {
cluster = NormalizeObservationCluster(cluster)
snapshot := OperatorFoundationSnapshot{
@@ -53,6 +73,8 @@ 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...),
@@ -85,6 +107,32 @@ func BuildOperatorFoundationSnapshot(cluster ClusterEvidence) OperatorFoundation
return snapshot
}
func operatorNodeStatuses(nodes []NodeEvidence) []OperatorNodeStatus {
if len(nodes) == 0 {
return nil
}
out := make([]OperatorNodeStatus, 0, len(nodes))
for _, node := range nodes {
status, reason := classifyNodeReadiness(node)
out = append(out, OperatorNodeStatus{
Name: defaultString(node.NodeName, node.KubernetesNode),
KubernetesNode: node.KubernetesNode,
InternalIP: node.InternalIP,
Schedulable: node.Schedulable,
Ready: node.Ready,
Status: status,
ReasonCode: reason,
LastHeartbeatAt: node.LastHeartbeatAt,
ReplicaCount: node.ReplicaCount,
RequiredImages: append([]string(nil), node.RequiredImages...),
MissingImages: append([]string(nil), node.MissingImages...),
Conditions: nodeReadinessConditions(node, status, reason),
EvidenceRefs: nodeEvidenceRefs(node),
})
}
return out
}
func hasCondition(conditions []ObservationCondition, conditionType, status string) bool {
for _, condition := range conditions {
if condition.Type == conditionType && (status == "" || condition.Status == status) {
@@ -111,3 +111,39 @@ func TestOperatorFoundationSnapshot_CountsStaleEvidenceVolumes(t *testing.T) {
t.Fatalf("missing cluster EvidenceStale condition: %+v", snapshot.Cluster.Conditions)
}
}
func TestOperatorFoundationSnapshot_IncludesNodeReadiness(t *testing.T) {
cluster := NewClusterEvidence(time.Date(2026, 6, 5, 16, 30, 0, 0, time.UTC))
cluster.Nodes = []NodeEvidence{{
NodeName: "m02",
KubernetesNode: "m02",
InternalIP: "192.168.1.184",
Schedulable: true,
Ready: true,
ReplicaCount: 1,
RequiredImages: []string{"sw-block:local"},
}, {
NodeName: "tp01",
KubernetesNode: "tp01",
InternalIP: "192.168.1.188",
Schedulable: true,
Ready: true,
MissingImages: []string{"sw-block-csi:local"},
}}
snapshot := BuildOperatorFoundationSnapshot(cluster)
if snapshot.Cluster.NodeCount != 2 || len(snapshot.Cluster.Nodes) != 2 {
t.Fatalf("node status=%+v", snapshot.Cluster)
}
ready := snapshot.Cluster.Nodes[0]
if ready.Status != ManagedVolumeStatusReady || ready.ReasonCode != ReasonNodeReady {
t.Fatalf("ready node=%+v", ready)
}
blocked := snapshot.Cluster.Nodes[1]
if blocked.Status != ManagedVolumeStatusBlocked || blocked.ReasonCode != ReasonImageMissingOnNode {
t.Fatalf("blocked node=%+v", blocked)
}
if len(blocked.MissingImages) != 1 {
t.Fatalf("blocked missing images=%+v", blocked)
}
}
@@ -181,6 +181,7 @@ func (r OperatorStatusReconciler) Reconcile(ctx context.Context) (OperatorStatus
clusterStatus := SwBlockClusterCRDStatus{
ObservedAt: observedAt,
NodeCount: len(cluster.Nodes),
Nodes: swBlockNodeStatuses(cluster.Nodes),
VolumeCount: snapshot.Cluster.VolumeCount,
ReadyVolumeCount: snapshot.Cluster.ReadyVolumeCount,
BlockedVolumeCount: snapshot.Cluster.BlockedVolumeCount,
@@ -260,6 +261,104 @@ func swBlockVolumeCRDActions(actions []ManagedVolumeOperatorAction) []SwBlockVol
return out
}
func swBlockNodeStatuses(nodes []NodeEvidence) []SwBlockNodeCRDStatus {
if len(nodes) == 0 {
return nil
}
out := make([]SwBlockNodeCRDStatus, 0, len(nodes))
for _, node := range nodes {
status, reason := classifyNodeReadiness(node)
out = append(out, SwBlockNodeCRDStatus{
Name: defaultString(node.NodeName, node.KubernetesNode),
KubernetesNode: node.KubernetesNode,
InternalIP: node.InternalIP,
Schedulable: node.Schedulable,
Ready: node.Ready,
Status: status,
ReasonCode: reason,
LastHeartbeatAt: node.LastHeartbeatAt,
ReplicaCount: node.ReplicaCount,
RequiredImages: append([]string(nil), node.RequiredImages...),
MissingImages: append([]string(nil), node.MissingImages...),
Conditions: nodeReadinessConditions(node, status, reason),
EvidenceRefs: nodeEvidenceRefs(node),
})
}
return out
}
func classifyNodeReadiness(node NodeEvidence) (string, string) {
switch {
case len(node.MissingImages) > 0:
return ManagedVolumeStatusBlocked, ReasonImageMissingOnNode
case !node.Ready:
return ManagedVolumeStatusUnknown, ReasonNodeNotReady
case !node.Schedulable:
return ManagedVolumeStatusBlocked, ReasonNodeSchedulingDisabled
default:
return ManagedVolumeStatusReady, ReasonNodeReady
}
}
func nodeReadinessConditions(node NodeEvidence, status, reason string) []ObservationCondition {
conditions := append([]ObservationCondition(nil), node.Conditions...)
switch status {
case ManagedVolumeStatusReady:
return ensureCondition(conditions, ObservationCondition{
Type: ConditionReady,
Status: "True",
Reason: reason,
Severity: "info",
Message: "node is ready for Seaweed Block",
})
case ManagedVolumeStatusBlocked:
conditions = ensureCondition(conditions, ObservationCondition{
Type: ConditionReady,
Status: "False",
Reason: reason,
Severity: "warning",
Message: "node is blocked for Seaweed Block",
})
return ensureCondition(conditions, ObservationCondition{
Type: ConditionBlocked,
Status: "True",
Reason: reason,
Severity: "warning",
Message: "node requires operator attention before scheduling Seaweed Block workloads",
})
default:
conditions = ensureCondition(conditions, ObservationCondition{
Type: ConditionReady,
Status: "Unknown",
Reason: reason,
Severity: "warning",
Message: "node readiness evidence is unavailable or not ready",
})
return ensureCondition(conditions, ObservationCondition{
Type: ConditionEvidenceStale,
Status: "True",
Reason: reason,
Severity: "warning",
Message: "node readiness evidence is insufficient",
})
}
}
func ensureCondition(conditions []ObservationCondition, condition ObservationCondition) []ObservationCondition {
if hasCondition(conditions, condition.Type, condition.Status) {
return conditions
}
return append(conditions, condition)
}
func nodeEvidenceRefs(node NodeEvidence) []string {
var refs []string
for _, condition := range node.Conditions {
refs = append(refs, condition.EvidenceRefs...)
}
return refs
}
func (r OperatorStatusReconciler) now() func() time.Time {
if r.Now != nil {
return r.Now
@@ -70,6 +70,9 @@ func TestOperatorStatusReconcilerWritesStatusOnlyProjection(t *testing.T) {
if writer.cluster.MutationAllowed {
t.Fatalf("cluster status must not allow mutation: %+v", writer.cluster)
}
if len(writer.cluster.Nodes) != 1 || writer.cluster.Nodes[0].Name != "m02" {
t.Fatalf("cluster nodes=%+v", writer.cluster.Nodes)
}
if got := writer.volumes[0].status.Status; got != ManagedVolumeStatusReady {
t.Fatalf("ready volume status=%s", got)
}
@@ -111,6 +114,118 @@ func TestOperatorStatusReconcilerWritesStatusOnlyProjection(t *testing.T) {
}
}
func TestOperatorStatusReconcilerProjectsNodeReadiness(t *testing.T) {
heartbeat := time.Date(2026, 6, 5, 16, 0, 0, 0, time.UTC)
source := fakeOperatorStatusSource{cluster: ClusterEvidence{
SchemaVersion: ObservationSchemaVersion,
CapturedAt: time.Date(2026, 6, 5, 16, 1, 0, 0, time.UTC),
Status: ObservationStatusOK,
Nodes: []NodeEvidence{{
NodeName: "node-loss-r1",
KubernetesNode: "m01",
InternalIP: "192.168.1.181",
Schedulable: true,
Ready: true,
LastHeartbeatAt: heartbeat,
ReplicaCount: 2,
RequiredImages: []string{"sw-block:local", "sw-block-csi:local"},
Conditions: []ObservationCondition{{
Type: ConditionReady,
Status: "True",
Reason: ReasonNodeReady,
Severity: "info",
Message: "node is ready for Seaweed Block",
}},
}},
}}
writer := &fakeOperatorStatusWriter{}
_, err := (OperatorStatusReconciler{
Source: source,
Writer: writer,
}).Reconcile(context.Background())
if err != nil {
t.Fatalf("reconcile: %v", err)
}
if writer.cluster.NodeCount != 1 || len(writer.cluster.Nodes) != 1 {
t.Fatalf("cluster node status=%+v", writer.cluster)
}
node := writer.cluster.Nodes[0]
if node.Name != "node-loss-r1" || node.KubernetesNode != "m01" || node.InternalIP != "192.168.1.181" {
t.Fatalf("node identity=%+v", node)
}
if !node.Schedulable || !node.Ready || node.Status != ManagedVolumeStatusReady || node.ReasonCode != ReasonNodeReady {
t.Fatalf("node readiness=%+v", node)
}
if !node.LastHeartbeatAt.Equal(heartbeat) || node.ReplicaCount != 2 || len(node.RequiredImages) != 2 {
t.Fatalf("node details=%+v", node)
}
assertCondition(t, node.Conditions, ConditionReady, "True", ReasonNodeReady)
rawStatus, err := json.Marshal(writer.cluster)
if err != nil {
t.Fatalf("marshal cluster status: %v", err)
}
raw := string(rawStatus)
for _, want := range []string{`"kubernetesNode":"m01"`, `"internalIP":"192.168.1.181"`, `"lastHeartbeatAt":"2026-06-05T16:00:00Z"`, `"requiredImages":["sw-block:local","sw-block-csi:local"]`} {
if !strings.Contains(raw, want) {
t.Fatalf("cluster node status missing %s: %s", want, raw)
}
}
for _, forbidden := range []string{"kubernetes_node", "internal_ip", "last_heartbeat_at", "required_images"} {
if strings.Contains(raw, forbidden) {
t.Fatalf("CRD node status must not use observation snake_case field %q: %s", forbidden, raw)
}
}
}
func TestOperatorStatusReconcilerProjectsImageMissingNodeAsBlocked(t *testing.T) {
source := fakeOperatorStatusSource{cluster: ClusterEvidence{
SchemaVersion: ObservationSchemaVersion,
CapturedAt: time.Date(2026, 6, 5, 16, 5, 0, 0, time.UTC),
Status: ObservationStatusOK,
Nodes: []NodeEvidence{{
NodeName: "m02",
KubernetesNode: "m02",
InternalIP: "192.168.1.184",
Schedulable: true,
Ready: true,
RequiredImages: []string{"ghcr.io/seaweedfs/seaweed-block:sha-test"},
MissingImages: []string{"ghcr.io/seaweedfs/seaweed-block:sha-test"},
Conditions: []ObservationCondition{{
Type: ConditionBlocked,
Status: "True",
Reason: ReasonImageMissingOnNode,
Severity: "warning",
Message: "required image is missing on node",
}},
}},
}}
writer := &fakeOperatorStatusWriter{}
_, err := (OperatorStatusReconciler{
Source: source,
Writer: writer,
}).Reconcile(context.Background())
if err != nil {
t.Fatalf("reconcile: %v", err)
}
if len(writer.cluster.Nodes) != 1 {
t.Fatalf("cluster nodes=%+v", writer.cluster.Nodes)
}
node := writer.cluster.Nodes[0]
if node.Status != ManagedVolumeStatusBlocked || node.ReasonCode != ReasonImageMissingOnNode {
t.Fatalf("node status=%+v", node)
}
if len(node.MissingImages) != 1 || node.MissingImages[0] != "ghcr.io/seaweedfs/seaweed-block:sha-test" {
t.Fatalf("missing images=%+v", node.MissingImages)
}
assertCondition(t, node.Conditions, ConditionReady, "False", ReasonImageMissingOnNode)
assertCondition(t, node.Conditions, ConditionBlocked, "True", ReasonImageMissingOnNode)
if writer.cluster.ReadyVolumeCount != 0 {
t.Fatalf("node blocker must not synthesize ready volumes: %+v", writer.cluster)
}
}
func TestOperatorStatusReconcilerStaleEvidenceProjectsUnknownAndWarningEvent(t *testing.T) {
source := fakeOperatorStatusSource{cluster: ClusterEvidence{
SchemaVersion: ObservationSchemaVersion,
+15 -9
View File
@@ -1,6 +1,6 @@
# Current Plan: Phase 36 - Productized Operations Actionability
Status: active, 16% complete. Started on 2026-06-05.
Status: active, 28% complete. Started on 2026-06-05.
Branch: `phase33-testops-failure-hardening`
@@ -94,7 +94,7 @@ internal review against roadmap and Phase 35 non-claims
Goal: publish node-level readiness facts into `SwBlockCluster.status.nodes[]`.
Status: pending.
Status: LOCAL PASS; QA pending.
Required facts:
@@ -109,11 +109,12 @@ Required facts:
Acceptance:
```text
[ ] healthy lab shows all expected nodes ready
[ ] missing image or missing prerequisite does not project cluster Ready=True
[ ] blocked node reason is stable and visible in CRD status
[ ] node readiness agrees across report, dashboard, operator-snapshot, CRD status
[ ] no storage/workload mutation verbs are added
[done-local] healthy node evidence projects Ready node status
[done-local] missing image projects blocked node reason
[done-local] blocked node reason is stable and visible in CRD status
[done-local] node readiness projects to operator-snapshot as well as CRD status
[done-local] no storage/workload mutation verbs are added
[pending-qa] live 1-node and 3-node status agreement
```
Verification:
@@ -272,8 +273,13 @@ PM wording review if README/release note changes
support-bundle refs, and safe next-step fields while preserving the
status/events-only mutation boundary. Focused tests failed first on missing
fields, then passed after the structural contract landed.
- 28%: D2 local node readiness projection landed. Existing `NodeEvidence`
now maps into `SwBlockCluster.status.nodes[]` and `operator-snapshot.json`
with stable node reasons such as `node_ready`, `node_not_ready`,
`node_scheduling_disabled`, and `image_missing_on_node`. Local tests cover
healthy and missing-image nodes; live QA remains pending.
## Next Step
Start D2 by wiring real node readiness/preflight evidence into
`SwBlockCluster.status.nodes[]`. Do not add mutating controller behavior.
Ask QA to run the D2 live node-readiness gate on 1-node and 3-node labs, then
continue D3 support-bundle pointers. Do not add mutating controller behavior.
@@ -134,6 +134,9 @@ Phase 36 cluster node status fields are:
| `status.nodes[].conditions[]` | operator-status aggregate | Kubernetes-style node readiness conditions | provisional |
| `status.nodes[].evidenceRefs[]` | evidence producer | supporting artifact paths | stable |
Initial Phase 36 node reason codes are `node_ready`, `node_not_ready`,
`node_scheduling_disabled`, and `image_missing_on_node`.
Phase 36 cleanup status fields are:
| Field | Owner Input | Meaning | Stability |
@@ -0,0 +1,102 @@
# Phase 36 D2 QA Assignment - Node Readiness Status
Status: ready for QA.
Source scope:
- `SwBlockCluster.status.nodes[]`
- `operator-snapshot.json.cluster.nodes[]`
- read-only/status-only operator-status controller
## Goal
Verify that existing product-owned node evidence is visible through
Kubernetes-native read-only status and agrees with the support/report surface.
This gate must not mutate storage or workloads.
## Required Checks
### G1: Healthy 1-Node Lab
Run the documented Helm first-volume path with operator-status enabled in
write mode.
Expected:
```text
SwBlockCluster.status.nodeCount=1
SwBlockCluster.status.nodes[0].status=ready
SwBlockCluster.status.nodes[0].reasonCode=node_ready
SwBlockCluster.status.nodes[0].ready=true
SwBlockCluster.status.nodes[0].schedulable=true
operator-snapshot.json cluster.node_count=1
operator-snapshot.json cluster.nodes[0].status=ready
no storage/workload mutation permission beyond CRD status and Events
```
### G2: Healthy 3-Node Lab
Run the same path on the 3-node k3s lab.
Expected:
```text
SwBlockCluster.status.nodeCount=3
SwBlockCluster.status.nodes has one entry per observed k3s node
all ready/schedulable nodes show status=ready reasonCode=node_ready
operator-snapshot.json has the same node names and node statuses
first-volume still verifies writer/reader
```
### G3: Missing Image / Node Blocker
Use an existing blocked-image path or a controlled missing-image setup.
Expected:
```text
affected node status=blocked
affected node reasonCode=image_missing_on_node
affected node conditions include Ready=False and Blocked=True
missingImages[] names the missing image
cluster/volume status must not show false Ready=True because of node evidence
```
If a live missing-image setup is too expensive, QA may start with a
bundle-backed replay, but mark the result as replay-only.
### G4: Boundary
Verify the operator-status ServiceAccount still has only:
```text
get/list/watch swblockclusters, swblockvolumes
get/update/patch swblockclusters/status, swblockvolumes/status
create events
```
And still cannot mutate:
```text
pods, deployments, PVCs, PVs, secrets, storageclasses, CRD spec
```
## Pass Criteria
```text
G1 PASS
G2 PASS
G3 PASS or replay-only PASS with live follow-up filed
G4 PASS
cleanup residue clean
```
## Non-Claims
- No automatic CR object creation.
- No node repair.
- No image import.
- No cleanup mutation.
- No scheduler mutation.
- No storage/workload mutation.