3333 value: "%s"
3434`
3535
36- var defautlGatewayClass = `
36+ var gatewayClassYaml = `
3737apiVersion: gateway.networking.k8s.io/v1
3838kind: GatewayClass
3939metadata:
4242 controllerName: %s
4343`
4444
45- var defautlGateway = `
45+ var defaultGateway = `
4646apiVersion: gateway.networking.k8s.io/v1
4747kind: Gateway
4848metadata:
5959 kind: GatewayProxy
6060 name: api7-proxy-config
6161`
62- var defautlGatewayHTTPS = `
62+ var defaultGatewayHTTPS = `
6363apiVersion: gateway.networking.k8s.io/v1
6464kind: Gateway
6565metadata:
@@ -111,7 +111,7 @@ spec:
111111
112112 By ("create GatewayClass" )
113113 gatewayClassName := fmt .Sprintf ("api7-%d" , time .Now ().Unix ())
114- err = s .CreateResourceFromStringWithNamespace (fmt .Sprintf (defautlGatewayClass , gatewayClassName , s .GetControllerName ()), "" )
114+ err = s .CreateResourceFromStringWithNamespace (fmt .Sprintf (gatewayClassYaml , gatewayClassName , s .GetControllerName ()), "" )
115115 Expect (err ).NotTo (HaveOccurred (), "creating GatewayClass" )
116116 time .Sleep (5 * time .Second )
117117
@@ -122,7 +122,7 @@ spec:
122122 Expect (gcyaml ).To (ContainSubstring ("message: the gatewayclass has been accepted by the api7-ingress-controller" ), "checking GatewayClass condition message" )
123123
124124 By ("create Gateway" )
125- err = s .CreateResourceFromString (fmt .Sprintf (defautlGateway , gatewayClassName ))
125+ err = s .CreateResourceFromString (fmt .Sprintf (defaultGateway , gatewayClassName ))
126126 Expect (err ).NotTo (HaveOccurred (), "creating Gateway" )
127127 time .Sleep (5 * time .Second )
128128
@@ -144,7 +144,7 @@ spec:
144144 createSecret (s , secretName )
145145 By ("create GatewayClass" )
146146 gatewayClassName := fmt .Sprintf ("api7-%d" , time .Now ().Unix ())
147- err = s .CreateResourceFromStringWithNamespace (fmt .Sprintf (defautlGatewayClass , gatewayClassName , s .GetControllerName ()), "" )
147+ err = s .CreateResourceFromStringWithNamespace (fmt .Sprintf (gatewayClassYaml , gatewayClassName , s .GetControllerName ()), "" )
148148 Expect (err ).NotTo (HaveOccurred (), "creating GatewayClass" )
149149 time .Sleep (5 * time .Second )
150150
@@ -155,7 +155,7 @@ spec:
155155 Expect (gcyaml ).To (ContainSubstring ("message: the gatewayclass has been accepted by the api7-ingress-controller" ), "checking GatewayClass condition message" )
156156
157157 By ("create Gateway" )
158- err = s .CreateResourceFromString (fmt .Sprintf (defautlGatewayHTTPS , gatewayClassName ))
158+ err = s .CreateResourceFromString (fmt .Sprintf (defaultGatewayHTTPS , gatewayClassName ))
159159 Expect (err ).NotTo (HaveOccurred (), "creating Gateway" )
160160 time .Sleep (5 * time .Second )
161161
@@ -211,6 +211,157 @@ spec:
211211 })
212212 })
213213
214+ Context ("HTTPRoute with Multiple Gateway" , func () {
215+ var additionalGatewayGroupID string
216+ var additionalNamespace string
217+ var additionalGatewayClassName string
218+
219+ var additionalGatewayProxyYaml = `
220+ apiVersion: gateway.apisix.io/v1alpha1
221+ kind: GatewayProxy
222+ metadata:
223+ name: additional-proxy-config
224+ spec:
225+ provider:
226+ type: ControlPlane
227+ controlPlane:
228+ endpoints:
229+ - %s
230+ auth:
231+ type: AdminKey
232+ adminKey:
233+ value: "%s"
234+ `
235+
236+ var additionalGateway = `
237+ apiVersion: gateway.networking.k8s.io/v1
238+ kind: Gateway
239+ metadata:
240+ name: additional-gateway
241+ spec:
242+ gatewayClassName: %s
243+ listeners:
244+ - name: http-additional
245+ protocol: HTTP
246+ port: 80
247+ allowedRoutes:
248+ namespaces:
249+ from: All
250+ infrastructure:
251+ parametersRef:
252+ group: gateway.apisix.io
253+ kind: GatewayProxy
254+ name: additional-proxy-config
255+ `
256+
257+ // HTTPRoute that references both gateways
258+ var multiGatewayHTTPRoute = `
259+ apiVersion: gateway.networking.k8s.io/v1
260+ kind: HTTPRoute
261+ metadata:
262+ name: multi-gateway-route
263+ spec:
264+ parentRefs:
265+ - name: api7ee
266+ namespace: %s
267+ - name: additional-gateway
268+ namespace: %s
269+ hostnames:
270+ - httpbin.example
271+ - httpbin-additional.example
272+ rules:
273+ - matches:
274+ - path:
275+ type: Exact
276+ value: /get
277+ backendRefs:
278+ - name: httpbin-service-e2e-test
279+ port: 80
280+ `
281+
282+ BeforeEach (func () {
283+ beforeEachHTTP ()
284+
285+ By ("Create additional gateway group" )
286+ var err error
287+ additionalGatewayGroupID , additionalNamespace , err = s .CreateAdditionalGatewayGroup ("multi-gw" )
288+ Expect (err ).NotTo (HaveOccurred (), "creating additional gateway group" )
289+
290+ By ("Create additional GatewayProxy" )
291+ // Get admin key for the additional gateway group
292+ resources , exists := s .GetAdditionalGatewayGroup (additionalGatewayGroupID )
293+ Expect (exists ).To (BeTrue (), "additional gateway group should exist" )
294+
295+ By ("Create additional GatewayClass" )
296+ additionalGatewayClassName = fmt .Sprintf ("api7-%d" , time .Now ().Unix ())
297+ err = s .CreateResourceFromStringWithNamespace (fmt .Sprintf (gatewayClassYaml , additionalGatewayClassName , s .GetControllerName ()), "" )
298+ Expect (err ).NotTo (HaveOccurred (), "creating additional GatewayClass" )
299+ time .Sleep (5 * time .Second )
300+ By ("Check additional GatewayClass condition" )
301+ gcyaml , err := s .GetResourceYaml ("GatewayClass" , additionalGatewayClassName )
302+ Expect (err ).NotTo (HaveOccurred (), "getting additional GatewayClass yaml" )
303+ Expect (gcyaml ).To (ContainSubstring (`status: "True"` ), "checking additional GatewayClass condition status" )
304+ Expect (gcyaml ).To (ContainSubstring ("message: the gatewayclass has been accepted by the api7-ingress-controller" ), "checking additional GatewayClass condition message" )
305+
306+ additionalGatewayProxy := fmt .Sprintf (additionalGatewayProxyYaml , framework .DashboardTLSEndpoint , resources .AdminAPIKey )
307+ err = s .CreateResourceFromStringWithNamespace (additionalGatewayProxy , additionalNamespace )
308+ Expect (err ).NotTo (HaveOccurred (), "creating additional GatewayProxy" )
309+
310+ By ("Create additional Gateway" )
311+ err = s .CreateResourceFromStringWithNamespace (
312+ fmt .Sprintf (additionalGateway , additionalGatewayClassName ),
313+ additionalNamespace ,
314+ )
315+ Expect (err ).NotTo (HaveOccurred (), "creating additional Gateway" )
316+ time .Sleep (5 * time .Second )
317+ })
318+
319+ It ("HTTPRoute should be accessible through both gateways" , func () {
320+ By ("Create HTTPRoute referencing both gateways" )
321+ multiGatewayRoute := fmt .Sprintf (multiGatewayHTTPRoute , s .Namespace (), additionalNamespace )
322+ ResourceApplied ("HTTPRoute" , "multi-gateway-route" , multiGatewayRoute , 1 )
323+
324+ By ("Access through default gateway" )
325+ s .NewAPISIXClient ().
326+ GET ("/get" ).
327+ WithHost ("httpbin.example" ).
328+ Expect ().
329+ Status (http .StatusOK )
330+
331+ By ("Access through additional gateway" )
332+ client , err := s .NewAPISIXClientForGatewayGroup (additionalGatewayGroupID )
333+ Expect (err ).NotTo (HaveOccurred (), "creating client for additional gateway" )
334+
335+ client .
336+ GET ("/get" ).
337+ WithHost ("httpbin-additional.example" ).
338+ Expect ().
339+ Status (http .StatusOK )
340+
341+ By ("Delete Additional Gateway" )
342+ err = s .DeleteResourceFromStringWithNamespace (fmt .Sprintf (additionalGateway , additionalGatewayClassName ), additionalNamespace )
343+ Expect (err ).NotTo (HaveOccurred (), "deleting additional Gateway" )
344+ time .Sleep (5 * time .Second )
345+
346+ By ("HTTPRoute should still be accessible through default gateway" )
347+ s .NewAPISIXClient ().
348+ GET ("/get" ).
349+ WithHost ("httpbin.example" ).
350+ Expect ().
351+ Status (http .StatusOK )
352+
353+ By ("HTTPRoute should not be accessible through additional gateway" )
354+ client , err = s .NewAPISIXClientForGatewayGroup (additionalGatewayGroupID )
355+ Expect (err ).NotTo (HaveOccurred (), "creating client for additional gateway" )
356+
357+ client .
358+ GET ("/get" ).
359+ WithHost ("httpbin-additional.example" ).
360+ Expect ().
361+ Status (http .StatusNotFound )
362+ })
363+ })
364+
214365 Context ("HTTPRoute Base" , func () {
215366 var exactRouteByGet = `
216367apiVersion: gateway.networking.k8s.io/v1
0 commit comments