serviceentry: drain Terminating pods from ServiceEntry-derived endpoints#14332
Merged
davidjumani merged 2 commits intoJun 30, 2026
Merged
Conversation
…d base for enterprise build) Signed-off-by: Nick Nellis <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes ServiceEntry-derived endpoint selection so north-south traffic drains pods as soon as they begin terminating (deletionTimestamp set), preventing Envoy EDS from continuing to route to a terminating-but-still-Ready local pod for its full grace period and enabling timely failover to healthy peer-cluster endpoints.
Changes:
- Extend
krtcollections.LocalityPodwith aTerminatingflag derived frompod.DeletionTimestamp. - Update ServiceEntry workload->endpoint conversion to exclude pod-backed workloads that are either
NotReadyorTerminating. - Add unit coverage ensuring terminating pods are excluded while WorkloadEntry/inline endpoints remain included.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/krtcollections/pods.go | Adds Terminating to LocalityPod, includes it in equality, and populates it from pod deletionTimestamp. |
| pkg/kgateway/extensions2/plugins/serviceentry/endpoints.go | Filters ServiceEntry-derived endpoints to skip terminating workloads in addition to not-ready workloads. |
| pkg/kgateway/extensions2/plugins/serviceentry/endpoints_test.go | Adds a unit test asserting terminating-but-ready pods are excluded while WorkloadEntry endpoints remain. |
| pkg/kgateway/extensions2/plugins/serviceentry/collections.go | Ensures WorkloadEntry/inline-derived synthetic workloads explicitly set Terminating: false. |
nmnellis
force-pushed
the
fix/se-terminating-clean
branch
from
June 30, 2026 15:46
00b4c1b to
b65953f
Compare
ymesika
approved these changes
Jun 30, 2026
Signed-off-by: Nick Nellis <[email protected]>
ymesika
approved these changes
Jun 30, 2026
davidjumani
enabled auto-merge
June 30, 2026 17:03
This was referenced Jun 30, 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
North-south traffic through kgateway to a global service (HTTPRoute → Istio
Hostnamebackend → ServiceEntry-derived EDS) keeps routing to a Terminating local pod for the duration of its termination grace period, instead of failing over to a healthy peer-cluster endpoint. The east-west (ztunnel) path and the plain Kubernetes Service backend path both drain the pod correctly; only the ServiceEntry path does not.Root cause. The ServiceEntry endpoint path filters workloads solely on the pod's
Readycondition (LocalityPod.Ready, derived fromisPodReadyConditionTrue). A pod that is terminating but still running keeps itsReadyconditionTruethrough itspreStop/ grace period — kubelet does not flip it to false on deletion. The other terminal signal,checkPodTerminal, only coversPhase == Failed || Succeeded, so aRunningterminating pod is not terminal either. Neither the pod'sdeletionTimestampnor the EndpointSliceterminatingcondition is consulted. As a result the terminating pod stays in the Envoy EDS atpriority 0, health_flags::healthy, the cross-cluster tier atpriority 1is never promoted, and new requests continue to hit the draining pod.Change. Carry a
Terminatingflag onLocalityPod(deletionTimestamp != nil;falsefor WorkloadEntry/inline/remote endpoints, whose health is managed by the remote cluster) and skip terminating pod-backed workloads inendpointsFromWorkloads, extending the existing readiness guard. Scoped to local pods only, so cross-cluster failover targets are never evicted.Change Type
/kind fix
Changelog
Additional Notes
Extends the ServiceEntry readiness fix (#14222) to the terminating state. The EndpointSlice-based Service path and ztunnel already drain terminating pods; this brings the ServiceEntry path to parity. Verified with a new unit test (
TestEndpointsFromWorkloads_SkipsTerminatingPods) and end-to-end on a 2-cluster ambient kind mesh (terminating local pod is removed from the kgateway EDS and N/S fails over to the peer cluster).