johannes-engler-mw commented on PR #2703:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/2703#issuecomment-3902097660

   Thanks @AlinsRan for the feedback on making this behavior configurable. I've 
evaluated two approaches and would like to propose a **mode enum** 
configuration rather than a simple boolean toggle.
   
     ### Proposed: `listener_port_match_mode` (enum: `auto` | `explicit` | 
`off`)
   
     Instead of a binary on/off, a mode enum provides three distinct behaviors:
   
     | Mode | Behavior |
     |------|----------|
     | `auto` (default) | Inject `server_port` vars when route explicitly 
targets a listener (`sectionName` or `port`) **or** when multiple listener 
ports are matched. This is the current behavior and maintains backward 
compatibility. |
     | `explicit` | Inject `server_port` vars **only** when route explicitly 
targets a listener. No heuristic injection for multiple ports. |
     | `off` | Never inject `server_port` vars. Listener ports are treated as 
infrastructure-level metadata only. |
   
     ### Why enum over boolean?
   
     1. **Gateway API semantics**: The spec distinguishes between implicit 
attachment (route attaches to gateway, all listeners) and explicit targeting
     (route specifies `sectionName` or `port`). A boolean conflates these — 
`explicit` mode preserves this distinction while `off` provides the pure
     infrastructure semantics.
   
     2. **Avoids future breaking changes**: If we ship a boolean and later need 
the `explicit` behavior, we'd have to break the config schema or add a
     second field.
   
     3. **Minimal additional complexity**: The difference is essentially a 
`switch` statement, a type definition, and a validation check. The config
     wiring is nearly identical to a boolean approach.
   
     ### Behavior matrix
   
     | Scenario | `auto` | `explicit` | `off` |
     |----------|--------|------------|-------|
     | Explicit `sectionName` targeting | inject | inject | no injection 
(warning) |
     | Explicit `port` targeting | inject | inject | no injection (warning) |
     | Multiple listener ports, no explicit targeting | inject | no injection | 
no injection |
     | Single listener port, no explicit targeting | no injection | no 
injection | no injection |
   
     ### Config example
   
     ```yaml
     listener_port_match_mode: auto  # Options: auto, explicit, off. Default: 
auto.
    ```
   
     The default auto maintains full backward compatibility. Users who need 
infrastructure-only semantics can set off, and those who want only explicit 
intent-based injection can use explicit.
   
     Are you comfortable with this approach, or would you prefer the simpler 
boolean toggle (enable_listener_port_match: true/false)?
   
   BR,
   Johannes


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to