fix: reconcile EC2 endpoints promptly after backend changes#14228
Merged
Conversation
Three eventual-consistency gaps in EC2 discovery, all stemming from the endpoint state only updating on the periodic refresh tick: - A spec change (port, address type, filters, region) served endpoints resolved under the old config for up to a full refresh interval; a port change routed traffic to the wrong port. The cached state now carries its config key, and endpoints resolved under different endpoint semantics are discarded instead of served. - A newly created backend served no endpoints until the next tick. The KRT transform now requests an immediate on-demand refresh (coalesced via a single-slot channel) when state is missing or stale. - A credential rotation (secret resourceVersion bump or role change) combined with a transient AWS listing failure wiped healthy endpoints, because the carry-forward required full config equality. Carry-forward and serving now tolerate credential-only changes: credentials affect authorization to list instances, not which endpoints a listing yields. Signed-off-by: omar <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves EC2 backend endpoint discovery by eliminating stale endpoint serving after Backend spec changes and by triggering on-demand refreshes to reduce time-to-correctness for new or changed backends, while also preserving previously-resolved endpoints across credential-only changes when AWS listing fails.
Changes:
- Added
endpointSemanticsEqualto distinguish endpoint-affecting config changes from credential-only changes. - Introduced a single-slot
refreshChand on-demand refresh requests to reconcile missing/stale state promptly. - Updated state carry-forward logic to preserve endpoints across credential-only changes during refresh failures, and updated
endpointsForBackendto discard cached endpoints resolved under outdated endpoint semantics.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/kgateway/extensions2/plugins/backend/ec2.go | Adds endpoint-semantics comparison, on-demand refresh signaling, and updated caching/serve logic to avoid stale endpoints and preserve endpoints across credential-only changes. |
| pkg/kgateway/extensions2/plugins/backend/ec2_test.go | Adds unit tests covering on-demand refresh requests, stale-state discard on semantic changes, and endpoint preservation across credential-only changes with refresh failures. |
Signed-off-by: omar <[email protected]>
davidjumani
approved these changes
Jun 25, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Jun 25, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Jun 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
EC2 endpoint discovery resolves instances on a periodic refresh tick (default 30s) and caches the result per backend. Three eventual-consistency gaps follow from the cached state only updating on that tick:
ec2config changed (port, address type, filters, region), KRT recomputed the endpoints immediately but served the addresses and port resolved under the old config until the next tick — a port change routed traffic to the wrong port for up to a full refresh interval.Changes
ec2BackendStateKeygainsendpointSemanticsEqual, comparing only the fields that determine which endpoints a listing yields (region, port, address type, filters) and deliberately excluding credential fields (role ARN, secret), which only affect authorization to list.endpointsForBackendnow compares the cached state's config key against the backend's current config:refreshChlets the KRT transform request an immediate on-demand refresh whenever state is missing (fixes 2) or stale (shrinks the staleness window in 1 from the refresh interval to roughly oneDescribeInstancesround-trip). Requests coalesce in the buffer; there is no re-trigger loop because every refresh — including a failed one — rewrites the state key to the current config.computeStatenow usesendpointSemanticsEqual, so a credential-only change followed by a failed re-list keeps the previously resolved endpoints (fixes 3). Semantic changes still clear them.Behavior note
For a semantic spec change, this trades "briefly wrong endpoints" for "briefly no endpoints" until the on-demand refresh lands. For a port change, serving the old port was actively wrong; the no-endpoint window is now typically a single AWS API round-trip rather than the refresh interval.
Change Type
/kind fix
Changelog
Additional Notes
Unit-test coverage: refresh requested when state is missing, stale state discarded after a port change, cached endpoints served across a credential-only change, and carry-forward preserved across a credential-only change with a failing lister. The existing test asserting that a full config change clears endpoints on failure is unchanged.