mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-18 04:54:54 +00:00
Merge pull request #132680 from milesbxf/topology-hints-dont-log-for-empty-endpointslices
Don't log irrelevant zone hints message on no endpoints
This commit is contained in:
@@ -42,6 +42,11 @@ import (
|
||||
// Serving-Terminating endpoints (independently for Cluster and Local) if no Ready
|
||||
// endpoints are available.
|
||||
func CategorizeEndpoints(endpoints []Endpoint, svcInfo ServicePort, nodeName string, nodeLabels map[string]string) (clusterEndpoints, localEndpoints, allReachableEndpoints []Endpoint, hasAnyEndpoints bool) {
|
||||
if len(endpoints) == 0 {
|
||||
// If there are no endpoints, we have nothing to categorize
|
||||
return
|
||||
}
|
||||
|
||||
var topologyMode string
|
||||
var useServingTerminatingEndpoints bool
|
||||
|
||||
@@ -153,6 +158,12 @@ 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 ""
|
||||
}
|
||||
|
||||
hasEndpointForNode := false
|
||||
allEndpointsHaveNodeHints := true
|
||||
hasEndpointForZone := false
|
||||
|
||||
@@ -390,6 +390,13 @@ func TestCategorizeEndpoints(t *testing.T) {
|
||||
clusterEndpoints: nil,
|
||||
localEndpoints: sets.New[string]("10.0.0.1:80"),
|
||||
allEndpoints: sets.New[string]("10.0.0.1:80"),
|
||||
}, {
|
||||
name: "empty endpoints when no service endpoints exist",
|
||||
serviceInfo: &BaseServicePortInfo{},
|
||||
endpoints: nil,
|
||||
clusterEndpoints: nil,
|
||||
localEndpoints: nil,
|
||||
allEndpoints: nil,
|
||||
}}
|
||||
|
||||
for _, tc := range testCases {
|
||||
@@ -398,7 +405,7 @@ func TestCategorizeEndpoints(t *testing.T) {
|
||||
|
||||
clusterEndpoints, localEndpoints, allEndpoints, hasAnyEndpoints := CategorizeEndpoints(tc.endpoints, tc.serviceInfo, tc.nodeName, tc.nodeLabels)
|
||||
|
||||
if tc.clusterEndpoints == nil && clusterEndpoints != nil {
|
||||
if len(tc.clusterEndpoints) == 0 && len(clusterEndpoints) != 0 {
|
||||
t.Errorf("expected no cluster endpoints but got %v", clusterEndpoints)
|
||||
} else {
|
||||
err := checkExpectedEndpoints(tc.clusterEndpoints, clusterEndpoints)
|
||||
@@ -407,7 +414,7 @@ func TestCategorizeEndpoints(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
if tc.localEndpoints == nil && localEndpoints != nil {
|
||||
if len(tc.localEndpoints) == 0 && len(localEndpoints) != 0 {
|
||||
t.Errorf("expected no local endpoints but got %v", localEndpoints)
|
||||
} else {
|
||||
err := checkExpectedEndpoints(tc.localEndpoints, localEndpoints)
|
||||
@@ -417,9 +424,9 @@ func TestCategorizeEndpoints(t *testing.T) {
|
||||
}
|
||||
|
||||
var expectedAllEndpoints sets.Set[string]
|
||||
if tc.clusterEndpoints != nil && tc.localEndpoints == nil {
|
||||
if len(tc.clusterEndpoints) != 0 && len(tc.localEndpoints) == 0 {
|
||||
expectedAllEndpoints = tc.clusterEndpoints
|
||||
} else if tc.localEndpoints != nil && tc.clusterEndpoints == nil {
|
||||
} else if len(tc.localEndpoints) != 0 && len(tc.clusterEndpoints) == 0 {
|
||||
expectedAllEndpoints = tc.localEndpoints
|
||||
} else {
|
||||
expectedAllEndpoints = tc.allEndpoints
|
||||
|
||||
Reference in New Issue
Block a user