mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
phase35: stabilize operator event identity
This commit is contained in:
1 parent
675b021de9
commit
6e24d17bbb
3 files changed
+67
-11
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user