@@ -47,13 +47,12 @@ func checkExpectedEndpoints(expected sets.Set[string], actual []Endpoint) error
47
47
48
48
func TestCategorizeEndpoints (t * testing.T ) {
49
49
testCases := []struct {
50
- name string
51
- hintsEnabled bool
52
- trafficDistFeatureEnabled bool
53
- pteEnabled bool
54
- nodeLabels map [string ]string
55
- serviceInfo ServicePort
56
- endpoints []Endpoint
50
+ name string
51
+ hintsEnabled bool
52
+ pteEnabled bool
53
+ nodeLabels map [string ]string
54
+ serviceInfo ServicePort
55
+ endpoints []Endpoint
57
56
58
57
// We distinguish `nil` ("service doesn't use this kind of endpoints") from
59
58
// `sets.Set[string]()` ("service uses this kind of endpoints but has no endpoints").
@@ -79,7 +78,7 @@ func TestCategorizeEndpoints(t *testing.T) {
79
78
clusterEndpoints : sets .New [string ]("10.1.2.3:80" , "10.1.2.6:80" ),
80
79
localEndpoints : nil ,
81
80
}, {
82
- name : "hints, hints annotation == disabled, hints ignored" ,
81
+ name : "hints, hints annotation == disabled, but endpointslice hints are not ignored since trafficDist feature-gate is always enabled by default " ,
83
82
hintsEnabled : true ,
84
83
nodeLabels : map [string ]string {v1 .LabelTopologyZone : "zone-a" },
85
84
serviceInfo : & BaseServicePortInfo {hintsAnnotation : "disabled" },
@@ -89,20 +88,7 @@ func TestCategorizeEndpoints(t *testing.T) {
89
88
& BaseEndpointInfo {endpoint : "10.1.2.5:80" , zoneHints : sets.New [string ]("zone-c" ), ready : true },
90
89
& BaseEndpointInfo {endpoint : "10.1.2.6:80" , zoneHints : sets.New [string ]("zone-a" ), ready : true },
91
90
},
92
- clusterEndpoints : sets .New [string ]("10.1.2.3:80" , "10.1.2.4:80" , "10.1.2.5:80" , "10.1.2.6:80" ),
93
- localEndpoints : nil ,
94
- }, {
95
- name : "hints disabled, hints annotation == auto" ,
96
- hintsEnabled : false ,
97
- nodeLabels : map [string ]string {v1 .LabelTopologyZone : "zone-a" },
98
- serviceInfo : & BaseServicePortInfo {hintsAnnotation : "auto" },
99
- endpoints : []Endpoint {
100
- & BaseEndpointInfo {endpoint : "10.1.2.3:80" , zoneHints : sets.New [string ]("zone-a" ), ready : true },
101
- & BaseEndpointInfo {endpoint : "10.1.2.4:80" , zoneHints : sets.New [string ]("zone-b" ), ready : true },
102
- & BaseEndpointInfo {endpoint : "10.1.2.5:80" , zoneHints : sets.New [string ]("zone-c" ), ready : true },
103
- & BaseEndpointInfo {endpoint : "10.1.2.6:80" , zoneHints : sets.New [string ]("zone-a" ), ready : true },
104
- },
105
- clusterEndpoints : sets .New [string ]("10.1.2.3:80" , "10.1.2.4:80" , "10.1.2.5:80" , "10.1.2.6:80" ),
91
+ clusterEndpoints : sets .New [string ]("10.1.2.3:80" , "10.1.2.6:80" ),
106
92
localEndpoints : nil ,
107
93
}, {
108
94
@@ -119,24 +105,10 @@ func TestCategorizeEndpoints(t *testing.T) {
119
105
clusterEndpoints : sets .New [string ]("10.1.2.3:80" , "10.1.2.6:80" ),
120
106
localEndpoints : nil ,
121
107
}, {
122
- name : "hints, hints annotation empty, hints ignored" ,
108
+ name : "hints, hints annotation empty but endpointslice hints are not ignored since trafficDist feature-gate is always enabled by default " ,
123
109
hintsEnabled : true ,
124
110
nodeLabels : map [string ]string {v1 .LabelTopologyZone : "zone-a" },
125
- serviceInfo : & BaseServicePortInfo {},
126
- endpoints : []Endpoint {
127
- & BaseEndpointInfo {endpoint : "10.1.2.3:80" , zoneHints : sets.New [string ]("zone-a" ), ready : true },
128
- & BaseEndpointInfo {endpoint : "10.1.2.4:80" , zoneHints : sets.New [string ]("zone-b" ), ready : true },
129
- & BaseEndpointInfo {endpoint : "10.1.2.5:80" , zoneHints : sets.New [string ]("zone-c" ), ready : true },
130
- & BaseEndpointInfo {endpoint : "10.1.2.6:80" , zoneHints : sets.New [string ]("zone-a" ), ready : true },
131
- },
132
- clusterEndpoints : sets .New [string ]("10.1.2.3:80" , "10.1.2.4:80" , "10.1.2.5:80" , "10.1.2.6:80" ),
133
- localEndpoints : nil ,
134
- }, {
135
- name : "hints, hints annotation empty but trafficDist feature gate enabled, hints are not ignored" ,
136
- hintsEnabled : true ,
137
- trafficDistFeatureEnabled : true ,
138
- nodeLabels : map [string ]string {v1 .LabelTopologyZone : "zone-a" },
139
- serviceInfo : & BaseServicePortInfo {},
111
+ serviceInfo : & BaseServicePortInfo { /* hints annotation empty */ },
140
112
endpoints : []Endpoint {
141
113
& BaseEndpointInfo {endpoint : "10.1.2.3:80" , zoneHints : sets.New [string ]("zone-a" ), ready : true },
142
114
& BaseEndpointInfo {endpoint : "10.1.2.4:80" , zoneHints : sets.New [string ]("zone-b" ), ready : true },
@@ -146,11 +118,10 @@ func TestCategorizeEndpoints(t *testing.T) {
146
118
clusterEndpoints : sets .New [string ]("10.1.2.3:80" , "10.1.2.6:80" ),
147
119
localEndpoints : nil ,
148
120
}, {
149
- name : "hints disabled, trafficDist feature gate enabled, hints are not ignored" ,
150
- hintsEnabled : false ,
151
- trafficDistFeatureEnabled : true ,
152
- nodeLabels : map [string ]string {v1 .LabelTopologyZone : "zone-a" },
153
- serviceInfo : & BaseServicePortInfo {},
121
+ name : "hints feature-gate disabled but endpointslice hints are not ignored since trafficDist feature-gate is always enabled by default" ,
122
+ hintsEnabled : false ,
123
+ nodeLabels : map [string ]string {v1 .LabelTopologyZone : "zone-a" },
124
+ serviceInfo : & BaseServicePortInfo {},
154
125
endpoints : []Endpoint {
155
126
& BaseEndpointInfo {endpoint : "10.1.2.3:80" , zoneHints : sets.New [string ]("zone-a" ), ready : true },
156
127
& BaseEndpointInfo {endpoint : "10.1.2.4:80" , zoneHints : sets.New [string ]("zone-b" ), ready : true },
@@ -160,11 +131,10 @@ func TestCategorizeEndpoints(t *testing.T) {
160
131
clusterEndpoints : sets .New [string ]("10.1.2.3:80" , "10.1.2.6:80" ),
161
132
localEndpoints : nil ,
162
133
}, {
163
- name : "externalTrafficPolicy: Local, topology ignored for Local endpoints" ,
164
- hintsEnabled : true ,
165
- trafficDistFeatureEnabled : true ,
166
- nodeLabels : map [string ]string {v1 .LabelTopologyZone : "zone-a" },
167
- serviceInfo : & BaseServicePortInfo {externalPolicyLocal : true , nodePort : 8080 , hintsAnnotation : "auto" },
134
+ name : "externalTrafficPolicy: Local, topology ignored for Local endpoints" ,
135
+ hintsEnabled : true ,
136
+ nodeLabels : map [string ]string {v1 .LabelTopologyZone : "zone-a" },
137
+ serviceInfo : & BaseServicePortInfo {externalPolicyLocal : true , nodePort : 8080 , hintsAnnotation : "auto" },
168
138
endpoints : []Endpoint {
169
139
& BaseEndpointInfo {endpoint : "10.1.2.3:80" , zoneHints : sets.New [string ]("zone-a" ), ready : true , isLocal : true },
170
140
& BaseEndpointInfo {endpoint : "10.1.2.4:80" , zoneHints : sets.New [string ]("zone-b" ), ready : true , isLocal : true },
@@ -175,11 +145,10 @@ func TestCategorizeEndpoints(t *testing.T) {
175
145
localEndpoints : sets .New [string ]("10.1.2.3:80" , "10.1.2.4:80" ),
176
146
allEndpoints : sets .New [string ]("10.1.2.3:80" , "10.1.2.4:80" , "10.1.2.6:80" ),
177
147
}, {
178
- name : "internalTrafficPolicy: Local, topology ignored for Local endpoints" ,
179
- hintsEnabled : true ,
180
- trafficDistFeatureEnabled : true ,
181
- nodeLabels : map [string ]string {v1 .LabelTopologyZone : "zone-a" },
182
- serviceInfo : & BaseServicePortInfo {internalPolicyLocal : true , hintsAnnotation : "auto" , externalPolicyLocal : false , nodePort : 8080 },
148
+ name : "internalTrafficPolicy: Local, topology ignored for Local endpoints" ,
149
+ hintsEnabled : true ,
150
+ nodeLabels : map [string ]string {v1 .LabelTopologyZone : "zone-a" },
151
+ serviceInfo : & BaseServicePortInfo {internalPolicyLocal : true , hintsAnnotation : "auto" , externalPolicyLocal : false , nodePort : 8080 },
183
152
endpoints : []Endpoint {
184
153
& BaseEndpointInfo {endpoint : "10.1.2.3:80" , zoneHints : sets.New [string ]("zone-a" ), ready : true , isLocal : true },
185
154
& BaseEndpointInfo {endpoint : "10.1.2.4:80" , zoneHints : sets.New [string ]("zone-b" ), ready : true , isLocal : true },
@@ -271,32 +240,6 @@ func TestCategorizeEndpoints(t *testing.T) {
271
240
},
272
241
clusterEndpoints : sets .New [string ]("10.1.2.3:80" , "10.1.2.6:80" ),
273
242
localEndpoints : nil ,
274
- }, {
275
- name : "hintsAnnotation empty, no filtering applied" ,
276
- hintsEnabled : true ,
277
- nodeLabels : map [string ]string {v1 .LabelTopologyZone : "zone-a" },
278
- serviceInfo : & BaseServicePortInfo {hintsAnnotation : "" },
279
- endpoints : []Endpoint {
280
- & BaseEndpointInfo {endpoint : "10.1.2.3:80" , zoneHints : sets.New [string ]("zone-a" ), ready : true },
281
- & BaseEndpointInfo {endpoint : "10.1.2.4:80" , zoneHints : sets.New [string ]("zone-b" ), ready : true },
282
- & BaseEndpointInfo {endpoint : "10.1.2.5:80" , zoneHints : sets.New [string ]("zone-c" ), ready : true },
283
- & BaseEndpointInfo {endpoint : "10.1.2.6:80" , zoneHints : sets.New [string ]("zone-a" ), ready : true },
284
- },
285
- clusterEndpoints : sets .New [string ]("10.1.2.3:80" , "10.1.2.4:80" , "10.1.2.5:80" , "10.1.2.6:80" ),
286
- localEndpoints : nil ,
287
- }, {
288
- name : "hintsAnnotation disabled, no filtering applied" ,
289
- hintsEnabled : true ,
290
- nodeLabels : map [string ]string {v1 .LabelTopologyZone : "zone-a" },
291
- serviceInfo : & BaseServicePortInfo {hintsAnnotation : "disabled" },
292
- endpoints : []Endpoint {
293
- & BaseEndpointInfo {endpoint : "10.1.2.3:80" , zoneHints : sets.New [string ]("zone-a" ), ready : true },
294
- & BaseEndpointInfo {endpoint : "10.1.2.4:80" , zoneHints : sets.New [string ]("zone-b" ), ready : true },
295
- & BaseEndpointInfo {endpoint : "10.1.2.5:80" , zoneHints : sets.New [string ]("zone-c" ), ready : true },
296
- & BaseEndpointInfo {endpoint : "10.1.2.6:80" , zoneHints : sets.New [string ]("zone-a" ), ready : true },
297
- },
298
- clusterEndpoints : sets .New [string ]("10.1.2.3:80" , "10.1.2.4:80" , "10.1.2.5:80" , "10.1.2.6:80" ),
299
- localEndpoints : nil ,
300
243
}, {
301
244
name : "missing hints, no filtering applied" ,
302
245
hintsEnabled : true ,
@@ -489,7 +432,6 @@ func TestCategorizeEndpoints(t *testing.T) {
489
432
for _ , tc := range testCases {
490
433
t .Run (tc .name , func (t * testing.T ) {
491
434
featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .TopologyAwareHints , tc .hintsEnabled )
492
- featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .ServiceTrafficDistribution , tc .trafficDistFeatureEnabled )
493
435
494
436
clusterEndpoints , localEndpoints , allEndpoints , hasAnyEndpoints := CategorizeEndpoints (tc .endpoints , tc .serviceInfo , tc .nodeLabels )
495
437
0 commit comments