Skip to content

Use indexer for EndpointSlice lookups to avoid O(n) scans in confd#11838

Open
haojiwu wants to merge 1 commit intoprojectcalico:masterfrom
haojiwu:haoji/fix-endpointslice-issue-master
Open

Use indexer for EndpointSlice lookups to avoid O(n) scans in confd#11838
haojiwu wants to merge 1 commit intoprojectcalico:masterfrom
haojiwu:haoji/fix-endpointslice-issue-master

Conversation

@haojiwu
Copy link

@haojiwu haojiwu commented Feb 12, 2026

Description

Bug fix: Use a cache indexer for EndpointSlice lookups in confd's route generator to avoid O(n) full scans.

The k8s 1.33 bump (#10715, 0e18c27) migrated confd from the deprecated v1.Endpoints API to discovery/v1.EndpointSlice. Since a single Service can have multiple EndpointSlices, getEndpointsForService was changed to iterate all EndpointSlices via List() and filter by label. This works correctly but is O(n) in the total number of EndpointSlices across all services.

This PR adds a svcKey indexer on EndpointSlices keyed by namespace/serviceName and uses ByIndex for O(1) lookups.

Changes:

  • confd/pkg/backends/calico/routes.go: Add endpointSliceServiceIndex indexer function, register it in the EndpointSlice informer, and rewrite getEndpointsForService to use ByIndex()
  • confd/pkg/backends/calico/routes_test.go: Register the indexer in test setup to match production initialization

Testing:

Existing unit tests pass and cover the affected code paths.

We applied this change on top of release-v3.31 and deployed to our cluster. The calico-node CPU usage dropped significantly, from ~2 cores (left, v3.31.3) to ~0.8 cores (right, with fix):

image

Related issues/PRs

Fixes performance regression introduced by #10715.

Todos

  • Tests
  • Documentation
  • Release note

Release Note

TBD

Reminder for the reviewer

Make sure that this PR has the correct labels and milestone set.

Every PR needs one docs-* label.

  • docs-pr-required: This change requires a change to the documentation that has not been completed yet.
  • docs-completed: This change has all necessary documentation completed.
  • docs-not-required: This change has no user-facing impact and requires no docs.

Every PR needs one release-note-* label.

  • release-note-required: This PR has user-facing changes. Most PRs should have this label.
  • release-note-not-required: This PR has no user-facing changes.

Other optional labels:

  • cherry-pick-candidate: This PR should be cherry-picked to an earlier release. For bug fixes only.
  • needs-operator-pr: This PR is related to install and requires a corresponding change to the operator.

@haojiwu haojiwu requested a review from a team as a code owner February 12, 2026 22:00
@marvin-tigera marvin-tigera added this to the Calico v3.32.0 milestone Feb 12, 2026
@marvin-tigera marvin-tigera added release-note-required Change has user-facing impact (no matter how small) docs-pr-required Change is not yet documented labels Feb 12, 2026
@CLAassistant
Copy link

CLAassistant commented Feb 12, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-pr-required Change is not yet documented release-note-required Change has user-facing impact (no matter how small)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants