Skip to content

Commit 070e76c

Browse files
committed
add test
1 parent ea2ecd6 commit 070e76c

File tree

5 files changed

+137
-2
lines changed

5 files changed

+137
-2
lines changed

test/e2e/framework/ingress.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type IngressDeployOpts struct {
3333
Namespace string
3434
AdminEnpoint string
3535
StatusAddress string
36+
Replicas int
3637
}
3738

3839
func (f *Framework) DeployIngress(opts IngressDeployOpts) {

test/e2e/framework/manifests/ingress.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,12 @@ data:
340340
controller_name: {{ .ControllerName | default "apisix.apache.org/api7-ingress-controller" }}
341341
342342
leader_election_id: "api7-ingress-controller-leader"
343+
provider:
344+
sync_period: 0s
345+
# The period between two consecutive syncs.
346+
# The default value is 0 seconds, which means the controller will not sync.
347+
# If you want to enable the sync, set it to a positive value.
348+
init_sync_delay: 1m
343349
---
344350
apiVersion: v1
345351
kind: Service
@@ -370,7 +376,7 @@ metadata:
370376
name: api7-ingress-controller-manager
371377
namespace: {{ .Namespace }}
372378
spec:
373-
replicas: 1
379+
replicas: {{ .Replicas | default 1 }}
374380
selector:
375381
matchLabels:
376382
app: api7-ingress-controller

test/e2e/gatewayapi/httproute.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,25 @@ spec:
411411
backendRefs:
412412
- name: httpbin-service-e2e-test
413413
port: 80
414+
`
415+
var exactRouteByGet2 = `
416+
apiVersion: gateway.networking.k8s.io/v1
417+
kind: HTTPRoute
418+
metadata:
419+
name: httpbin2
420+
spec:
421+
parentRefs:
422+
- name: api7ee
423+
hostnames:
424+
- httpbin2.example
425+
rules:
426+
- matches:
427+
- path:
428+
type: Exact
429+
value: /get
430+
backendRefs:
431+
- name: httpbin-service-e2e-test
432+
port: 80
414433
`
415434
var invalidBackendPort = `
416435
apiVersion: v1
@@ -532,6 +551,46 @@ spec:
532551
Expect(nodes).To(HaveLen(1), "checking nodes length")
533552
Expect(nodes[0].Port).To(Equal(80))
534553
})
554+
555+
It("Delete HTTPRoute during restart", func() {
556+
By("create HTTPRoute httpbin")
557+
ResourceApplied("HTTPRoute", "httpbin", exactRouteByGet, 1)
558+
559+
By("create HTTPRoute httpbin2")
560+
ResourceApplied("HTTPRoute", "httpbin2", exactRouteByGet2, 1)
561+
562+
s.NewAPISIXClient().
563+
GET("/get").
564+
WithHost("httpbin.example").
565+
Expect().
566+
Status(200)
567+
568+
s.NewAPISIXClient().
569+
GET("/get").
570+
WithHost("httpbin2.example").
571+
Expect().
572+
Status(200)
573+
574+
s.ScaleIngress(0)
575+
576+
By("delete HTTPRoute httpbin2")
577+
s.DeleteResource("HTTPRoute", "httpbin2")
578+
579+
s.ScaleIngress(1)
580+
time.Sleep(1 * time.Minute)
581+
582+
s.NewAPISIXClient().
583+
GET("/get").
584+
WithHost("httpbin.example").
585+
Expect().
586+
Status(200)
587+
588+
s.NewAPISIXClient().
589+
GET("/get").
590+
WithHost("httpbin2.example").
591+
Expect().
592+
Status(404)
593+
})
535594
})
536595

537596
Context("HTTPRoute Rule Match", func() {

test/e2e/ingress/ingress.go

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ spec:
170170
apiVersion: networking.k8s.io/v1
171171
kind: Ingress
172172
metadata:
173-
name: api7-ingress-default
173+
name: api7-ingress-external
174174
spec:
175175
rules:
176176
- host: httpbin.external
@@ -234,6 +234,63 @@ spec:
234234
Expect().
235235
Status(200)
236236
})
237+
238+
It("Delete Ingress during restart", func() {
239+
By("create GatewayProxy")
240+
gatewayProxy := fmt.Sprintf(gatewayProxyYaml, framework.DashboardTLSEndpoint, s.AdminKey())
241+
err := s.CreateResourceFromStringWithNamespace(gatewayProxy, "default")
242+
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy")
243+
time.Sleep(5 * time.Second)
244+
245+
By("create Default IngressClass")
246+
err = s.CreateResourceFromStringWithNamespace(defaultIngressClass, "")
247+
Expect(err).NotTo(HaveOccurred(), "creating Default IngressClass")
248+
time.Sleep(5 * time.Second)
249+
250+
By("create Ingress with ExternalName")
251+
err = s.CreateResourceFromString(ingressWithExternalName)
252+
Expect(err).NotTo(HaveOccurred(), "creating Ingress without IngressClass")
253+
time.Sleep(5 * time.Second)
254+
255+
By("create Ingress")
256+
err = s.CreateResourceFromString(defaultIngress)
257+
Expect(err).NotTo(HaveOccurred(), "creating Ingress without IngressClass")
258+
time.Sleep(5 * time.Second)
259+
260+
By("checking the external service response")
261+
s.NewAPISIXClient().
262+
GET("/get").
263+
WithHost("httpbin.external").
264+
Expect().
265+
Status(200)
266+
267+
s.NewAPISIXClient().
268+
GET("/get").
269+
WithHost("default.example.com").
270+
Expect().
271+
Status(200)
272+
273+
s.ScaleIngress(0)
274+
275+
By("delete Ingress")
276+
err = s.DeleteResourceFromString(defaultIngress)
277+
Expect(err).NotTo(HaveOccurred(), "deleting Ingress without IngressClass")
278+
279+
s.ScaleIngress(1)
280+
time.Sleep(1 * time.Minute)
281+
282+
s.NewAPISIXClient().
283+
GET("/get").
284+
WithHost("httpbin.external").
285+
Expect().
286+
Status(200)
287+
288+
s.NewAPISIXClient().
289+
GET("/get").
290+
WithHost("default.example.com").
291+
Expect().
292+
Status(404)
293+
})
237294
})
238295

239296
Context("IngressClass with GatewayProxy", func() {

test/e2e/scaffold/ingress.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,17 @@ func (s *Scaffold) deployIngress() {
1111
AdminTLSVerify: false,
1212
Namespace: s.namespace,
1313
AdminEnpoint: framework.DashboardTLSEndpoint,
14+
Replicas: 1,
15+
})
16+
}
17+
18+
func (s *Scaffold) ScaleIngress(replicas int) {
19+
s.DeployIngress(framework.IngressDeployOpts{
20+
ControllerName: s.opts.ControllerName,
21+
AdminKey: s.AdminKey(),
22+
AdminTLSVerify: false,
23+
Namespace: s.namespace,
24+
AdminEnpoint: framework.DashboardTLSEndpoint,
25+
Replicas: replicas,
1426
})
1527
}

0 commit comments

Comments
 (0)