Skip to content

Commit cbcc4fa

Browse files
committed
fix: gateway proxy
Signed-off-by: ashing <[email protected]>
1 parent d7f500f commit cbcc4fa

File tree

2 files changed

+62
-48
lines changed

2 files changed

+62
-48
lines changed

test/e2e/gatewayapi/controller.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,29 @@ import (
88
. "github.com/onsi/gomega"
99
"github.com/stretchr/testify/assert"
1010

11+
"github.com/api7/api7-ingress-controller/test/e2e/framework"
1112
"github.com/api7/api7-ingress-controller/test/e2e/scaffold"
1213
)
1314

1415
var _ = Describe("Check if controller cache gets synced with correct resources", func() {
16+
17+
var gatewayProxyYaml = `
18+
apiVersion: gateway.apisix.io/v1alpha1
19+
kind: GatewayProxy
20+
metadata:
21+
name: api7-proxy-config
22+
spec:
23+
provider:
24+
type: ControlPlane
25+
controlPlane:
26+
endpoints:
27+
- %s
28+
auth:
29+
type: AdminKey
30+
adminKey:
31+
value: "%s"
32+
`
33+
1534
var defautlGatewayClass = `
1635
apiVersion: gateway.networking.k8s.io/v1
1736
kind: GatewayClass
@@ -34,6 +53,11 @@ spec:
3453
- name: http1
3554
protocol: HTTP
3655
port: 80
56+
infrastructure:
57+
parametersRef:
58+
group: gateway.apisix.io
59+
kind: GatewayProxy
60+
name: api7-proxy-config
3761
`
3862

3963
var ResourceApplied = func(s *scaffold.Scaffold, resourType, resourceName, ns, resourceRaw string, observedGeneration int) {
@@ -63,6 +87,13 @@ metadata:
6387
`, gatewayName))
6488
Expect(err).NotTo(HaveOccurred(), "creating namespace")
6589
By(fmt.Sprintf("create GatewayClass for controller %s", s.GetControllerName()))
90+
91+
By("create GatewayProxy")
92+
gatewayProxy := fmt.Sprintf(gatewayProxyYaml, framework.DashboardTLSEndpoint, s.AdminKey())
93+
err = s.CreateResourceFromStringWithNamespace(gatewayProxy, gatewayName)
94+
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy")
95+
time.Sleep(5 * time.Second)
96+
6697
gatewayClassName := fmt.Sprintf("api7-%d", time.Now().Unix())
6798
err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defautlGatewayClass, gatewayClassName, gatewayName, s.GetControllerName()), gatewayName)
6899
Expect(err).NotTo(HaveOccurred(), "creating GatewayClass")

test/e2e/gatewayapi/gatewayproxy.go

Lines changed: 31 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,6 @@ spec:
4242
name: api7-proxy-config
4343
`
4444

45-
var gatewayWithoutProxy = `
46-
apiVersion: gateway.networking.k8s.io/v1
47-
kind: Gateway
48-
metadata:
49-
name: api7
50-
spec:
51-
gatewayClassName: %s
52-
listeners:
53-
- name: http
54-
protocol: HTTP
55-
port: 80
56-
`
57-
5845
var gatewayProxyWithEnabledPlugin = `
5946
apiVersion: gateway.apisix.io/v1alpha1
6047
kind: GatewayProxy
@@ -84,6 +71,15 @@ kind: GatewayProxy
8471
metadata:
8572
name: api7-proxy-config
8673
spec:
74+
provider:
75+
type: ControlPlane
76+
controlPlane:
77+
endpoints:
78+
- %s
79+
auth:
80+
type: AdminKey
81+
adminKey:
82+
value: "%s"
8783
plugins:
8884
- name: response-rewrite
8985
enabled: false
@@ -98,6 +94,15 @@ kind: GatewayProxy
9894
metadata:
9995
name: api7-proxy-config
10096
spec:
97+
provider:
98+
type: ControlPlane
99+
controlPlane:
100+
endpoints:
101+
- %s
102+
auth:
103+
type: AdminKey
104+
adminKey:
105+
value: "%s"
101106
plugins:
102107
- name: error-page
103108
enabled: true
@@ -117,6 +122,15 @@ kind: GatewayProxy
117122
metadata:
118123
name: api7-proxy-config
119124
spec:
125+
provider:
126+
type: ControlPlane
127+
controlPlane:
128+
endpoints:
129+
- %s
130+
auth:
131+
type: AdminKey
132+
adminKey:
133+
value: "%s"
120134
plugins:
121135
- name: error-page
122136
enabled: true
@@ -226,7 +240,7 @@ spec:
226240
resp.Header("X-Proxy-Test").IsEqual("enabled")
227241

228242
By("Update GatewayProxy with disabled plugin")
229-
err := s.CreateResourceFromString(gatewayProxyWithDisabledPlugin)
243+
err := s.CreateResourceFromString(fmt.Sprintf(gatewayProxyWithDisabledPlugin, framework.DashboardTLSEndpoint, s.AdminKey()))
230244
Expect(err).NotTo(HaveOccurred(), "updating GatewayProxy with disabled plugin")
231245
time.Sleep(5 * time.Second)
232246

@@ -242,37 +256,6 @@ spec:
242256

243257
resp.Header("X-Proxy-Test").IsEmpty()
244258
})
245-
246-
It("Should work normally without GatewayProxy", func() {
247-
By("Create HTTPRoute for Gateway with GatewayProxy")
248-
resourceApplied("HTTPRoute", "test-route", fmt.Sprintf(httpRouteForTest, "api7"), 1)
249-
250-
By("Check if the plugin is applied")
251-
resp := s.NewAPISIXClient().
252-
GET("/get").
253-
WithHost("example.com").
254-
Expect().
255-
Status(200)
256-
257-
resp.Header("X-Proxy-Test").IsEqual("enabled")
258-
259-
By("Update Gateway without GatewayProxy")
260-
err := s.CreateResourceFromString(fmt.Sprintf(gatewayWithoutProxy, gatewayClassName))
261-
Expect(err).NotTo(HaveOccurred(), "updating Gateway without GatewayProxy")
262-
time.Sleep(5 * time.Second)
263-
264-
By("Create HTTPRoute for Gateway without GatewayProxy")
265-
resourceApplied("HTTPRoute", "test-route", fmt.Sprintf(httpRouteForTest, "api7"), 1)
266-
267-
By("Check if the route works without plugin")
268-
resp = s.NewAPISIXClient().
269-
GET("/get").
270-
WithHost("example.com").
271-
Expect().
272-
Status(200)
273-
274-
resp.Header("X-Proxy-Test").IsEmpty()
275-
})
276259
})
277260

278261
Context("Test Gateway with PluginMetadata", func() {
@@ -282,7 +265,7 @@ spec:
282265

283266
It("Should work OK with error-page", func() {
284267
By("Update GatewayProxy with PluginMetadata")
285-
err = s.CreateResourceFromString(gatewayProxyWithPluginMetadata0)
268+
err = s.CreateResourceFromString(fmt.Sprintf(gatewayProxyWithPluginMetadata0, framework.DashboardTLSEndpoint, s.AdminKey()))
286269
Expect(err).ShouldNot(HaveOccurred())
287270
time.Sleep(5 * time.Second)
288271

@@ -298,7 +281,7 @@ spec:
298281
Body().Contains("404 from plugin metadata")
299282

300283
By("Update GatewayProxy with PluginMetadata")
301-
err = s.CreateResourceFromString(gatewayProxyWithPluginMetadata1)
284+
err = s.CreateResourceFromString(fmt.Sprintf(gatewayProxyWithPluginMetadata1, framework.DashboardTLSEndpoint, s.AdminKey()))
302285
Expect(err).ShouldNot(HaveOccurred())
303286
time.Sleep(5 * time.Second)
304287

@@ -311,7 +294,7 @@ spec:
311294
Body().Contains(`{"error_msg":"404 Route Not Found"}`)
312295

313296
By("Delete GatewayProxy")
314-
err = s.DeleteResourceFromString(gatewayProxyWithPluginMetadata0)
297+
err = s.DeleteResourceFromString(fmt.Sprintf(gatewayProxyWithPluginMetadata0, framework.DashboardTLSEndpoint, s.AdminKey()))
315298
Expect(err).ShouldNot(HaveOccurred())
316299
time.Sleep(5 * time.Second)
317300

0 commit comments

Comments
 (0)