enhancement: reliable ValkeyNode.Status.Role - #320
Conversation
Signed-off-by: Joseph Heyburn <jdheyburn@gmail.com>
Signed-off-by: Joseph Heyburn <jdheyburn@gmail.com>
|
@greptile-apps Review |
|
this is the right foundation to build the label on, and keying the hint on the annotation value rather than one thing worth pinning down now, since this PR fixes the meaning of "role" that the PDB in #303 will consume: valkey only counts masters that serve at least one slot as voters in a failover election (a master with that distinction shows up during a reshard: a primary whose last slots have just migrated away is still flagged master until it demotes, but it has already stopped voting. if for the follow-up label: worth thinking about the lifecycle when a pod is recreated. the label lives on the pod, not the pod template, so a fresh pod starts without it and a primaries PDB selecting on it won't match until the next reconcile patches it back. brief and self-healing, but it's a window where the node is unprotected right after a roll, so patching it as soon as the pod reports Ready is worth the ordering care. and to state the invariant from #310 explicitly, since both live in the same area now: this label is the right input for the PDB because eviction re-evaluates it continuously, and the wrong input for topology spread, which is evaluated once at placement and wants the stable node-index=0 identity. same label, opposite conclusions. |
This PR closes #261
Summary
The existing Status.Role being reported on ValkeyNode was quite naive in that it would only be updated after a reconciliation cycle, which is currently every 60s. This can mean it lags behind when failovers happen for whatever reason.
While nothing depends on Status.Role for now (it is meant purely for the end user), behind this PR will be one to patch a label (smth like
valkey.io/current-role) on Pods of what their current role is (to be used in PDBs per-shard as part of #303). That implementation will sit in the same logic as this PR is adding.Features / Behaviour Changes
When the pod is not ready, the role reported will be an empty string - given that we do not want to serve stale data.
Implementation
Role resolution stays with the ValkeyNode controller (it remains the only writer of Status.Role), but it now becomes event-driven instead of relying on the 60s cadence:
Reviewer attention:
Limitations
Testing
Unit + envtest cover the role parsers, the set/clear/keep-last-known logic, the pod predicate and map function, the observed-role hint, and the scrape gating.
Tested locally on a Kind cluster:
Checklist
Before submitting the PR make sure the following are checked:
pre-commit run --all-filesor hooks on commit)