Skip to content

fix: reconcile/builder correctness bugs with unit tests - #96

Open
chideat wants to merge 4 commits into
mainfrom
fix/reconcile-builder-correctness-bugs
Open

fix: reconcile/builder correctness bugs with unit tests#96
chideat wants to merge 4 commits into
mainfrom
fix/reconcile-builder-correctness-bugs

Conversation

@chideat

@chideat chideat commented Jun 20, 2026

Copy link
Copy Markdown
Owner

Summary

A batch of surgical, behavior-preserving correctness fixes (no new logic) across the reconcile, builder, webhook, config, and helper layers, each shipped with a unit test. Found via an architecture review; scoped down to verified bugs only.

Every fix was cross-checked against the surrounding logic and controller-runtime semantics. For the trickiest ones (R2/R3/R5/R10) the regression test was proven to fail against the buggy code and pass after the fix.

Fixes

Area Bug Fix
ops/failover/actor/actor_patch_labels.go missing return → nil-pointer panic when Monitor().Master() errors add return
valkey/failover/monitor/manual_monitor.go successful manual failover falls through and returns an error return nil on success
pkg/kubernetes/clientset/pod.go UpdatePod submits the stale arg, not the merged oldPod Update(ctx, oldPod)
builder/{cluster,failover}builder/configmap.go memory-sizing guard && is always false → Limits→Requests fallback never fires &&||
controller/failover_controller.go finalizer re-added to a deleting object (missing return) return after removal (mirrors cluster)
config/env.go Getenv returns defaults[0] instead of the matched default return v
webhook/rds/v1alpha1/valkey_webhook.go error message inverted vs. condition "spec.resources is required"
builder/{cluster,failover}builder/statefulset.go PVC OwnerReferences set on a range-copy → RetainAfterDeleted ignored index-based assignment
cmd/helper/sync/controller.go etcd size guard constant ~1Gi instead of ~1Mi (never fires) extract exceedsConfigMapSizeLimit, fix constant
internal/util/auth.go dead code (CheckRule/CheckUserRuleUpdate/AuthConfig) removed (+ tests)

Deliberately out of scope

  • actor.RequeueAfter's time.Sleep is intentional — owner-triggered reconciles preempt the requeue timer, so the sleep is a load-bearing pacing floor, not redundant. Left as-is.
  • Sentinel component-label fix deferred — the label flows into the immutable StatefulSet selector, so changing it would break reconciliation of existing Sentinels. Needs a migration strategy.

Testing

  • New/extended unit tests for every fix.
  • Full unit suite incl. envtest (internal/controller, internal/webhook/rds/...) is green (go test -count=1, 35 packages, 0 failures).
  • No api/ type changes → no make manifests/make generate needed.
  • E2E suite unaffected (it asserts readiness + read/write, not the changed internals); no e2e edits.

🤖 Generated with Claude Code

chideat and others added 4 commits June 20, 2026 23:31
Surgical, behavior-preserving fixes (no new logic), each with a unit test.

- ops/failover patch-labels: add missing `return` so a Monitor().Master()
  error no longer falls through to a nil-pointer panic
- valkey/failover manual monitor: return nil on successful promotion instead
  of falling through to the "No available node to failover" error
- clientset UpdatePod: submit the merged oldPod (with server ResourceVersion),
  not the caller's stale pod argument
- builder configmap (cluster+failover): fix memory-sizing guard `&&`->`||` so
  the Limits->Requests memory fallback actually fires
- controller failover: return after finalizer removal so it is not re-added to
  an object being deleted (mirrors cluster_controller)
- config.Getenv: return the matched non-empty default, not always defaults[0]
- rds webhook: correct the inverted "spec.resources is required" message
- builder statefulset (cluster+failover): set PVC OwnerReferences via index so
  RetainAfterDeleted is honored (range-copy bug)
- helper sync: fix etcd object-size guard constant (~1Gi -> ~1Mi) via a small
  pure `exceedsConfigMapSizeLimit` helper
- remove dead util.CheckRule/CheckUserRuleUpdate/AuthConfig and their tests

Full unit suite incl. envtest (controller/webhook) is green.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Align the mock method tables with gofmt so the new/modified test files pass
the format check.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
…e guard

Addresses code-review follow-ups (all test-only / no production behavior change):

- add internal/testutil with configurable FakeFailoverInstance and
  FakeValkeyNode, replacing three near-identical per-package mocks
  (failoverbuilder, ops/failover/actor, valkey/failover/monitor). The
  certmetav1.ObjectReference deprecation now surfaces once instead of 3x.
- simplify exceedsConfigMapSizeLimit to take a single dataSize (oldTotal and
  oldData always cancelled to 0 at the only call site); behavior unchanged.

Verified: ACL-rule validation is fully handled by pkg/types/user.Rule.Validate
(user webhook + pkg/security/acl), so the earlier dead-code removal left no gap.

Full unit suite incl. envtest is green.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@chideat
chideat enabled auto-merge (squash) June 22, 2026 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant