Repository navigation
feat(gateway): Add NetworkService session affinity - #1005
Conversation
9070dd0 to
e228c49
Compare
e228c49 to
15540b9
Compare
The gateway always hashed a client's address and source port, so every connection from one client was balanced on its own and nothing could pin a client to one backend. NetworkService gains spec.sessionAffinity with three values: - None, the default, keeps hashing the address and source port. - ClientIP hashes the client's address only, so every connection from one address reaches one backend. - ClientIPAndProtocol hashes the address and the L4 protocol. The setting reaches the datapath as one byte in each vip_table value. It sits in the alignment gap before generation, so the value stays 3216 bytes, a vip_table pinned by an older release stays compatible and keeps its rows, and those rows read as None. flow_hash and its Go mirror FlowHash take the affinity and the protocol, and VIPTable.Register refuses an unknown affinity. Under either client-IP mode the Maglev table is keyed by backend address rather than address and port. The API makes a tenant serve a second VIP from another NetworkService with a different backendPort, and keying by port would give those services different tables over the same pods, so a client would reach different backends. None keeps the old keying, so upgrading moves no existing flow. The engine compares the affinity when deciding whether a rule changed, so editing it reprograms every gateway node at the next reconcile without a restart. A change rehashes every connection of the service, and the docs say so, along with the bound that a backend-set change moves about 1 in N clients. Tests cover each mode across two independently programmed gateway nodes and three services over one backend set, the loaded XDP program against FlowHash for every mode over TCP and UDP on IPv6 and IPv4, a live affinity change, and an upgrade over a vip_table pinned at the previous layout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
15540b9 to
e29e48e
Compare
|
Two review passes ran before this was marked ready. CI is green at e29e48e, and auto-merge waits for an approving review. First pass, at 9070dd0. The reviewers split, so the open questions went to a person, who chose to land #1003 first, squash the follow-up commit, and roll out to staging on merge without a soak. Second pass, at 15540b9, after the squash and the rebase onto #1003. The person chose to land this before #845, whose author rebases and regenerates the CRD afterwards. Since then the branch was rebased onto #1006, which touched the same API file. Both sides were kept, the CRD and API reference regenerated with no extra diff, and the subject was shortened to 50 characters. The enum values What each reviewer ran: Locally at e29e48e, lint, the unit suite and the root eBPF suites pass, and the Kind e2e passed before the final rebase. No review requirement was relaxed, and the code owners are requested. |
Summary
The gateway balances each connection from a client on its own, so nothing can pin a client to one backend.
A service can now choose
ClientIPorClientIPAndProtocolaffinity, which sends a client's connections to one backend across ports and across services over the same backends, on every gateway node alike.The default keeps today's behaviour, and upgrading moves no existing flow.
Changing a service's affinity moves most of its open connections, and changing its backend set moves about one client in N, where N is the number of backends.
Test plan
Fixes #733
🤖 Generated with Claude Code