1818package v2
1919
2020import (
21+ "fmt"
22+ "net/http"
23+ "time"
24+
2125 . "github.com/onsi/ginkgo/v2"
2226 . "github.com/onsi/gomega"
27+ "k8s.io/apimachinery/pkg/types"
2328
29+ apiv2 "github.com/apache/apisix-ingress-controller/api/v2"
30+ "github.com/apache/apisix-ingress-controller/test/e2e/framework"
2431 "github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
2532)
2633
@@ -56,11 +63,14 @@ spec:
5663`
5764
5865var _ = Describe ("APISIX Standalone Basic Tests" , Label ("apisix.apache.org" , "v2" , "basic" ), func () {
59- s := scaffold .NewScaffold (& scaffold.Options {
60- ControllerName : "apisix.apache.org/apisix-ingress-controller" ,
61- })
66+ var (
67+ s = scaffold .NewScaffold (& scaffold.Options {
68+ ControllerName : "apisix.apache.org/apisix-ingress-controller" ,
69+ })
70+ applier = framework .NewApplier (s .GinkgoT , s .K8sClient , s .CreateResourceFromString )
71+ )
6272
63- Describe ("APISIX HTTP Proxy" , func () {
73+ Context ("APISIX HTTP Proxy" , func () {
6474 It ("should handle basic HTTP requests" , func () {
6575 httpClient := s .NewAPISIXClient ()
6676 Expect (httpClient ).NotTo (BeNil ())
@@ -83,6 +93,97 @@ var _ = Describe("APISIX Standalone Basic Tests", Label("apisix.apache.org", "v2
8393 Expect ().
8494 Status (404 ).Body ().Contains ("404 Route Not Found" )
8595 })
96+ })
97+
98+ Context ("IngressClass Annotations" , func () {
99+ It ("Basic tests" , func () {
100+ const gatewayProxyYaml = `
101+ apiVersion: apisix.apache.org/v1alpha1
102+ kind: GatewayProxy
103+ metadata:
104+ name: apisix-proxy-config
105+ spec:
106+ provider:
107+ type: ControlPlane
108+ controlPlane:
109+ endpoints:
110+ - %s
111+ auth:
112+ type: AdminKey
113+ adminKey:
114+ value: "%s"
115+ `
86116
117+ const ingressClassYaml = `
118+ apiVersion: networking.k8s.io/%s
119+ kind: IngressClass
120+ metadata:
121+ name: apisix
122+ annotations:
123+ apisix.apache.org/parameters-namespace: %s
124+ spec:
125+ controller: apisix.apache.org/apisix-ingress-controller
126+ parameters:
127+ apiGroup: apisix.apache.org
128+ kind: GatewayProxy
129+ name: apisix-proxy-config
130+ `
131+
132+ By ("create GatewayProxy" )
133+ gatewayProxy := fmt .Sprintf (gatewayProxyYaml , s .Deployer .GetAdminEndpoint (), s .AdminKey ())
134+ err := s .CreateResourceFromString (gatewayProxy )
135+ Expect (err ).NotTo (HaveOccurred (), "creating GatewayProxy" )
136+ time .Sleep (5 * time .Second )
137+
138+ By ("create IngressClass" )
139+ ingressClass := fmt .Sprintf (ingressClassYaml , framework .IngressVersion , s .Namespace ())
140+ err = s .CreateResourceFromString (ingressClass )
141+ Expect (err ).NotTo (HaveOccurred (), "creating IngressClass" )
142+ time .Sleep (5 * time .Second )
143+
144+ const apisixRouteSpec = `
145+ apiVersion: apisix.apache.org/v2
146+ kind: ApisixRoute
147+ metadata:
148+ name: default
149+ spec:
150+ ingressClassName: apisix
151+ http:
152+ - name: rule0
153+ match:
154+ hosts:
155+ - httpbin
156+ paths:
157+ - %s
158+ backends:
159+ - serviceName: httpbin-service-e2e-test
160+ servicePort: 80
161+ `
162+ request := func (path string ) int {
163+ return s .NewAPISIXClient ().GET (path ).WithHost ("httpbin" ).Expect ().Raw ().StatusCode
164+ }
165+
166+ By ("apply ApisixRoute" )
167+ var apisixRoute apiv2.ApisixRoute
168+ applier .MustApplyAPIv2 (types.NamespacedName {Namespace : s .Namespace (), Name : "default" }, & apisixRoute , fmt .Sprintf (apisixRouteSpec , "/get" ))
169+
170+ By ("verify ApisixRoute works" )
171+ Eventually (request ).WithArguments ("/get" ).WithTimeout (8 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusOK ))
172+
173+ By ("update ApisixRoute" )
174+ applier .MustApplyAPIv2 (types.NamespacedName {Namespace : s .Namespace (), Name : "default" }, & apisixRoute , fmt .Sprintf (apisixRouteSpec , "/headers" ))
175+ Eventually (request ).WithArguments ("/get" ).WithTimeout (8 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusNotFound ))
176+ s .RequestAssert (& scaffold.RequestAssert {
177+ Method : "GET" ,
178+ Path : "/headers" ,
179+ Host : "httpbin" ,
180+ Check : scaffold .WithExpectedStatus (http .StatusOK ),
181+ })
182+
183+ By ("delete ApisixRoute" )
184+ err = s .DeleteResource ("ApisixRoute" , "default" )
185+ Expect (err ).ShouldNot (HaveOccurred (), "deleting ApisixRoute" )
186+ Eventually (request ).WithArguments ("/headers" ).WithTimeout (8 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusNotFound ))
187+ })
87188 })
88189})
0 commit comments