Skip to content

Commit ff640c3

Browse files
committed
Minor updates to kube-proxy topology code
Clarify the comments around terminating endpoints. Remove stale references to the ProxyTerminatingEndpoints feature gate in the unit tests.
1 parent 19952a2 commit ff640c3

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

pkg/proxy/topology.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,19 @@ import (
2626
// - The service's usable Cluster-traffic-policy endpoints (taking topology into account, if
2727
// relevant). This will be nil if the service does not ever use Cluster traffic policy.
2828
//
29-
// - The service's usable Local-traffic-policy endpoints (including terminating endpoints, if
30-
// relevant). This will be nil if the service does not ever use Local traffic policy.
29+
// - The service's usable Local-traffic-policy endpoints. This will be nil if the
30+
// service does not ever use Local traffic policy.
3131
//
3232
// - The combined list of all endpoints reachable from this node (which is the union of the
3333
// previous two lists, but in the case where it is identical to one or the other, we avoid
3434
// allocating a separate list).
3535
//
3636
// - An indication of whether the service has any endpoints reachable from anywhere in the
3737
// cluster. (This may be true even if allReachableEndpoints is empty.)
38+
//
39+
// "Usable endpoints" means Ready endpoints by default, but will fall back to
40+
// Serving-Terminating endpoints (independently for Cluster and Local) if no Ready
41+
// endpoints are available.
3842
func CategorizeEndpoints(endpoints []Endpoint, svcInfo ServicePort, nodeLabels map[string]string) (clusterEndpoints, localEndpoints, allReachableEndpoints []Endpoint, hasAnyEndpoints bool) {
3943
var useTopology, useServingTerminatingEndpoints bool
4044

@@ -50,9 +54,10 @@ func CategorizeEndpoints(endpoints []Endpoint, svcInfo ServicePort, nodeLabels m
5054
return true
5155
})
5256

53-
// if there are 0 cluster-wide endpoints, we can try to fallback to any terminating endpoints that are ready.
54-
// When falling back to terminating endpoints, we do NOT consider topology aware routing since this is a best
55-
// effort attempt to avoid dropping connections.
57+
// If we didn't get any endpoints, try again using terminating endpoints.
58+
// (Note that we would already have chosen to ignore topology if there
59+
// were no ready endpoints for the given topology, so the problem at this
60+
// point must be that there are no ready endpoints anywhere.)
5661
if len(clusterEndpoints) == 0 {
5762
clusterEndpoints = filterEndpoints(endpoints, func(ep Endpoint) bool {
5863
if ep.IsServing() && ep.IsTerminating() {

pkg/proxy/topology_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ func checkExpectedEndpoints(expected sets.Set[string], actual []Endpoint) error
4545
func TestCategorizeEndpoints(t *testing.T) {
4646
testCases := []struct {
4747
name string
48-
pteEnabled bool
4948
nodeLabels map[string]string
5049
serviceInfo ServicePort
5150
endpoints []Endpoint
@@ -240,7 +239,6 @@ func TestCategorizeEndpoints(t *testing.T) {
240239
localEndpoints: nil,
241240
}, {
242241
name: "Cluster traffic policy, all endpoints are terminating",
243-
pteEnabled: true,
244242
serviceInfo: &BaseServicePortInfo{},
245243
endpoints: []Endpoint{
246244
&BaseEndpointInfo{endpoint: "10.0.0.0:80", ready: false, serving: true, terminating: true, isLocal: true},
@@ -290,7 +288,6 @@ func TestCategorizeEndpoints(t *testing.T) {
290288
allEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.1:80"),
291289
}, {
292290
name: "iTP: Local, eTP: Local, all endpoints remote and terminating",
293-
pteEnabled: true,
294291
serviceInfo: &BaseServicePortInfo{internalPolicyLocal: true, externalPolicyLocal: true, nodePort: 8080},
295292
endpoints: []Endpoint{
296293
&BaseEndpointInfo{endpoint: "10.0.0.0:80", ready: false, serving: true, terminating: true, isLocal: false},
@@ -302,7 +299,6 @@ func TestCategorizeEndpoints(t *testing.T) {
302299
onlyRemoteEndpoints: true,
303300
}, {
304301
name: "iTP: Cluster, eTP: Local, with terminating endpoints",
305-
pteEnabled: true,
306302
serviceInfo: &BaseServicePortInfo{internalPolicyLocal: false, externalPolicyLocal: true, nodePort: 8080},
307303
endpoints: []Endpoint{
308304
&BaseEndpointInfo{endpoint: "10.0.0.0:80", ready: true, isLocal: false},

0 commit comments

Comments
 (0)