Skip to content

Commit 69a72d3

Browse files
committed
Remove some comments and update array capacity calculation
1 parent 7400fe0 commit 69a72d3

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

internal/controller/nginx/config/generator.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,6 @@ func (g GeneratorImpl) executeConfigTemplates(
173173
}
174174
}
175175

176-
// for fp, bytes := range fileBytes {
177-
// fmt.Println("Generated NGINX configuration file: " + fp)
178-
// fmt.Println(string(bytes))
179-
// }
180-
181176
var mgmtFiles []agent.File
182177
if g.plus {
183178
mgmtFiles = g.generateMgmtFiles(conf)

internal/controller/nginx/config/servers.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,6 @@ func createLocations(
487487
locs = append(locs, createDefaultRootLocation())
488488
}
489489

490-
// fmt.Println("These are all the locations", locs)
491-
492490
return locs, matchPairs, grpcServer
493491
}
494492

@@ -521,7 +519,22 @@ func createInternalLocationsForRule(
521519
keepAliveCheck keepAliveChecker,
522520
mirrorPercentage *float64,
523521
) ([]http.Location, []routeMatch) {
524-
internalLocations := make([]http.Location, 0, len(rule.MatchRules))
522+
// Calculate the exact capacity needed
523+
capacity := 0
524+
for _, r := range rule.MatchRules {
525+
if !rule.HasInferenceBackends {
526+
capacity++ // intLocation (always created for non-inference)
527+
} else {
528+
// For inference backends with matches
529+
if len(r.BackendGroup.Backends) > 1 {
530+
capacity++ // intSplitClientsLocation (created for multiple backends)
531+
}
532+
533+
capacity += len(r.BackendGroup.Backends) * 2 // intEPPLocation and intProxyPassLocation per backend
534+
}
535+
}
536+
537+
internalLocations := make([]http.Location, 0, capacity)
525538
matches := make([]routeMatch, 0, len(rule.MatchRules))
526539
for matchRuleIdx, r := range rule.MatchRules {
527540
var intLocation http.Location

internal/controller/nginx/config/servers_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,7 +2449,6 @@ func TestCreateLocations_InferenceBackends(t *testing.T) {
24492449

24502450
hrNsName := types.NamespacedName{Namespace: "test", Name: "route1"}
24512451

2452-
// Reusable backend definitions
24532452
singleInferenceBackend := dataplane.Backend{
24542453
UpstreamName: "test_foo_80",
24552454
Valid: true,
@@ -2528,7 +2527,6 @@ func TestCreateLocations_InferenceBackends(t *testing.T) {
25282527
},
25292528
}
25302529

2531-
// Reusable backend groups
25322530
singleInferenceGroup := dataplane.BackendGroup{
25332531
Source: hrNsName,
25342532
RuleIdx: 0,
@@ -2553,7 +2551,6 @@ func TestCreateLocations_InferenceBackends(t *testing.T) {
25532551
Backends: []dataplane.Backend{multiMatchPrimaryBackend, multiMatchSecondaryBackend},
25542552
}
25552553

2556-
// Reusable path rules
25572554
pathRuleInferenceOnly := dataplane.PathRule{
25582555
Path: "/inference",
25592556
PathType: dataplane.PathTypeExact,

0 commit comments

Comments
 (0)