@@ -19,21 +19,28 @@ package v1alpha1
19
19
20
20
import (
21
21
"fmt"
22
+ "time"
22
23
23
24
. "github.com/onsi/ginkgo/v2"
24
25
. "github.com/onsi/gomega"
26
+ "k8s.io/apimachinery/pkg/types"
25
27
26
28
"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
27
29
)
28
30
29
31
var _ = Describe ("Test BackendTrafficPolicy base on HTTPRoute" , Label ("apisix.apache.org" , "v1alpha1" , "backendtrafficpolicy" ), func () {
30
- s := scaffold .NewDefaultScaffold ()
32
+ var (
33
+ s = scaffold .NewScaffold (& scaffold.Options {
34
+ ControllerName : fmt .Sprintf ("apisix.apache.org/apisix-ingress-controller-%d" , time .Now ().Unix ()),
35
+ })
36
+ err error
37
+ )
31
38
32
39
var defaultGatewayProxy = `
33
40
apiVersion: apisix.apache.org/v1alpha1
34
41
kind: GatewayProxy
35
42
metadata:
36
- name: apisix-proxy-config
43
+ name: %s
37
44
spec:
38
45
provider:
39
46
type: ControlPlane
59
66
apiVersion: gateway.networking.k8s.io/v1
60
67
kind: Gateway
61
68
metadata:
62
- name: apisix
69
+ name: %s
63
70
spec:
64
71
gatewayClassName: %s
65
72
listeners:
@@ -70,17 +77,18 @@ spec:
70
77
parametersRef:
71
78
group: apisix.apache.org
72
79
kind: GatewayProxy
73
- name: apisix-proxy-config
80
+ name: %s
74
81
`
75
82
76
83
var defaultHTTPRoute = `
77
84
apiVersion: gateway.networking.k8s.io/v1
78
85
kind: HTTPRoute
79
86
metadata:
80
87
name: httpbin
88
+ namespace: %s
81
89
spec:
82
90
parentRefs:
83
- - name: apisix
91
+ - name: %s
84
92
hostnames:
85
93
- "httpbin.org"
86
94
rules:
@@ -125,7 +133,26 @@ spec:
125
133
`
126
134
127
135
BeforeEach (func () {
128
- s .ApplyDefaultGatewayResource (defaultGatewayProxy , defaultGatewayClass , defaultGateway , defaultHTTPRoute )
136
+ gatewayName := s .Namespace ()
137
+ By ("create GatewayProxy" )
138
+ gatewayProxyName := gatewayName
139
+ err = s .CreateResourceFromString (fmt .Sprintf (defaultGatewayProxy , gatewayProxyName , s .Deployer .GetAdminEndpoint (), s .AdminKey ()))
140
+ Expect (err ).NotTo (HaveOccurred (), "creating GatewayProxy" )
141
+ time .Sleep (time .Second )
142
+
143
+ By ("create GatewayClass" )
144
+ gatewayClassName := fmt .Sprintf ("apisix-%d" , time .Now ().Unix ())
145
+ err = s .CreateResourceFromString (fmt .Sprintf (defaultGatewayClass , gatewayClassName , s .GetControllerName ()))
146
+ Expect (err ).NotTo (HaveOccurred (), "creating GatewayClass" )
147
+ time .Sleep (time .Second )
148
+
149
+ By ("create Gateway" )
150
+ err = s .CreateResourceFromString (fmt .Sprintf (defaultGateway , gatewayName , gatewayClassName , gatewayProxyName ))
151
+ Expect (err ).NotTo (HaveOccurred (), "creating Gateway" )
152
+ time .Sleep (time .Second )
153
+
154
+ By ("create HTTPRoute" )
155
+ s .ApplyHTTPRoute (types.NamespacedName {Namespace : s .Namespace (), Name : "httpbin" }, fmt .Sprintf (defaultHTTPRoute , gatewayName , s .Namespace ()))
129
156
})
130
157
It ("should rewrite upstream host" , func () {
131
158
s .ResourceApplied ("BackendTrafficPolicy" , "httpbin" , createUpstreamHost , 1 )
@@ -184,15 +211,14 @@ spec:
184
211
185
212
var _ = Describe ("Test BackendTrafficPolicy base on Ingress" , Label ("apisix.apache.org" , "v1alpha1" , "backendtrafficpolicy" ), func () {
186
213
s := scaffold .NewScaffold (& scaffold.Options {
187
- ControllerName : "apisix.apache.org/apisix-ingress-controller" ,
214
+ ControllerName : fmt . Sprintf ( "apisix.apache.org/apisix-ingress-controller-%d" , time . Now (). Unix ()) ,
188
215
})
189
216
190
217
var defaultGatewayProxy = `
191
218
apiVersion: apisix.apache.org/v1alpha1
192
219
kind: GatewayProxy
193
220
metadata:
194
- name: apisix-proxy-config
195
- namespace: default
221
+ name: %s
196
222
spec:
197
223
provider:
198
224
type: ControlPlane
@@ -212,12 +238,12 @@ metadata:
212
238
annotations:
213
239
ingressclass.kubernetes.io/is-default-class: "true"
214
240
spec:
215
- controller: "apisix.apache.org/apisix-ingress-controller "
241
+ controller: "%s "
216
242
parameters:
217
243
apiGroup: "apisix.apache.org"
218
244
kind: "GatewayProxy"
219
- name: "apisix-proxy-config "
220
- namespace: "default "
245
+ name: "%s "
246
+ namespace: "%s "
221
247
scope: "Namespace"
222
248
`
223
249
@@ -241,25 +267,28 @@ spec:
241
267
`
242
268
var beforeEach = func () {
243
269
By ("create GatewayProxy" )
244
- gatewayProxy := fmt .Sprintf (defaultGatewayProxy , s .Deployer .GetAdminEndpoint (), s .AdminKey ())
245
- err := s .CreateResourceFromStringWithNamespace (gatewayProxy , "default" )
270
+ gatewayProxyName := s .Namespace ()
271
+ gatewayProxy := fmt .Sprintf (defaultGatewayProxy , gatewayProxyName , s .Deployer .GetAdminEndpoint (), s .AdminKey ())
272
+ err := s .CreateResourceFromString (gatewayProxy )
246
273
Expect (err ).NotTo (HaveOccurred (), "creating GatewayProxy" )
247
274
248
275
By ("create IngressClass with GatewayProxy reference" )
249
- err = s .CreateResourceFromStringWithNamespace ( defaultIngressClass , "" )
276
+ err = s .CreateResourceFromString ( fmt . Sprintf ( defaultIngressClass , s . GetControllerName (), gatewayProxyName , s . Namespace ()) )
250
277
Expect (err ).NotTo (HaveOccurred (), "creating IngressClass with GatewayProxy" )
251
278
252
279
By ("create Ingress with GatewayProxy IngressClass" )
253
280
err = s .CreateResourceFromString (defaultIngress )
254
281
Expect (err ).NotTo (HaveOccurred (), "creating Ingress with GatewayProxy IngressClass" )
255
282
}
256
283
257
- Context ("Rewrite Upstream Host" , func () {
284
+ // Tests concerning the default ingress class need to be run serially
285
+ Context ("Rewrite Upstream Host" , Serial , func () {
258
286
var createUpstreamHost = `
259
287
apiVersion: apisix.apache.org/v1alpha1
260
288
kind: BackendTrafficPolicy
261
289
metadata:
262
290
name: httpbin
291
+ namespace: %s
263
292
spec:
264
293
targetRefs:
265
294
- name: httpbin-service-e2e-test
@@ -274,6 +303,7 @@ apiVersion: apisix.apache.org/v1alpha1
274
303
kind: BackendTrafficPolicy
275
304
metadata:
276
305
name: httpbin
306
+ namespace: %s
277
307
spec:
278
308
targetRefs:
279
309
- name: httpbin-service-e2e-test
@@ -293,19 +323,20 @@ spec:
293
323
"Host" : "httpbin.org" ,
294
324
},
295
325
}
296
- s .ResourceApplied ("BackendTrafficPolicy" , "httpbin" , createUpstreamHost , 1 )
326
+
327
+ s .ResourceApplied ("BackendTrafficPolicy" , "httpbin" , fmt .Sprintf (createUpstreamHost , s .Namespace ()), 1 )
297
328
s .RequestAssert (reqAssert .SetChecks (
298
329
scaffold .WithExpectedStatus (200 ),
299
330
scaffold .WithExpectedBodyContains ("httpbin.example.com" ),
300
331
))
301
332
302
- s .ResourceApplied ("BackendTrafficPolicy" , "httpbin" , updateUpstreamHost , 2 )
333
+ s .ResourceApplied ("BackendTrafficPolicy" , "httpbin" , fmt . Sprintf ( updateUpstreamHost , s . Namespace ()) , 2 )
303
334
s .RequestAssert (reqAssert .SetChecks (
304
335
scaffold .WithExpectedStatus (200 ),
305
336
scaffold .WithExpectedBodyContains ("httpbin.update.example.com" ),
306
337
))
307
338
308
- err := s .DeleteResourceFromString (createUpstreamHost )
339
+ err := s .DeleteResourceFromString (fmt . Sprintf ( createUpstreamHost , s . Namespace ()) )
309
340
Expect (err ).NotTo (HaveOccurred (), "deleting BackendTrafficPolicy" )
310
341
311
342
s .RequestAssert (reqAssert .SetChecks (
0 commit comments