Skip to content

feat(kg): add a configurable --check-in-period flag - #550

Open
IvanHunters wants to merge 1 commit into
squat:mainfrom
IvanHunters:feat/configurable-check-in-period
Open

IvanHunters wants to merge 1 commit into
squat:mainfrom
IvanHunters:feat/configurable-check-in-period

Conversation

@IvanHunters

Copy link
Copy Markdown

What

Add a --check-in-period flag to kg so the node check-in interval, and the Ready staleness window derived from it, can be tuned. The default is unchanged at 30s, so existing deployments behave exactly as before.

Why

A node's WireGuard IP is assigned by its rank in the currently Ready set: NewTopology allocates addresses over the sorted segments, and the segment list is built only from nodes that pass Node.Ready(). A node is Ready only while its last-seen annotation is within 2 * checkInPeriod (60s by default), and each node refreshes its own last-seen every checkInPeriod (30s).

On large clusters (around 200 nodes) the per-node last-seen writes generate enough watch churn that liveness cannot propagate within the 60s window. Every agent's Ready set collapses to a small subset, allocation runs over that tiny set, and most nodes end up assigning their own node the first address of the subnet, colliding on a single WireGuard IP. Because the IP is a function of rank in the Ready set, a single Ready flap shifts many nodes' IPs, which triggers more rewrites and more churn, so the system oscillates around the Ready threshold.

Making the period configurable lets operators widen the freshness window on large clusters so the Ready set stays close to the full node set. This is a mitigation, not a root-cause fix: the underlying problem is that IP allocation is coupled to the volatile Ready set. Full analysis and other fix directions are in #549.

Changes

  • pkg/mesh/backend.go: checkInPeriod becomes a package variable defaulting to the new exported DefaultCheckInPeriod (30s); semantics are unchanged.
  • pkg/mesh/mesh.go: New takes a checkIn time.Duration; when it is greater than zero it sets the period, otherwise the default is kept, so existing New callers and tests are unaffected.
  • cmd/kg/main.go: register the --check-in-period flag with default mesh.DefaultCheckInPeriod and pass it to mesh.New.

Testing

  • go build ./... (linux/amd64)
  • go test ./pkg/mesh/
  • go vet ./pkg/mesh/ ./cmd/kg/

A node's WireGuard IP is assigned by its rank in the currently Ready
set, and a node counts as Ready only while its last-seen annotation is
within twice the check-in period (60s by default). On large clusters the
per-node last-seen writes generate enough watch churn that liveness
cannot propagate within that window, so every agent's Ready set collapses
and most nodes collide on the first address of the subnet.

Add a --check-in-period flag so operators can widen the freshness window
on large clusters. The default is unchanged at 30s, so existing
deployments behave exactly as before.

Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
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