diff --git a/pkg/proxy/topology.go b/pkg/proxy/topology.go index ef16d559b1c..d68aeb40f94 100644 --- a/pkg/proxy/topology.go +++ b/pkg/proxy/topology.go @@ -52,6 +52,19 @@ func CategorizeEndpoints(endpoints []Endpoint, svcInfo ServicePort, nodeLabels m return true }) + // if there are 0 cluster-wide endpoints, we can try to fallback to any terminating endpoints that are ready. + // When falling back to terminating endpoints, we do NOT consider topology aware routing since this is a best + // effort attempt to avoid dropping connections. + if len(clusterEndpoints) == 0 && utilfeature.DefaultFeatureGate.Enabled(features.ProxyTerminatingEndpoints) { + clusterEndpoints = filterEndpoints(endpoints, func(ep Endpoint) bool { + if ep.IsServing() && ep.IsTerminating() { + return true + } + + return false + }) + } + // If there are any Ready endpoints anywhere in the cluster, we are // guaranteed to get one in clusterEndpoints. if len(clusterEndpoints) > 0 { diff --git a/pkg/proxy/topology_test.go b/pkg/proxy/topology_test.go index 35c110815a2..cdab4926ccb 100644 --- a/pkg/proxy/topology_test.go +++ b/pkg/proxy/topology_test.go @@ -350,7 +350,17 @@ func TestCategorizeEndpoints(t *testing.T) { serviceInfo: &BaseServiceInfo{}, endpoints: []Endpoint{ &BaseEndpointInfo{Endpoint: "10.0.0.0:80", Ready: false, Serving: true, Terminating: true, IsLocal: true}, - &BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: false, Serving: true, Terminating: true, IsLocal: true}, + &BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: false, Serving: true, Terminating: true, IsLocal: false}, + }, + clusterEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.1:80"), + localEndpoints: nil, + }, { + name: "Cluster traffic policy, PTE disabled, all endpoints are terminating", + pteEnabled: false, + serviceInfo: &BaseServiceInfo{}, + endpoints: []Endpoint{ + &BaseEndpointInfo{Endpoint: "10.0.0.0:80", Ready: false, Serving: true, Terminating: true, IsLocal: true}, + &BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: false, Serving: true, Terminating: true, IsLocal: false}, }, clusterEndpoints: sets.NewString(), localEndpoints: nil, @@ -412,9 +422,9 @@ func TestCategorizeEndpoints(t *testing.T) { &BaseEndpointInfo{Endpoint: "10.0.0.0:80", Ready: false, Serving: true, Terminating: true, IsLocal: false}, &BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: false, Serving: true, Terminating: true, IsLocal: false}, }, - clusterEndpoints: sets.NewString(), + clusterEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.1:80"), localEndpoints: sets.NewString(), - allEndpoints: sets.NewString(), + allEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.1:80"), onlyRemoteEndpoints: true, }, { name: "iTP: Cluster, eTP: Local, PTE disabled, with terminating endpoints",