diff --git a/pkg/proxy/topology.go b/pkg/proxy/topology.go index 3c5caa0e60d..ae7274c5b25 100644 --- a/pkg/proxy/topology.go +++ b/pkg/proxy/topology.go @@ -68,6 +68,9 @@ func filterEndpointsWithHints(endpoints []Endpoint, hintsAnnotation string, node filteredEndpoints := []Endpoint{} for _, endpoint := range endpoints { + if !endpoint.IsReady() { + continue + } if endpoint.GetZoneHints().Len() == 0 { klog.InfoS("Skipping topology aware endpoint filtering since one or more endpoints is missing a zone hint") return endpoints diff --git a/pkg/proxy/topology_test.go b/pkg/proxy/topology_test.go index 9587d70933a..ae9dcdfece2 100644 --- a/pkg/proxy/topology_test.go +++ b/pkg/proxy/topology_test.go @@ -31,6 +31,7 @@ func TestFilterEndpoints(t *testing.T) { type endpoint struct { ip string zoneHints sets.String + unready bool } testCases := []struct { name string @@ -138,12 +139,12 @@ func TestFilterEndpoints(t *testing.T) { endpoints := []Endpoint{} for _, ep := range tc.endpoints { - endpoints = append(endpoints, &BaseEndpointInfo{Endpoint: ep.ip, ZoneHints: ep.zoneHints}) + endpoints = append(endpoints, &BaseEndpointInfo{Endpoint: ep.ip, ZoneHints: ep.zoneHints, Ready: !ep.unready}) } expectedEndpoints := []Endpoint{} for _, ep := range tc.expectedEndpoints { - expectedEndpoints = append(expectedEndpoints, &BaseEndpointInfo{Endpoint: ep.ip, ZoneHints: ep.zoneHints}) + expectedEndpoints = append(expectedEndpoints, &BaseEndpointInfo{Endpoint: ep.ip, ZoneHints: ep.zoneHints, Ready: !ep.unready}) } filteredEndpoints := FilterEndpoints(endpoints, tc.serviceInfo, tc.nodeLabels) @@ -161,6 +162,7 @@ func Test_filterEndpointsWithHints(t *testing.T) { type endpoint struct { ip string zoneHints sets.String + unready bool } testCases := []struct { name string @@ -200,6 +202,35 @@ func Test_filterEndpointsWithHints(t *testing.T) { {ip: "10.1.2.3", zoneHints: sets.NewString("zone-a")}, {ip: "10.1.2.6", zoneHints: sets.NewString("zone-a")}, }, + }, { + name: "unready endpoint", + nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"}, + hintsAnnotation: "auto", + endpoints: []endpoint{ + {ip: "10.1.2.3", zoneHints: sets.NewString("zone-a")}, + {ip: "10.1.2.4", zoneHints: sets.NewString("zone-b")}, + {ip: "10.1.2.5", zoneHints: sets.NewString("zone-c")}, + {ip: "10.1.2.6", zoneHints: sets.NewString("zone-a"), unready: true}, + }, + expectedEndpoints: []endpoint{ + {ip: "10.1.2.3", zoneHints: sets.NewString("zone-a")}, + }, + }, { + name: "only unready endpoints in same zone (should not filter)", + nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"}, + hintsAnnotation: "auto", + endpoints: []endpoint{ + {ip: "10.1.2.3", zoneHints: sets.NewString("zone-a"), unready: true}, + {ip: "10.1.2.4", zoneHints: sets.NewString("zone-b")}, + {ip: "10.1.2.5", zoneHints: sets.NewString("zone-c")}, + {ip: "10.1.2.6", zoneHints: sets.NewString("zone-a"), unready: true}, + }, + expectedEndpoints: []endpoint{ + {ip: "10.1.2.3", zoneHints: sets.NewString("zone-a"), unready: true}, + {ip: "10.1.2.4", zoneHints: sets.NewString("zone-b")}, + {ip: "10.1.2.5", zoneHints: sets.NewString("zone-c")}, + {ip: "10.1.2.6", zoneHints: sets.NewString("zone-a"), unready: true}, + }, }, { name: "normal endpoint filtering, Auto annotation", nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"}, @@ -291,12 +322,12 @@ func Test_filterEndpointsWithHints(t *testing.T) { t.Run(tc.name, func(t *testing.T) { endpoints := []Endpoint{} for _, ep := range tc.endpoints { - endpoints = append(endpoints, &BaseEndpointInfo{Endpoint: ep.ip, ZoneHints: ep.zoneHints}) + endpoints = append(endpoints, &BaseEndpointInfo{Endpoint: ep.ip, ZoneHints: ep.zoneHints, Ready: !ep.unready}) } expectedEndpoints := []Endpoint{} for _, ep := range tc.expectedEndpoints { - expectedEndpoints = append(expectedEndpoints, &BaseEndpointInfo{Endpoint: ep.ip, ZoneHints: ep.zoneHints}) + expectedEndpoints = append(expectedEndpoints, &BaseEndpointInfo{Endpoint: ep.ip, ZoneHints: ep.zoneHints, Ready: !ep.unready}) } filteredEndpoints := filterEndpointsWithHints(endpoints, tc.hintsAnnotation, tc.nodeLabels)