Skip to content

Commit 58c4a23

Browse files
committed
Fix style comments
1 parent 7ae3474 commit 58c4a23

File tree

3 files changed

+23
-36
lines changed

3 files changed

+23
-36
lines changed

internal/controller/state/graph/graph_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ func TestBuildGraph(t *testing.T) {
795795
): {"fizz.example.org"},
796796
},
797797
},
798-
SectionName: nil, // No expansion - represents attachment to all listeners
798+
SectionName: nil, // represents attachment to all listeners
799799
},
800800
},
801801
Spec: L4RouteSpec{

internal/controller/state/graph/policies.go

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ func checkForRouteOverlap(route *L7Route, hostPortPaths map[string]string) *cond
462462
port := parentRef.Attachment.ListenerPort
463463
for _, hostnames := range parentRef.Attachment.AcceptedHostnames {
464464
mergedHostnames := getMergedHostnames(route, hostnames)
465-
if cond := checkHostnamesOverlap(route, mergedHostnames, port, hostPortPaths); cond != nil {
465+
if cond := checkURIsOverlap(route, mergedHostnames, port, hostPortPaths); cond != nil {
466466
return cond
467467
}
468468
}
@@ -483,47 +483,36 @@ func getMergedHostnames(route *L7Route, hostnames []string) []string {
483483
}
484484

485485
func getHostnameMatches(hostname string, routeHostnames []v1.Hostname) []string {
486-
foundExactMatch := false
487486
moreSpecificHostnames := make([]string, 0)
488487

489488
for _, h := range routeHostnames {
490489
if hostname == string(h) {
491-
foundExactMatch = true
492-
break
490+
return []string{hostname}
493491
}
494-
if Match(hostname, string(h)) {
492+
if match(hostname, string(h)) {
495493
moreSpecificHostnames = append(moreSpecificHostnames, GetMoreSpecificHostname(hostname, string(h)))
496494
}
497495
}
498496

499-
if foundExactMatch {
500-
return []string{hostname}
501-
}
502497
return moreSpecificHostnames
503498
}
504499

505-
func checkHostnamesOverlap(
506-
route *L7Route, hostnames []string, port v1.PortNumber, hostPortPaths map[string]string,
500+
func checkURIsOverlap(
501+
route *L7Route,
502+
hostnames []string,
503+
port v1.PortNumber,
504+
hostPortPaths map[string]string,
507505
) *conditions.Condition {
508506
for _, hostname := range hostnames {
509-
if cond := checkHostnamePathsOverlap(route, hostname, port, hostPortPaths); cond != nil {
510-
return cond
511-
}
512-
}
513-
return nil
514-
}
515-
516-
func checkHostnamePathsOverlap(
517-
route *L7Route, hostname string, port v1.PortNumber, hostPortPaths map[string]string,
518-
) *conditions.Condition {
519-
for _, rule := range route.Spec.Rules {
520-
for _, match := range rule.Matches {
521-
if match.Path != nil && match.Path.Value != nil {
522-
key := fmt.Sprintf("%s:%d%s", hostname, port, *match.Path.Value)
523-
if val, ok := hostPortPaths[key]; !ok {
524-
hostPortPaths[key] = fmt.Sprintf("%s/%s", route.Source.GetNamespace(), route.Source.GetName())
525-
} else {
526-
return createTargetConflictCondition(route, val)
507+
for _, rule := range route.Spec.Rules {
508+
for _, match := range rule.Matches {
509+
if match.Path != nil && match.Path.Value != nil {
510+
key := fmt.Sprintf("%s:%d%s", hostname, port, *match.Path.Value)
511+
if val, ok := hostPortPaths[key]; !ok {
512+
hostPortPaths[key] = fmt.Sprintf("%s/%s", route.Source.GetNamespace(), route.Source.GetName())
513+
} else {
514+
return createTargetConflictCondition(route, val)
515+
}
527516
}
528517
}
529518
}

internal/controller/state/graph/route_common.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,10 @@ func buildSectionNameRefs(
318318
}
319319
}
320320

321-
// Create a single parentRef without expansion
322321
sectionNameRefs = append(sectionNameRefs, ParentRef{
323-
Idx: i,
324-
Gateway: CreateParentRefGateway(gw),
325-
SectionName: nil, // Keep as nil to indicate attachment to multiple listeners
326-
Port: p.Port,
322+
Idx: i,
323+
Gateway: CreateParentRefGateway(gw),
324+
Port: p.Port,
327325
})
328326

329327
continue
@@ -926,15 +924,15 @@ func findAcceptedHostnames(listenerHostname *v1.Hostname, routeHostnames []v1.Ho
926924

927925
for _, h := range routeHostnames {
928926
routeHost := string(h)
929-
if Match(hostname, routeHost) {
927+
if match(hostname, routeHost) {
930928
result = append(result, GetMoreSpecificHostname(hostname, routeHost))
931929
}
932930
}
933931

934932
return result
935933
}
936934

937-
func Match(listenerHost, routeHost string) bool {
935+
func match(listenerHost, routeHost string) bool {
938936
if listenerHost == "" {
939937
return true
940938
}

0 commit comments

Comments
 (0)