Skip to content

Commit b6b80ef

Browse files
Report empty address list instead of error. (#11603)
This is what I originally had and I was under the impression that ReportError had the same behavior but from reading the code it seems like the default balancer (pickfirst) handles these two calls differently.
1 parent 3cb2356 commit b6b80ef

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

server/util/kuberesolver/kuberesolver.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,13 @@ func (b *kubeResolverBuilder) Build(target resolver.Target, cc resolver.ClientCo
436436

437437
cancel, err := b.manager.WatchPodIP(endpoint, func(addr string, watchErr error) {
438438
if watchErr != nil {
439-
r.cc.ReportError(watchErr)
439+
// Report an empty address list. At least for the "pickfirst"
440+
// balancer it causes the existing connection to be closed
441+
// whereas calling ReportError causes it to keep using the old
442+
// address list. In the case where a pod is removed/restarted,
443+
// we wanted to close the connection since we know the IP is
444+
// no longer valid.
445+
_ = r.cc.UpdateState(resolver.State{})
440446
return
441447
}
442448
r.updateState(addr)

server/util/kuberesolver/kuberesolver_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,12 @@ func TestResolveNonExistentPod(t *testing.T) {
237237
require.NoError(t, err)
238238
defer r.Close()
239239

240-
// Should get an error reported since pod doesn't exist.
240+
// Should get an empty address list since pod doesn't exist.
241241
select {
242-
case err := <-cc.errors:
243-
require.Contains(t, err.Error(), "not found")
242+
case state := <-cc.states:
243+
require.Empty(t, state.Addresses)
244244
case <-time.After(5 * time.Second):
245-
require.FailNow(t, "timed out waiting for error")
245+
require.FailNow(t, "timed out waiting for state update")
246246
}
247247
}
248248

0 commit comments

Comments
 (0)