fix(helpers): make backendRef port optional in HTTPRoute rules - #603
Conversation
|
Thank you for your contribution @alex1989hu, please review my comment: The new test case is not valid according to the Gateway API specification. It defines: backendRefs:
- name: example-serviceBecause neither The chart does support explicit non-Service backends through the As written, the PR allows an invalid Service backendRef to render successfully. I think the test should continue to require a port for the default Service case. Port omission should only be accepted when |
|
Do I understand correctly that you'd like to enforce the |
|
@alex1989hu I feel like it's the more correct thing to do, what do you think? |
I'm okay with that change. I've just pushed a commit 5f9dd47 , could you please take a look? |
|
Thanks, the Service/default-kind case is now handled correctly. One remaining issue: Could we use Then use The |
5f9dd47 to
8a06504
Compare
Good catch, thank you! I copied your proposal and added two tests in 8a06504 |
8a06504 to
36ce852
Compare
The HTTPRoute backendRefs template required .port on every backendRef and failed the render if it was missing, but per the Gateway API spec port is optional on BackendRef Only validate and render port when it is actually set, leaving it out of the manifest entirely when omitted. Signed-off-by: Alex Szakaly <alex.szakaly@gmail.com>
…te rules The previous fix made port fully optional on every HTTPRoute backendRef, but per the Gateway API spec port is only optional when kind is not Service. Port is required when kind is omitted (defaults to Service) or set explicitly to Service. Fail the render with a clear error when port is missing on a Service backendRef, and keep port optional for any other kind. Signed-off-by: Alex Szakaly <alex.szakaly@gmail.com>
Port was checked for truthiness, so port: 0 was wrongly treated as omitted Signed-off-by: Alex Szakaly <alex.szakaly@gmail.com>
161b6d7 to
235c0ad
Compare
|
Thanks for the fix @alex1989hu! I pushed a few additions on top of your commits before merging:
Also rebased onto main. Merged, thanks again for the contribution! |
The HTTPRoute backendRefs template required
.porton every backendRef and failed the render if it was missing, but per the Gateway API spec port is optional on aBackendRefin general. It is only required when the referent is a core Kubernetes Service.What changed
portis validated and rendered only when it is actually set, and left out of the manifest entirely when omitted (e.g. forkind: ServiceImportbackends).portwhen the referent is a core Kubernetes Service (group: ""andkind: Service, the default) still fails the render, now with an explicit message:backendRef "<name>": port is required when the referent is a Kubernetes Service.port: '{{ .Values.optionalPort }}'with the value unset) is treated as unset, so the optionality also works with template expressions.portdocumentation invalues.yaml, README, andvalues.schema.jsonnow states when the field may be omitted.Note on the issue repro
The exact reproduction in #602 (no port, kind defaulting to Service) still fails by design, because the Gateway API spec requires port for Service referents and the HTTPRoute CRD would reject the manifest anyway. The difference is that the failure message now explains the actual constraint instead of
Invalid port value: 0. Backends of any other kind render without a port as the issue expects.Tests
Unit tests cover: port omitted for a non-Service kind (rendered without port), port omitted for a Service (explicit failure), empty templated port for both cases, out-of-range and explicit-zero ports, mixed rules where only some backendRefs have a port, and a Service in a non-core group (port optional).
Closes #602