nginx-gateway-fabric
nginx-gateway-fabric copied to clipboard
Duplicated SectionName Expansion Logic
trafficstars
Describe the bug
The core issue lies in route_common.go:
- Section name refs are expanded once during the build phase (
buildSectionNameRefs) and then expanded again later when finding attachable listeners. - This double-expansion leads to inconsistent behavior and should be refactored so that section name refs are only expanded once, in a single, well-defined place.
Additional context
Several related inconsistencies appear to stem from this section name ref issue:
-
Policies handling (policies.go L463)
- The logic for merging listener hostnames with route hostnames does not properly handle wildcards.
AcceptedHostnamesis currently a map of slices of strings, but we need to flatten it.
-
ParentRefAttachmentStatus structure
type ParentRefAttachmentStatus struct { AcceptedHostnames map[string][]string FailedConditions []conditions.Condition ListenerPort v1.PortNumber Attached bool }ListenerPortis modeled as a single port, but a ParentRef can attach to multiple listeners, each with different ports.- This mismatch may cause incorrect or incomplete status reporting.
-
Refactoring difficulty
- The correct long-term solution would be to refactor
buildSectionNamelogic, but that risks undoing bug fix [#3400].
- The correct long-term solution would be to refactor
Summary
- Root issue: Section name ref expansion is happening in multiple places (build + attachment), causing inconsistencies.
- Side effects: Incorrect hostname merging, improperly structured
AcceptedHostnames, and overly simplifiedListenerPorthandling. - Next steps: A careful refactor of section name handling is needed, ideally consolidating expansion logic without regressing [#3400].