From 6e24d17bbbd62fcf1bb3b38007ad9b7d52b2a694 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 4 Jun 2026 00:57:56 -0700 Subject: [PATCH] phase35: stabilize operator event identity --- .../core/ops/kubernetes_status_writer.go | 8 ++-- .../core/ops/kubernetes_status_writer_test.go | 26 ++++++++++- seaweed-block/internal/docs/current-plan.md | 44 ++++++++++++++++--- 3 files changed, 67 insertions(+), 11 deletions(-) diff --git a/seaweed-block/core/ops/kubernetes_status_writer.go b/seaweed-block/core/ops/kubernetes_status_writer.go index 37e576f3bb..1950861da9 100644 --- a/seaweed-block/core/ops/kubernetes_status_writer.go +++ b/seaweed-block/core/ops/kubernetes_status_writer.go @@ -111,7 +111,7 @@ func (c *KubernetesStatusClient) EmitEvent(ctx context.Context, event OperatorKu body := kubernetesCoreEvent{ APIVersion: "v1", Kind: "Event", - Metadata: kubernetesMetadata{Name: kubernetesEventName(event, now), Namespace: namespace}, + Metadata: kubernetesMetadata{Name: kubernetesEventName(event), Namespace: namespace}, InvolvedObject: kubernetesObjectReferenceFromOperator(event.InvolvedObject), Type: event.Type, Reason: event.Reason, @@ -173,12 +173,12 @@ func kubernetesObjectReferenceFromOperator(ref OperatorObjectRef) kubernetesObje } } -func kubernetesEventName(event OperatorKubernetesEvent, at time.Time) string { - base := kubernetesName(event.InvolvedObject.Name + "-" + event.Reason) +func kubernetesEventName(event OperatorKubernetesEvent) string { + base := kubernetesName(event.InvolvedObject.Name + "-" + event.Type + "-" + event.Reason) if base == "unknown-volume" { base = "sw-block-event" } - return fmt.Sprintf("%s.%d", base, at.UnixNano()) + return base } func pathEscape(value string) string { diff --git a/seaweed-block/core/ops/kubernetes_status_writer_test.go b/seaweed-block/core/ops/kubernetes_status_writer_test.go index c9281e49f4..91c57e90e1 100644 --- a/seaweed-block/core/ops/kubernetes_status_writer_test.go +++ b/seaweed-block/core/ops/kubernetes_status_writer_test.go @@ -151,9 +151,13 @@ func TestKubernetesStatusClientCreatesCoreEvents(t *testing.T) { if involved["kind"] != SwBlockVolumeKind || involved["name"] != "blocked-pvc" { t.Fatalf("involvedObject=%+v", involved) } + metadata := eventBody["metadata"].(map[string]any) + if metadata["name"] != "blocked-pvc-warning-csi-node-image-pull-failed" { + t.Fatalf("event name=%s", metadata["name"]) + } } -func TestKubernetesStatusClientTreatsDuplicateEventAsSuccess(t *testing.T) { +func TestKubernetesStatusClientTreatsPersistentEventAsIdempotentSuccess(t *testing.T) { seen := map[string]bool{} server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { var body map[string]any @@ -190,14 +194,32 @@ func TestKubernetesStatusClientTreatsDuplicateEventAsSuccess(t *testing.T) { if err := client.EmitEvent(context.Background(), event); err != nil { t.Fatalf("first event: %v", err) } + event.ObservedAt = event.ObservedAt.Add(time.Minute) if err := client.EmitEvent(context.Background(), event); err != nil { - t.Fatalf("duplicate event must be idempotent success: %v", err) + t.Fatalf("persistent event must be idempotent success: %v", err) } if len(seen) != 1 { t.Fatalf("seen events=%+v", seen) } } +func TestKubernetesEventNameSeparatesTypeAndReason(t *testing.T) { + base := OperatorKubernetesEvent{ + InvolvedObject: OperatorObjectRef{Name: "demo-pvc"}, + Reason: ReasonFirstVolumeVerified, + } + normal := base + normal.Type = "Normal" + warning := base + warning.Type = "Warning" + if kubernetesEventName(normal) == kubernetesEventName(warning) { + t.Fatalf("event names must separate type: normal=%s warning=%s", kubernetesEventName(normal), kubernetesEventName(warning)) + } + if got := kubernetesEventName(normal); strings.Contains(got, ".") { + t.Fatalf("event name must be stable and not timestamp-suffixed: %s", got) + } +} + func TestKubernetesStatusClientReturnsHTTPFailure(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNotFound) diff --git a/seaweed-block/internal/docs/current-plan.md b/seaweed-block/internal/docs/current-plan.md index a729e9e6d8..164e2a90ae 100644 --- a/seaweed-block/internal/docs/current-plan.md +++ b/seaweed-block/internal/docs/current-plan.md @@ -1,6 +1,6 @@ # Current Plan: Phase 35 - Kubernetes-Native Read-Only Operator Foundation -Status: active, 78% complete. Started on 2026-06-02. +Status: active, 82% complete. Started on 2026-06-02. Branch: `phase33-testops-failure-hardening` @@ -251,6 +251,8 @@ Result: Goal: make important transitions visible through standard Kubernetes Events. +Status: event identity hygiene local PASS; live QA pending. + Required Events: - `VolumeReady` as Normal. @@ -267,6 +269,33 @@ events are deduplicated enough to avoid timeline spam events match ManagedVolume/operator-snapshot reason codes ``` +Local verification: + +```text +[done] Kubernetes Event names are stable per SwBlockVolume object, Event type, + and reason code. The name no longer embeds observedAt.UnixNano(). +[done] Persistent same-reason Events become idempotent 409 success across + reconcile iterations instead of creating a new Event each time. +[done] Normal and Warning Events for the same object/reason get different + names. +[done] go test ./core/ops ./cmd/sw-block ./cmd/blockcsi +[done] helm lint charts/seaweed-block +``` + +Open D6 validation: + +```text +[pending] live QA should run repeated write-mode reconciles for a persistent + blocked volume and verify Event object count stays bounded. +[pending] live QA should verify Event reason/type alignment for: + first_volume_verified -> Normal + csi_node_image_pull_failed -> Warning + transparent_host_path_recovered -> Normal + evidence_stale/status_endpoint_unreachable -> Warning +[pending] CleanupRequired Event remains pending until cleanup residue evidence + is projected as a ManagedVolume condition. +``` + ## D7: Read-Only Boundary Gate Goal: prove the new operator foundation cannot mutate storage. @@ -358,13 +387,18 @@ finished plan moved under internal/docs/finished-plans/ Blocked or Ready=True, while `wal_integrity_fault` projected to Blocked/Ready=False. Warning Events landed and the status/events-only RBAC boundary held. +- 82%: D6 event identity hygiene landed locally. Kubernetes Event names are + stable per object/type/reason, so repeated persistent conditions dedupe via + idempotent 409 handling instead of producing timestamp-suffixed Event spam. + Scoped Go tests and Helm lint pass. Live QA and full reason/type coverage are + pending. ## Next Step -Implement and validate D6 Kubernetes Events semantics. Start with stable Event -identity: persistent same-reason conditions must dedupe across reconcile -iterations, and same-reason different-condition Events must either be -disambiguated or intentionally collapsed without aborting status publication. +Ask QA to run the D6 live Event hygiene gate on the current branch tip. The +main proof is repeated write-mode reconcile against a persistent blocked volume: +the second reconcile should exit 0 and not grow a new Event object for the same +object/type/reason. ```text VolumeReady -> Normal