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.
This commit is contained in:
ansilh
2026-02-04 17:34:19 +05:30
parent 0cf6c382a0
commit 18f56fa7c7
2 changed files with 16 additions and 0 deletions

View File

@@ -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 {

View File

@@ -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 {