Skip to content

destination: return identity for a terminating pod when it is the only pod on its IP - #15770

Open
aniketatgithub wants to merge 1 commit into
linkerd:mainfrom
aniketatgithub:fix-15765-terminating-pod-identity
Open

aniketatgithub wants to merge 1 commit into
linkerd:mainfrom
aniketatgithub:fix-15765-terminating-pod-identity

Conversation

@aniketatgithub

Copy link
Copy Markdown

destination: return identity for a terminating pod when it is the only pod on its IP

Problem

When a pod is terminating but still running, new meshed clients that connect
to its IP get no identity from the destination controller. They connect in
plaintext, and a port that only allows MeshTLSAuthentication denies them.
getIndexedPods drops every pod with a deletionTimestamp, so a lookup
that starts after the delete finds nothing, even though the pod is still
serving traffic until its preStop hook finishes.

Solution

getIndexedPods now keeps a still-Running terminating pod as a fallback and
returns it when it is the only pod on the IP. When a live pod shares the IP,
the live pod wins, so the #5940 guard against two pods on one IP (AWS VPC
CNI reusing a terminating pod's IP) is unchanged. Succeeded/Failed pods are
never returned.

Validation

New TestIpWatcherGetTerminatingPod in
controller/api/destination/watcher/workload_watcher_test.go:

  • a single terminating Running pod is returned by getPodByPodIP
    (fails before the fix, passes after)
  • a live pod wins when it shares the IP with a terminating pod
  • two terminating pods on one IP return no pod
  • a Succeeded pod with a deletion timestamp returns no pod

go test ./controller/api/destination/watcher/ -run TestIpWatcherGetTerminatingPod
passes; gofmt and go vet are clean on the changed package.

Fixes #15765

Signed-off-by: Aniket aniketkomailkro@gmail.com

…y pod on its IP

Problem

When a pod is terminating but still running, new meshed clients that connect
to its IP get no identity from the destination controller. They connect in
plaintext, and a port that only allows MeshTLSAuthentication denies them.
`getIndexedPods` drops every pod with a `deletionTimestamp`, so a lookup
that starts after the delete finds nothing, even though the pod is still
serving traffic until its preStop hook finishes.

Solution

`getIndexedPods` now keeps a still-Running terminating pod as a fallback and
returns it when it is the only pod on the IP. When a live pod shares the IP,
the live pod wins, so the linkerd#5940 guard against two pods on one IP (AWS VPC
CNI reusing a terminating pod's IP) is unchanged. Succeeded/Failed pods are
never returned.

Validation

New `TestIpWatcherGetTerminatingPod` in
`controller/api/destination/watcher/workload_watcher_test.go`:
- a single terminating Running pod is returned by `getPodByPodIP`
  (fails before the fix, passes after)
- a live pod wins when it shares the IP with a terminating pod
- two terminating pods on one IP return no pod
- a Succeeded pod with a deletion timestamp returns no pod

`go test ./controller/api/destination/watcher/ -run TestIpWatcherGetTerminatingPod`
passes; `gofmt` and `go vet` are clean on the changed package.

Fixes linkerd#15765

Signed-off-by: Aniket <aniketkomailkro@gmail.com>
@aniketatgithub
aniketatgithub requested a review from a team as a code owner November 5, 2026 09:18
@aniketatgithub

Copy link
Copy Markdown
Author

Friendly ping — this has been open a week with no review yet, and the workflows are still waiting for approval to run. Could someone approve the runs and take a look when they get a chance?

@toidiu

toidiu commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

@aniketatgithub hey thanks for reporting the issue.

When a pod is terminating but still running, new meshed clients that connect
to its IP get no identity from the destination controller. They connect in
plaintext, and a port that only allows MeshTLSAuthentication denies them.
getIndexedPods drops every pod with a deletionTimestamp, so a lookup
that starts after the delete finds nothing, even though the pod is still
serving traffic until its preStop hook finishes.

Can you help me understand your use case here:

  • why you need to connect to a terminating pod?
    • since it is terminating, new connections would not be accepted right?
  • are there any alternatives that you considered that would work instead?

getIndexedPods now keeps a still-Running terminating pod as a fallback and
returns it when it is the only pod on the IP. When a live pod shares the IP,
the live pod wins

This make me pause since the logic is more complicated and correctness now relies on some subtle logic. This is why I would like to understand your usecase and see if there are other options.

@aniketatgithub

Copy link
Copy Markdown
Author

The reported use case is Pekko cluster remoting during rolling restarts, where new members join by connecting to existing members by IP while they leave, and the terminating pod still accepts connections until its preStop hook finishes. The alternative would be for joining members to wait out the grace period, which stalls cluster formation on every restart. The fix only makes new lookups match what lookups started before the delete already return, and the #5940 guard is unchanged when a live pod shares the IP.

@tiagomota

Copy link
Copy Markdown

Thanks for picking this up @aniketatgithub, and thanks @toidiu for looking. Adding some context on the use case that lead to me reporting #15765:

Why connect to a terminating pod?

  • Deletion only removes the pod from Service endpoints.
  • Its IP stays routable and the process keeps accepting connections until it exits.
  • Clustered systems that talk peer-to-peer by pod IP depend on that during graceful shutdown.
    • In our case it's Pekko cluster remoting: on SIGTERM a member leaves the cluster and hands its work over to the other members.
    • Until that finishes, it is still a member, and every other member, including pods started by the same rollout, must be able to reach it.
    • Linkerd agrees the pod is reachable: its proxy accepts the connection and runs authorization. It denies the connection only because the client got no identity from discovery and sent plaintext.

What breaks?

  • With a MeshTLSAuthentication-only policy on the remoting port, a rolling restart had a new pod marking the leaving member unreachable.
  • The split brain resolver then downed members and the service returned errors for a couple of minutes. We see the same no-identity fingerprint (no_tls_reason="not_provided_by_service_discovery", no dst_pod) in most rollouts, for remoting and for Pekko Management bootstrap probes, which also dial pod IPs.

Alternatives we tried or rejected:

  • Shortening the shutdown window: it narrows the race, but there is always a gap between the deletion mark and the member leaving.
  • Admitting the pod subnet unauthenticated on that port: our current workaround, but it defeats a mesh-only policy.
  • Making new pods wait until no peer is terminating: application code per protocol and per port, and it slows every rollout.
  • Running a patched destination controller: works (it's the repro result in the issue), but we'd rather not maintain a fork.

On your subtle logic concern:

  • I think the current behavior is already timing-dependent. A client whose lookup started before the deletion keeps getting the pod's identity, and a client whose lookup starts one second later gets none, for the same pod and port.
  • This change makes new lookups match existing watches.
  • The Ignore pods in "Terminating" when watching IP addresses. #5940 protection is unchanged: the terminating pod is returned only when it is the only pod on the IP, so a reused IP still resolves to the live pod and at most one pod is ever returned. Relax Pod readiness requirements for destination controller #13557 made the same kind of change for pods that aren't ready yet.

@toidiu toidiu self-assigned this Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Destination controller returns no identity for a terminating pod on a new pod-IP lookup

3 participants