Skip to content

FQDN: preallocate identities for fqdn selectors#39868

Merged
squeed merged 4 commits intocilium:mainfrom
squeed:namemanager-preallocate-identities
Jun 17, 2025
Merged

FQDN: preallocate identities for fqdn selectors#39868
squeed merged 4 commits intocilium:mainfrom
squeed:namemanager-preallocate-identities

Conversation

@squeed
Copy link
Copy Markdown
Contributor

@squeed squeed commented Jun 3, 2025

Background: the ToFQDN policy feature works by assigning labels with source fqdn: to IP addresses as names are learned. For example, the IP address 1.1.1.1 may have the labels (reserved:world, fqdn:one.one.one.one). (Note that IPs no longer have per-IP labels unless also selected by toCIDR policies.)

Before this change, identities were allocated when the first IP was discovered that matched a selector. Now, identities are allocated when ToFQDN policies are first created.

The goal is to reduce tail latency. Because allocating an identity requires a policy update, all endpoints must lock, apply incremental changes, and update envoy before the DNS packet can be returned to the requesting pod.

By pre-allocating identities, newly learned IPs require only an ipcache write, not a policymap and envoy update. This reduces DNS response latency.

Reduces ToFQDN selector tail latency by pre-allocating selected identities. This slightly increases bpf policymap utilization.

@squeed squeed requested review from a team as code owners June 3, 2025 14:47
@squeed squeed added the kind/enhancement This would improve or streamline existing functionality. label Jun 3, 2025
@squeed squeed requested a review from viktor-kurchenko June 3, 2025 14:47
@squeed squeed added kind/performance There is a performance impact of this. release-note/minor This PR changes functionality that users may find relevant to operating Cilium. sig/policy Impacts whether traffic is allowed or denied based on user-defined policies. labels Jun 3, 2025
@squeed squeed requested a review from bimmlerd June 3, 2025 14:47
@squeed squeed added the area/fqdn Affects the FQDN policies feature label Jun 3, 2025
@squeed squeed requested review from gandro and joamaki June 3, 2025 14:47
Copy link
Copy Markdown
Member

@bimmlerd bimmlerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, some nits.

Copy link
Copy Markdown
Member

@gandro gandro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad to see this finally happening! 🎉 Two comments

@squeed
Copy link
Copy Markdown
Contributor Author

squeed commented Jun 5, 2025

As @gandro observed, there is a race between the allocator and ipcache, as both want to own the policy map update lifecycle.

I will file a PR shortly that moves updates exclusively to the allocator. Once that merges, we can proceed with this PR.

@squeed squeed added the dont-merge/blocked Another PR must be merged before this one. label Jun 5, 2025
@squeed
Copy link
Copy Markdown
Contributor Author

squeed commented Jun 10, 2025

Filed #39970 to refactor identity distribution. Once that merges I'll rebase this, and the race will go away.

@squeed squeed force-pushed the namemanager-preallocate-identities branch from d8907f2 to 9fb2b8d Compare June 16, 2025 11:59
@squeed squeed requested a review from gandro June 16, 2025 12:01
@squeed squeed force-pushed the namemanager-preallocate-identities branch from 9fb2b8d to 99214b5 Compare June 16, 2025 12:04
@squeed squeed removed the dont-merge/blocked Another PR must be merged before this one. label Jun 16, 2025
Copy link
Copy Markdown
Member

@gandro gandro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me now!

@squeed
Copy link
Copy Markdown
Contributor Author

squeed commented Jun 16, 2025

/test

@squeed squeed force-pushed the namemanager-preallocate-identities branch from 99214b5 to 416ae94 Compare June 16, 2025 15:01
@squeed
Copy link
Copy Markdown
Contributor Author

squeed commented Jun 16, 2025

Whoops, this triggered an ipcache deadlock. Fortunately the fix was simple.

@squeed
Copy link
Copy Markdown
Contributor Author

squeed commented Jun 16, 2025

/test

@squeed squeed force-pushed the namemanager-preallocate-identities branch from 416ae94 to cd25b56 Compare June 16, 2025 15:43
@squeed
Copy link
Copy Markdown
Contributor Author

squeed commented Jun 16, 2025

/test

squeed added 4 commits June 16, 2025 22:27
The local identity allocator checkpoints its state, and restores it
early in daemon startup. However, there may be other users of the
allocator that allocate local identities early on startup.

We should not permit allocation to happen until checkpoint restoration
is complete. Thus, we start the allocator locked, only unlocking when
restoration is complete.

Signed-off-by: Casey Callendrello <cdc@isovalent.com>
Background: the ToFQDN policy feature works by assigning labels with
source `fqdn:` to IP addresses as names are learned. For example, the IP
address 1.1.1.1 may have the labels (reserved:world,
fqdn:one.one.one.one).

Before this change, identities were allocated when the first IP was
discovered that matched a selector. Now, identities are allocated when
ToFQDN policies are first created.

The goal is to reduce tail latency. Because allocating an identity
requires a policy update, all endpoints must lock, apply incremental
changes, and update envoy *before* the DNS packet can be returned to the
requesting pod.

By pre-allocating identities, newly learned IPs require only an ipcache
write, not a policymap and envoy update. This reduces DNS response
latency.

Signed-off-by: Casey Callendrello <cdc@isovalent.com>
This just wires up dnsProxy.preAllocateIdentities to the
--tofqdns-preallocate-identities flag.

Signed-off-by: Casey Callendrello <cdc@isovalent.com>
Now that we require identity allocation to be synchronous, we put
ourselves at risk of a deadlock between the ipcache and the NameManager.

Specifically, the IPCache holds the metadata lock while it allocates
identities, but the allocator depends on the SelectorCache making
progress. Unfortunately, the SelectorCache can be blocked on the
NameManager, and the NameManager needs to be able to upsert in to the
ipcache metadata layer.

The fix is to drop the ipcache metadata lock while allocating, which is
a good idea anyways.

Signed-off-by: Casey Callendrello <cdc@isovalent.com>
@squeed squeed force-pushed the namemanager-preallocate-identities branch from cd25b56 to 40a6dea Compare June 16, 2025 20:27
@squeed
Copy link
Copy Markdown
Contributor Author

squeed commented Jun 16, 2025

Needed to adjust the Ginkgo test slightly to expect two identities in a command that previously got one. Just some fragile json parsing that needed fixing.

@squeed
Copy link
Copy Markdown
Contributor Author

squeed commented Jun 16, 2025

/test

@squeed squeed enabled auto-merge June 16, 2025 21:13
@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jun 17, 2025
@squeed squeed added this pull request to the merge queue Jun 17, 2025
Merged via the queue into cilium:main with commit 495164a Jun 17, 2025
68 checks passed
@squeed squeed deleted the namemanager-preallocate-identities branch June 17, 2025 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/fqdn Affects the FQDN policies feature kind/enhancement This would improve or streamline existing functionality. kind/performance There is a performance impact of this. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/minor This PR changes functionality that users may find relevant to operating Cilium. sig/policy Impacts whether traffic is allowed or denied based on user-defined policies.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants