@@ -211,6 +211,177 @@ spec:
211211 })
212212 })
213213
214+ Context ("HTTPRoute with Multiple Gateway" , func () {
215+ var additionalGatewayGroupID string
216+ var additionalNamespace string
217+
218+ var additionalGatewayProxyYaml = `
219+ apiVersion: gateway.apisix.io/v1alpha1
220+ kind: GatewayProxy
221+ metadata:
222+ name: additional-proxy-config
223+ spec:
224+ provider:
225+ type: ControlPlane
226+ controlPlane:
227+ endpoints:
228+ - %s
229+ auth:
230+ type: AdminKey
231+ adminKey:
232+ value: "%s"
233+ `
234+
235+ var additionalGateway = `
236+ apiVersion: gateway.networking.k8s.io/v1
237+ kind: Gateway
238+ metadata:
239+ name: additional-gateway
240+ spec:
241+ gatewayClassName: %s
242+ listeners:
243+ - name: http-additional
244+ protocol: HTTP
245+ port: 80
246+ allowedRoutes:
247+ namespaces:
248+ from: All
249+ infrastructure:
250+ parametersRef:
251+ group: gateway.apisix.io
252+ kind: GatewayProxy
253+ name: additional-proxy-config
254+ `
255+
256+ // HTTPRoute that references both gateways
257+ var multiGatewayHTTPRoute = `
258+ apiVersion: gateway.networking.k8s.io/v1
259+ kind: HTTPRoute
260+ metadata:
261+ name: multi-gateway-route
262+ spec:
263+ parentRefs:
264+ - name: api7ee
265+ namespace: %s
266+ - name: additional-gateway
267+ namespace: %s
268+ hostnames:
269+ - httpbin.example
270+ - httpbin-additional.example
271+ rules:
272+ - matches:
273+ - path:
274+ type: Exact
275+ value: /get
276+ backendRefs:
277+ - name: httpbin-service-e2e-test
278+ port: 80
279+ `
280+
281+ var gatewayClassName string
282+
283+ BeforeEach (func () {
284+ By ("Create GatewayProxy" )
285+ gatewayProxy := fmt .Sprintf (gatewayProxyYaml , framework .DashboardTLSEndpoint , s .AdminKey ())
286+ err := s .CreateResourceFromString (gatewayProxy )
287+ Expect (err ).NotTo (HaveOccurred (), "creating GatewayProxy" )
288+ time .Sleep (5 * time .Second )
289+
290+ By ("create GatewayClass" )
291+ gatewayClassName = fmt .Sprintf ("api7-%d" , time .Now ().Unix ())
292+ err = s .CreateResourceFromStringWithNamespace (fmt .Sprintf (defautlGatewayClass , gatewayClassName , s .GetControllerName ()), "" )
293+ Expect (err ).NotTo (HaveOccurred (), "creating GatewayClass" )
294+ time .Sleep (5 * time .Second )
295+
296+ By ("check GatewayClass condition" )
297+ gcyaml , err := s .GetResourceYaml ("GatewayClass" , gatewayClassName )
298+ Expect (err ).NotTo (HaveOccurred (), "getting GatewayClass yaml" )
299+ Expect (gcyaml ).To (ContainSubstring (`status: "True"` ), "checking GatewayClass condition status" )
300+ Expect (gcyaml ).To (ContainSubstring ("message: the gatewayclass has been accepted by the api7-ingress-controller" ), "checking GatewayClass condition message" )
301+
302+ By ("create Gateway" )
303+ err = s .CreateResourceFromString (fmt .Sprintf (defautlGateway , gatewayClassName ))
304+ Expect (err ).NotTo (HaveOccurred (), "creating Gateway" )
305+ time .Sleep (5 * time .Second )
306+
307+ By ("check Gateway condition" )
308+ gwyaml , err := s .GetResourceYaml ("Gateway" , "api7ee" )
309+ Expect (err ).NotTo (HaveOccurred (), "getting Gateway yaml" )
310+ Expect (gwyaml ).To (ContainSubstring (`status: "True"` ), "checking Gateway condition status" )
311+ Expect (gwyaml ).To (ContainSubstring ("message: the gateway has been accepted by the api7-ingress-controller" ), "checking Gateway condition message" )
312+
313+ By ("Create additional gateway group" )
314+ additionalGatewayGroupID , additionalNamespace , err = s .CreateAdditionalGatewayGroup ("multi-gw" )
315+ Expect (err ).NotTo (HaveOccurred (), "creating additional gateway group" )
316+
317+ By ("Initialize dataplane client for additional gateway group" )
318+ err = s .InitializeDataplaneClientForGatewayGroup (additionalGatewayGroupID )
319+ Expect (err ).NotTo (HaveOccurred (), "initializing dataplane client" )
320+
321+ By ("Create additional GatewayProxy" )
322+ // Get admin key for the additional gateway group
323+ resources , exists := s .GetAdditionalGatewayGroup (additionalGatewayGroupID )
324+ Expect (exists ).To (BeTrue (), "additional gateway group should exist" )
325+
326+ additionalGatewayProxy := fmt .Sprintf (additionalGatewayProxyYaml , framework .DashboardTLSEndpoint , resources .AdminAPIKey )
327+ err = s .CreateResourceFromStringWithNamespace (additionalGatewayProxy , additionalNamespace )
328+ Expect (err ).NotTo (HaveOccurred (), "creating additional GatewayProxy" )
329+
330+ By ("Create additional Gateway" )
331+ err = s .CreateResourceFromStringWithNamespace (
332+ fmt .Sprintf (additionalGateway , gatewayClassName ),
333+ additionalNamespace ,
334+ )
335+ Expect (err ).NotTo (HaveOccurred (), "creating additional Gateway" )
336+ time .Sleep (5 * time .Second )
337+ })
338+
339+ It ("HTTPRoute should be accessible through both gateways" , func () {
340+ By ("Create HTTPRoute referencing both gateways" )
341+ multiGatewayRoute := fmt .Sprintf (multiGatewayHTTPRoute , s .Namespace (), additionalNamespace )
342+ ResourceApplied ("HTTPRoute" , "multi-gateway-route" , multiGatewayRoute , 1 )
343+
344+ By ("Access through default gateway" )
345+ s .NewAPISIXClient ().
346+ GET ("/get" ).
347+ WithHost ("httpbin.example" ).
348+ Expect ().
349+ Status (http .StatusOK )
350+
351+ By ("Access through additional gateway" )
352+ client , err := s .NewAPISIXClientForGatewayGroup (additionalGatewayGroupID )
353+ Expect (err ).NotTo (HaveOccurred (), "creating client for additional gateway" )
354+
355+ client .
356+ GET ("/get" ).
357+ WithHost ("httpbin-additional.example" ).
358+ Expect ().
359+ Status (http .StatusOK )
360+
361+ By ("Delete Additional Gateway" )
362+ err = s .DeleteResourceFromStringWithNamespace (fmt .Sprintf (additionalGateway , gatewayClassName ), additionalNamespace )
363+ Expect (err ).NotTo (HaveOccurred (), "deleting additional Gateway" )
364+ time .Sleep (5 * time .Second )
365+
366+ By ("HTTPRoute should still be accessible through default gateway" )
367+ s .NewAPISIXClient ().
368+ GET ("/get" ).
369+ WithHost ("httpbin.example" ).
370+ Expect ().
371+ Status (http .StatusOK )
372+
373+ By ("HTTPRoute should not be accessible through additional gateway" )
374+ client , err = s .NewAPISIXClientForGatewayGroup (additionalGatewayGroupID )
375+ Expect (err ).NotTo (HaveOccurred (), "creating client for additional gateway" )
376+
377+ client .
378+ GET ("/get" ).
379+ WithHost ("httpbin-additional.example" ).
380+ Expect ().
381+ Status (http .StatusNotFound )
382+ })
383+ })
384+
214385 Context ("HTTPRoute Base" , func () {
215386 var exactRouteByGet = `
216387apiVersion: gateway.networking.k8s.io/v1
0 commit comments