Skip to content

Commit 51392c0

Browse files
committed
fix: r
Signed-off-by: ashing <[email protected]>
1 parent b7bb5e1 commit 51392c0

File tree

3 files changed

+479
-30
lines changed

3 files changed

+479
-30
lines changed

test/e2e/gatewayapi/httproute.go

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 = `
216387
apiVersion: gateway.networking.k8s.io/v1

test/e2e/scaffold/dp.go

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package scaffold
1616

1717
import (
18-
"github.com/gruntwork-io/terratest/modules/k8s"
1918
. "github.com/onsi/gomega"
2019

2120
"github.com/api7/api7-ingress-controller/test/e2e/framework"
@@ -43,36 +42,13 @@ func (s *Scaffold) deployDataplane() {
4342
}
4443

4544
func (s *Scaffold) newAPISIXTunnels() error {
46-
var (
47-
httpNodePort int
48-
httpsNodePort int
49-
httpPort int
50-
httpsPort int
51-
serviceName = "api7ee3-apisix-gateway-mtls"
52-
)
53-
54-
svc := s.dataplaneService
55-
for _, port := range svc.Spec.Ports {
56-
if port.Name == "http" {
57-
httpNodePort = int(port.NodePort)
58-
httpPort = int(port.Port)
59-
} else if port.Name == "https" {
60-
httpsNodePort = int(port.NodePort)
61-
httpsPort = int(port.Port)
62-
}
63-
}
64-
s.apisixHttpTunnel = k8s.NewTunnel(s.kubectlOptions, k8s.ResourceTypeService, serviceName,
65-
httpNodePort, httpPort)
66-
s.apisixHttpsTunnel = k8s.NewTunnel(s.kubectlOptions, k8s.ResourceTypeService, serviceName,
67-
httpsNodePort, httpsPort)
68-
69-
if err := s.apisixHttpTunnel.ForwardPortE(s.t); err != nil {
45+
serviceName := "api7ee3-apisix-gateway-mtls"
46+
httpTunnel, httpsTunnel, err := s.createDataplaneTunnels(s.dataplaneService, s.kubectlOptions, serviceName)
47+
if err != nil {
7048
return err
7149
}
72-
s.addFinalizers(s.apisixHttpTunnel.Close)
73-
if err := s.apisixHttpsTunnel.ForwardPortE(s.t); err != nil {
74-
return err
75-
}
76-
s.addFinalizers(s.apisixHttpsTunnel.Close)
50+
51+
s.apisixHttpTunnel = httpTunnel
52+
s.apisixHttpsTunnel = httpsTunnel
7753
return nil
7854
}

0 commit comments

Comments
 (0)