@@ -214,22 +214,22 @@ func (l *ClusterL4EndpointsCalculator) CalculateEndpoints(eds []types.EndpointsD
214
214
}
215
215
l .logger .V (2 ).Info ("Got zoneNodeMap as input for service" , "zoneNodeMap" , nodeMapToString (zoneNodeMap ), "serviceID" , l .svcId )
216
216
217
- wanted := l .subsetSizeLimit
217
+ wanted := l .wantedInternalEndpointsCount ( len ( zoneNodeMap ))
218
218
if l .lbType == types .L4ExternalLB {
219
- wanted = l .wantedNEGsCount (eds , currentMap , len (zoneSubnetPairs ))
219
+ wanted = l .wantedExternalEndpointsCount (eds , currentMap , len (zoneSubnetPairs ))
220
220
}
221
221
222
222
subsetMap , err := getSubsetPerZone (zoneNodeMap , wanted , l .svcId , currentMap , l .logger , l .networkInfo )
223
223
return subsetMap , nil , 0 , err
224
224
}
225
225
226
- // wantedNEGsCount will determine the amount of NEGs that:
226
+ // wantedExternalEndpointsCount will determine the amount of endpoints that:
227
227
// * scales linearly based on the number of pods
228
- // * won't over provision NEGs over the nodes or pods count
229
- // * won't delete already existing NEGs , as that requires connection draining
230
- // * will provide at least 3 NEGs per zone/subnet pair
228
+ // * won't over provision endpoints over the nodes or pods count
229
+ // * won't delete already existing endpoints , as that requires connection draining
230
+ // * will provide at least 3 endpoints per zone/subnet pair
231
231
// * takes into account limits for passthrough NetLB and ILB
232
- func (l * ClusterL4EndpointsCalculator ) wantedNEGsCount (eds []types.EndpointsData , currentMap map [types.NEGLocation ]types.NetworkEndpointSet , zoneSubnetPairCount int ) int {
232
+ func (l * ClusterL4EndpointsCalculator ) wantedExternalEndpointsCount (eds []types.EndpointsData , currentMap map [types.NEGLocation ]types.NetworkEndpointSet , zoneSubnetPairCount int ) int {
233
233
// Compute the networkEndpoints, with total endpoints <= l.subsetSizeLimit.
234
234
optimal := linearEndpointsPerPods (zoneSubnetPairCount , edsLen (eds ), l .subsetSizeLimit )
235
235
@@ -242,6 +242,26 @@ func (l *ClusterL4EndpointsCalculator) wantedNEGsCount(eds []types.EndpointsData
242
242
return wanted
243
243
}
244
244
245
+ // wantedInternalEndpointsCount will determine the amount of endpoints that is divisible by the number of zones
246
+ // This should lead to improvements in the amount of connection draining that is done,
247
+ func (l * ClusterL4EndpointsCalculator ) wantedInternalEndpointsCount (zonesCount int ) int {
248
+ // | zones | endpoints per zone | total endpoints |
249
+ // | ----- | ------------------ | --------------- |
250
+ // | 1 | 24 | 24 |
251
+ // | 2 | 12 | 24 |
252
+ // | 3 | 8 | 24 |
253
+ // | 4 | 6 | 24 |
254
+ // | 5 | 5 | 25 |
255
+ // | 6 | 4 | 24 |
256
+ // | ----- | ------------------ | --------------- |
257
+ // Based on https://cloud.google.com/compute/docs/regions-zones#available
258
+ // There are no regions with more than 4 zones currently.
259
+ if zonesCount != 0 && 24 % zonesCount == 0 { // If there is some issue with zonesCount we don't want to divide by zero
260
+ return 24
261
+ }
262
+ return 25
263
+ }
264
+
245
265
func linearEndpointsPerPods (zoneSubnetPairCount , endpointsCount , subsetSizeLimit int ) int {
246
266
const minCountPerZoneSubnetPair = 3
247
267
lowerZonalBasedBound := zoneSubnetPairCount * minCountPerZoneSubnetPair
0 commit comments