Skip to content

Commit 8714e4d

Browse files
test: cover a route moving off a Gateway managed by this controller
Attaches an HTTPRoute to the additional gateway, then repoints its parentRefs at a Gateway whose GatewayClass names a different controller. The route object is never deleted, so this exercises the empty-gateway-list path in the reconciler rather than the deletion path. Fails before the fix: the additional gateway keeps returning 200 because the configuration pushed for the route is never removed from its data plane.
1 parent ad75001 commit 8714e4d

1 file changed

Lines changed: 96 additions & 0 deletions

File tree

test/e2e/gatewayapi/httproute.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,56 @@ spec:
251251
name: additional-proxy-config
252252
`
253253

254+
// GatewayClass owned by a different controller, plus a Gateway using it.
255+
// Moving a route onto this Gateway takes it out of the scope of the
256+
// controller under test without deleting the route itself.
257+
var foreignGatewayClassYaml = `
258+
apiVersion: gateway.networking.k8s.io/v1
259+
kind: GatewayClass
260+
metadata:
261+
name: %s
262+
spec:
263+
controllerName: "apisix.apache.org/not-exist"
264+
`
265+
266+
var foreignGateway = `
267+
apiVersion: gateway.networking.k8s.io/v1
268+
kind: Gateway
269+
metadata:
270+
name: foreign-gateway
271+
spec:
272+
gatewayClassName: %s
273+
listeners:
274+
- name: http-foreign
275+
protocol: HTTP
276+
port: 80
277+
allowedRoutes:
278+
namespaces:
279+
from: All
280+
`
281+
282+
// HTTPRoute with a single parent, whose name is filled in by the test.
283+
var singleParentHTTPRoute = `
284+
apiVersion: gateway.networking.k8s.io/v1
285+
kind: HTTPRoute
286+
metadata:
287+
name: moving-route
288+
spec:
289+
parentRefs:
290+
- name: %s
291+
namespace: %s
292+
hostnames:
293+
- httpbin-additional.example
294+
rules:
295+
- matches:
296+
- path:
297+
type: Exact
298+
value: /get
299+
backendRefs:
300+
- name: httpbin-service-e2e-test
301+
port: 80
302+
`
303+
254304
// HTTPRoute that references both gateways
255305
var multiGatewayHTTPRoute = `
256306
apiVersion: gateway.networking.k8s.io/v1
@@ -372,6 +422,52 @@ spec:
372422
Check: scaffold.WithExpectedStatus(http.StatusNotFound),
373423
})
374424
})
425+
426+
It("HTTPRoute should stop being served after moving to another controller's Gateway", func() {
427+
By("Create HTTPRoute on the additional gateway")
428+
s.ResourceApplied("HTTPRoute", "moving-route",
429+
fmt.Sprintf(singleParentHTTPRoute, "additional-gateway", additionalSvc.Namespace), 1)
430+
431+
client, err := s.NewAPISIXClientForGateway(additionalGatewayGroupID)
432+
Expect(err).NotTo(HaveOccurred(), "creating client for additional gateway")
433+
434+
By("HTTPRoute should be accessible through the additional gateway")
435+
s.RequestAssert(&scaffold.RequestAssert{
436+
Client: client,
437+
Method: "GET",
438+
Path: "/get",
439+
Host: "httpbin-additional.example",
440+
Check: scaffold.WithExpectedStatus(http.StatusOK),
441+
Timeout: time.Second * 30,
442+
Interval: time.Second * 2,
443+
})
444+
445+
By("Create a Gateway owned by another controller")
446+
foreignGatewayClassName := fmt.Sprintf("foreign-gatewayclass-%d", time.Now().Nanosecond())
447+
err = s.CreateResourceFromStringWithNamespace(
448+
fmt.Sprintf(foreignGatewayClassYaml, foreignGatewayClassName), "")
449+
Expect(err).NotTo(HaveOccurred(), "creating foreign GatewayClass")
450+
451+
err = s.CreateResourceFromStringWithNamespace(
452+
fmt.Sprintf(foreignGateway, foreignGatewayClassName), additionalSvc.Namespace)
453+
Expect(err).NotTo(HaveOccurred(), "creating foreign Gateway")
454+
455+
By("Move the HTTPRoute's parentRefs to that Gateway")
456+
err = s.CreateResourceFromString(
457+
fmt.Sprintf(singleParentHTTPRoute, "foreign-gateway", additionalSvc.Namespace))
458+
Expect(err).NotTo(HaveOccurred(), "moving HTTPRoute parentRefs")
459+
460+
By("HTTPRoute should no longer be accessible through the additional gateway")
461+
s.RequestAssert(&scaffold.RequestAssert{
462+
Client: client,
463+
Method: "GET",
464+
Path: "/get",
465+
Host: "httpbin-additional.example",
466+
Check: scaffold.WithExpectedStatus(http.StatusNotFound),
467+
Timeout: time.Second * 30,
468+
Interval: time.Second * 2,
469+
})
470+
})
375471
})
376472

377473
Context("HTTPRoute Base", func() {

0 commit comments

Comments
 (0)