From 18f56fa7c72228e4590557e877ca79286b5ba10e Mon Sep 17 00:00:00 2001 From: ansilh Date: Wed, 4 Feb 2026 17:34:19 +0530 Subject: [PATCH 1/2] fix(kube-proxy): skip topology hints logging when no ready endpoints exist When all endpoints are non-ready (ready=false, serving=false, terminating=false), the topologyModeFromHints function was incorrectly logging "Ignoring same-zone topology hints for service since no hints were provided for zone" because the boolean flags remained at their initial values after the loop skipped all non-ready endpoints. This fix adds tracking for whether any ready endpoints were processed and returns early if none exist, avoiding misleading log messages. Also adds a test case covering this scenario. --- pkg/proxy/topology.go | 7 +++++++ pkg/proxy/topology_test.go | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/pkg/proxy/topology.go b/pkg/proxy/topology.go index c8b447971ed..9c7c7e9a258 100644 --- a/pkg/proxy/topology.go +++ b/pkg/proxy/topology.go @@ -168,6 +168,7 @@ func topologyModeFromHints(svcInfo ServicePort, endpoints []Endpoint, nodeName, return "" } + hasReadyEndpoints := false hasEndpointForNode := false allEndpointsHaveNodeHints := true hasEndpointForZone := false @@ -176,6 +177,7 @@ func topologyModeFromHints(svcInfo ServicePort, endpoints []Endpoint, nodeName, if !endpoint.IsReady() { continue } + hasReadyEndpoints = true if endpoint.NodeHints().Len() == 0 { allEndpointsHaveNodeHints = false @@ -190,6 +192,11 @@ func topologyModeFromHints(svcInfo ServicePort, endpoints []Endpoint, nodeName, } } + // If no ready endpoints exist, there are no hints to consider + if !hasReadyEndpoints { + return "" + } + if utilfeature.DefaultFeatureGate.Enabled(features.PreferSameTrafficDistribution) { if allEndpointsHaveNodeHints { if hasEndpointForNode { diff --git a/pkg/proxy/topology_test.go b/pkg/proxy/topology_test.go index 8e9ed4333d2..e15337a1732 100644 --- a/pkg/proxy/topology_test.go +++ b/pkg/proxy/topology_test.go @@ -398,6 +398,15 @@ func TestCategorizeEndpoints(t *testing.T) { clusterEndpoints: nil, localEndpoints: nil, allEndpoints: nil, + }, { + name: "single endpoint not ready, not serving, not terminating", + nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"}, + serviceInfo: &BaseServicePortInfo{}, + endpoints: []Endpoint{ + &BaseEndpointInfo{endpoint: "10.0.0.0:80", ready: false, serving: false, terminating: false}, + }, + clusterEndpoints: sets.New[string](), + localEndpoints: nil, }} for _, tc := range testCases { From 440cfca4ef722479d99904eb5c714563e7f8ebf1 Mon Sep 17 00:00:00 2001 From: ansilh Date: Fri, 6 Feb 2026 21:56:58 +0530 Subject: [PATCH 2/2] refactor(kube-proxy): remove redundant empty endpoints check in topologyModeFromHints The len(endpoints) == 0 check is now redundant since the hasReadyEndpoints check handles this case when the slice is empty, the loop executes zero times, hasReadyEndpoints stays false, and returns "" via the same path. --- pkg/proxy/topology.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pkg/proxy/topology.go b/pkg/proxy/topology.go index 9c7c7e9a258..48b2e541136 100644 --- a/pkg/proxy/topology.go +++ b/pkg/proxy/topology.go @@ -162,12 +162,6 @@ func CategorizeEndpoints(endpoints []Endpoint, svcInfo ServicePort, nodeName str // hinted for this node's zone, then it returns "PreferSameZone". // - Otherwise it returns "" (meaning, no topology / default traffic distribution). func topologyModeFromHints(svcInfo ServicePort, endpoints []Endpoint, nodeName, zone string) string { - if len(endpoints) == 0 { - // The code below assumes at least 1 endpoint; if there are no endpoints, - // there are no hints. - return "" - } - hasReadyEndpoints := false hasEndpointForNode := false allEndpointsHaveNodeHints := true