Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Conformance Test Journal: HTTPRouteHostnameIntersection

## 1. Test Overview
- **Name**: `HTTPRouteHostnameIntersection`
- **Description**: Verifies that HTTPRoutes attach to listeners only if they have intersecting hostnames, and should accept requests only for the intersecting hostnames.
- **Manifests**: `sigs.k8s.io/gateway-api/conformance/tests/httproute-hostname-intersection.yaml` (v1.6.0)

## 2. Issue / Failure Analysis
- **Observed Behavior**: The test case `HTTPRoutes_have_to_be_counted_in_AttachedRoutes_only_if_they_are_Accepted` failed on AttachedRoutes count expectations. For example, it expected `AttachedRoutes` to be 2 for `listener-1` but got 4.
- **Root Cause**: When computing listener status and `AttachedRoutes` inside `pkg/controller/gateway_controller.go`, the controller only verified whether the route matched the Gateway Name/SectionName and was accepted overall (`route.IsAccepted(ControllerName)`). However, it did not verify if the route actually had intersecting hostnames with the specific listener's hostname. Consequently, a route with non-intersecting hostnames (that was accepted by one listener) was incorrectly counted as attached to *all* other listeners where the section name was empty or matched.

## 3. Implementation / Fix Strategy
- **Approach**:
1. Updated the route-to-listener attachment logic in `pkg/controller/gateway_controller.go` to compute parent namespace match and hostname intersection for each individual listener.
2. Verified that `state.IntersectHostnames(routeHostnames, listenerHostname)` returns a non-empty intersection (or the route defines no hostnames) before incrementing `AttachedRoutes` for that listener.
3. Enabled/uncommented the `tests.HTTPRouteHostnameIntersection` conformance test in `tests/e2e/conformance_test.go`.
- **Key Files Modified**:
- `pkg/controller/gateway_controller.go`
- `tests/e2e/conformance_test.go`

## 4. Validation & Results
- **Unit Tests**: Ran unit tests with `ap test` and confirmed all passed.
- **Conformance Logs**:
```
--- PASS: TestConformance (62.28s)
--- PASS: TestConformance/HTTPRouteHostnameIntersection (1.62s)
--- PASS: TestConformance/HTTPRouteHostnameIntersection/HTTPRoutes_that_do_intersect_with_listener_hostnames (0.01s)
--- PASS: TestConformance/HTTPRouteHostnameIntersection/HTTPRoutes_that_do_not_intersect_with_listener_hostnames (0.01s)
--- PASS: TestConformance/HTTPRouteHostnameIntersection/HTTPRoutes_have_to_be_counted_in_AttachedRoutes_only_if_they_are_Accepted (0.00s)
--- PASS: TestConformance/HTTPRouteHostnameIntersection/HTTPRoutes_intersects_with_an_unspecified_hostname_listener (0.16s)
PASS
ok github.com/gke-labs/gateway-api-reference-implementation/tests/e2e 62.302s
```
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.26.4
FROM golang:1.26.5

# Install git and other basics
RUN apt-get update && apt-get install -y git curl
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module github.com/gke-labs/gateway-api-reference-implementation

go 1.26.4

toolchain go1.26.5

require (
github.com/google/go-cmp v0.7.0
golang.org/x/net v0.56.0
Expand Down
2 changes: 1 addition & 1 deletion images/gari-controller/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.26.4 AS builder
FROM golang:1.26.5 AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
Expand Down
16 changes: 13 additions & 3 deletions pkg/controller/gateway_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,21 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
attachedRoutes := 0
for _, route := range routes {
for _, parentRef := range route.Spec.ParentRefs {
if string(parentRef.Name) == gw.Name {
parentNamespace := route.Namespace
if ns := state.ValueOf(parentRef.Namespace); ns != "" {
parentNamespace = string(ns)
}
if string(parentRef.Name) == gw.Name && parentNamespace == gw.Namespace {
if sn := state.ValueOf(parentRef.SectionName); sn == "" || string(sn) == string(listener.Name) {
if route.IsAccepted(ControllerName) {
attachedRoutes++
break
// Also check if the route actually intersects/matches this listener's hostname
routeHostnames := route.GetHostnames()
listenerHostname := state.ValueOf(listener.Hostname)
effectiveHostnames := state.IntersectHostnames(routeHostnames, string(listenerHostname))
if len(effectiveHostnames) > 0 || len(routeHostnames) == 0 {
attachedRoutes++
break
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ func TestConformance(t *testing.T) {
tests.HTTPRoutePathMatchOrder,
tests.HTTPRouteExactPathMatching,
tests.HTTPRouteMethodMatching, // Fails on HTTPRouteMethodMatching/11 with headers under v1.5.0
tests.HTTPRouteHeaderMatching, // Fails under v1.6.0
// tests.HTTPRouteHostnameIntersection, // Fails on AttachedRoutes count under v1.5.0
tests.HTTPRouteHeaderMatching,
tests.HTTPRouteHostnameIntersection,
// tests.HTTPRouteRewriteHost, // Fails on rewrite-host-and-modify-headers under v1.5.0
// tests.HTTPRouteRewritePath, // Fails on rewrite-path-and-modify-headers under v1.5.0
// tests.HTTPRouteInvalidBackendRefUnknownKind, // Fails under v1.6.0
Expand Down
2 changes: 1 addition & 1 deletion tests/toolbox/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.26.4 AS builder
FROM golang:1.26.5 AS builder
WORKDIR /app
COPY main.go .
RUN CGO_ENABLED=0 go build -o toolbox main.go
Expand Down
Loading