Blog

One family cleared the other's change: dual-stack lease updates in flannel

On this page
  1. When it happens
  2. Why the gap existed
  3. What a peer does with that
  4. The fix
  5. The test
  6. What review changed
  7. The lesson

In flannel’s kube subnet manager, a dual-stack node that changed only its IPv4 public address, or only its IPv6 one, sent no lease event to the other nodes. I sent the fix (PR #2610, merged 2026-11-19). It changes nine lines of handleUpdateLeaseEvent and adds one table test. The PR links no issue.

When it happens

With the kube subnet manager, flanneld on each node writes annotations on its own Node object: backend-type, backend-data, public-ip, backend-v6-data and public-ipv6, under a prefix such as flannel.alpha.coreos.com/. Every other node watches Nodes. On each update, handleUpdateLeaseEvent decides whether the change is worth a lease event, and nodeToLease builds the lease. On a dual-stack node that lease holds the IPv4 and IPv6 pod CIDRs, PublicIP, PublicIPv6, BackendData, BackendV6Data and one BackendType shared by both families (pkg/subnet/kube/kube.go, nodeToLease, lines 542-620).

The case from the PR: a dual-stack node (EnableIPv4 and EnableIPv6 both true) whose IPv4 public address changes from 192.0.2.10 to 192.0.2.11. Its flanneld patches public-ip and leaves the IPv6 annotations alone. On master the handler sent no event. The new test failed there like this:

kube_test.go:117: dual-stack, public ip: expected lease event true, but was false.
kube_test.go:117: dual-stack, backend data: expected lease event true, but was false.
kube_test.go:117: dual-stack, public ipv6: expected lease event true, but was false.
kube_test.go:117: dual-stack, backend v6 data: expected lease event true, but was false.

The periodic resync does not repair this. It runs every five minutes (resyncPeriod, kube.go:51) and, per the PR, delivers the node unchanged as old and new, so the handler sees no difference. The other nodes keep the old public address of that node until a later update changes the annotations of both families, or their own flanneld restarts.

Why the gap existed

The IPv4 check and the IPv6 check shared one flag. Abbreviated:

var changed = true
if ksm.enableIPv4 && /* v4 data, type and public-ip all equal */ {
	changed = false
}
if ksm.enableIPv6 && /* v6 data, type and public-ipv6 all equal */ {
	changed = false
}

A check cleared the flag when its own family was unchanged. On a dual-stack node, one family always was. An IPv4-only change was cleared by the IPv6 check, and an IPv6-only change by the IPv4 check. Single-stack nodes run one check, so they were fine. A change to backend-type is seen by both checks, so neither cleared the flag; the merge commit message says updates that change both families behave as before.

What a peer does with that

I read the vxlan backend at the merge commit. A lease event reaches handleSubnetEvents (pkg/backend/vxlan/vxlan_network.go:398). For an EventAdded it builds the peer’s state from the lease’s public address. With direct routing it replaces the route to the node’s subnet with the public IP as gateway (lines 432-434, 479-482). Without it, it adds an ARP entry for the subnet, an FDB entry keyed on PublicIP, and the vxlan route (lines 488-514). The IPv6 side does the same with PublicIPv6 (lines 542-551). When the handler drops the update, none of that runs, so the peer’s entries still name the old address. I did not measure how traffic fails after that, and the PR does not report it.

The fix

The flag now starts false, and each enabled family sets it when the backend type or its own annotations differ (kube.go:318-330):

var changed = false
if ksm.enableIPv4 && (/* v4 data, type or public-ip differ */) {
	changed = true
}
if ksm.enableIPv6 && (/* v6 data, type or public-ipv6 differ */) {
	changed = true
}

If the flag is still false the handler returns. Otherwise it builds the lease and queues an EventAdded (kube.go:331-340). The event carries the whole lease, both families. The visible change, per the PR: a single-family update on a dual-stack cluster now produces a lease event and the usual “Creating the node lease” log line. Single-stack updates behave as before.

The test

TestHandleUpdateLeaseEvent (pkg/subnet/kube/kube_test.go:59) has 11 rows (lines 93-103): five dual-stack, three IPv4-only, three IPv6-only. Each row builds an old node and a new node with some annotations changed, calls the handler on a manager with a one-slot events channel, and checks whether one event was queued. The single-stack rows include the opposite family: with only IPv4 enabled, a changed public-ipv6 expects no event, and with only IPv6 enabled, a changed public-ip expects none.

The PR reports the results of go test -count=3 -v -run 'TestHandleUpdateLeaseEvent' ./pkg/subnet/kube: on master 4 rows fail in each of 3 runs, the four above; with the fix 11 of 11 pass in each of 3 runs, and the whole package passes.

What review changed

Nothing in the patch. The review bot left a summary that recommended approval and listed no open issues. @thomasferrandiz wrote: “Thanks for the fix. Can you please check the failing test?”

The failing test job stopped in functional/k8s_test.go:148 while creating the first Node, before Flannel started. It was the shared test-CA problem reported in #2620 and fixed by #2621. I rebased onto a commit that includes that fix. The lease-update patch stayed the same. go test -race ./pkg/subnet/kube -count=3 and go vet ./pkg/subnet/kube passed locally. I did not run the full Docker functional suite locally; the updated branch was set to run it in CI. @thomasferrandiz approved the PR and merged it (merge dated 2026-11-19).

The lesson

  • Two checks that share one flag should move it in one direction only. Collect the differences, then decide.
  • A periodic resync cannot repair an update handler that drops deltas, because it hands over the same object as old and new.
  • Test each family of a dual-stack setup alone. Rows that change both families, or nothing, pass on the broken code.

If you run flannel on dual-stack nodes whose public addresses change, reply on X.