Skip to content

Commit 3ce4c54

Browse files
committed
fix test
1 parent 1fbadd2 commit 3ce4c54

File tree

5 files changed

+209
-167
lines changed

5 files changed

+209
-167
lines changed

internal/controller/apisixroute_controller.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,13 +642,20 @@ func (r *ApisixRouteReconciler) listApisixRoutesForPluginConfig(ctx context.Cont
642642

643643
// First check if the ApisixPluginConfig has matching IngressClassName
644644
if pc.Spec.IngressClassName != "" {
645-
var ic networkingv1.IngressClass
646-
if err := r.Get(ctx, client.ObjectKey{Name: pc.Spec.IngressClassName}, &ic); err != nil {
645+
var icObj client.Object
646+
switch r.ICGV.String() {
647+
case networkingv1beta1.SchemeGroupVersion.String():
648+
icObj = &networkingv1beta1.IngressClass{}
649+
default:
650+
icObj = &networkingv1.IngressClass{}
651+
}
652+
if err := r.Get(ctx, client.ObjectKey{Name: pc.Spec.IngressClassName}, icObj); err != nil {
647653
if client.IgnoreNotFound(err) != nil {
648654
r.Log.Error(err, "failed to get IngressClass for ApisixPluginConfig", "pluginconfig", pc.Name)
649655
}
650656
return nil
651657
}
658+
ic := convertIngressClass(icObj)
652659
if !matchesController(ic.Spec.Controller) {
653660
return nil
654661
}

test/e2e/crds/v2/globalrule.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,23 @@ var _ = Describe("Test GlobalRule", Label("apisix.apache.org", "v2", "apisixglob
3434
ControllerName: "apisix.apache.org/apisix-ingress-controller",
3535
})
3636

37-
var ingressYaml = `
38-
apiVersion: networking.k8s.io/v1
39-
kind: Ingress
37+
var defaultRoute = `
38+
apiVersion: apisix.apache.org/v2
39+
kind: ApisixRoute
4040
metadata:
41-
name: test-ingress
41+
name: default
4242
spec:
4343
ingressClassName: apisix
44-
rules:
45-
- host: globalrule.example.com
46-
http:
44+
http:
45+
- name: rule0
46+
match:
47+
hosts:
48+
- globalrule.example.com
4749
paths:
48-
- path: /
49-
pathType: Prefix
50-
backend:
51-
service:
52-
name: httpbin-service-e2e-test
53-
port:
54-
number: 80
50+
- /*
51+
backends:
52+
- serviceName: httpbin-service-e2e-test
53+
servicePort: 80
5554
`
5655

5756
Context("ApisixGlobalRule Basic Operations", func() {
@@ -68,9 +67,9 @@ spec:
6867
Expect(err).NotTo(HaveOccurred(), "creating IngressClass")
6968
time.Sleep(5 * time.Second)
7069

71-
By("create Ingress")
72-
err = s.CreateResourceFromString(ingressYaml)
73-
Expect(err).NotTo(HaveOccurred(), "creating Ingress")
70+
By("create ApisixRoute")
71+
err = s.CreateResourceFromString(defaultRoute)
72+
Expect(err).NotTo(HaveOccurred(), "creating ApisixRoute")
7473
time.Sleep(5 * time.Second)
7574

7675
By("verify Ingress works")

test/e2e/crds/v2/status.go

Lines changed: 1 addition & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
3535
)
3636

37-
var _ = Describe("Test CRD Status", Label("apisix.apache.org", "v2", "apisixroute"), func() {
37+
var _ = Describe("Test apisix.apache.org/v2 Status", Label("apisix.apache.org", "v2", "apisixroute"), func() {
3838
var (
3939
s = scaffold.NewScaffold(&scaffold.Options{
4040
ControllerName: "apisix.apache.org/apisix-ingress-controller",
@@ -220,147 +220,4 @@ spec:
220220
"should not update the same status condition again")
221221
})
222222
})
223-
224-
Context("Test HTTPRoute Sync Status", func() {
225-
const httproute = `
226-
apiVersion: gateway.networking.k8s.io/v1
227-
kind: HTTPRoute
228-
metadata:
229-
name: httpbin
230-
spec:
231-
parentRefs:
232-
- name: apisix
233-
hostnames:
234-
- "httpbin"
235-
rules:
236-
- matches:
237-
- path:
238-
type: Exact
239-
value: /get
240-
backendRefs:
241-
- name: httpbin-service-e2e-test
242-
port: 80
243-
`
244-
const gatewayClass = `
245-
apiVersion: gateway.networking.k8s.io/v1
246-
kind: GatewayClass
247-
metadata:
248-
name: %s
249-
spec:
250-
controllerName: %s
251-
`
252-
const gatewayProxy = `
253-
apiVersion: apisix.apache.org/v1alpha1
254-
kind: GatewayProxy
255-
metadata:
256-
name: apisix-proxy-config
257-
spec:
258-
provider:
259-
type: ControlPlane
260-
controlPlane:
261-
endpoints:
262-
- %s
263-
auth:
264-
type: AdminKey
265-
adminKey:
266-
value: "%s"
267-
`
268-
const defaultGateway = `
269-
apiVersion: gateway.networking.k8s.io/v1
270-
kind: Gateway
271-
metadata:
272-
name: apisix
273-
spec:
274-
gatewayClassName: %s
275-
listeners:
276-
- name: http1
277-
protocol: HTTP
278-
port: 80
279-
infrastructure:
280-
parametersRef:
281-
group: apisix.apache.org
282-
kind: GatewayProxy
283-
name: apisix-proxy-config
284-
`
285-
BeforeEach(func() {
286-
By("create GatewayProxy")
287-
gatewayProxy := fmt.Sprintf(gatewayProxy, s.Deployer.GetAdminEndpoint(), s.AdminKey())
288-
err := s.CreateResourceFromString(gatewayProxy)
289-
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy")
290-
time.Sleep(5 * time.Second)
291-
292-
By("create GatewayClass")
293-
gatewayClassName := fmt.Sprintf("apisix-%d", time.Now().Unix())
294-
err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(gatewayClass, gatewayClassName, s.GetControllerName()), "")
295-
Expect(err).NotTo(HaveOccurred(), "creating GatewayClass")
296-
time.Sleep(5 * time.Second)
297-
298-
By("create Gateway")
299-
err = s.CreateResourceFromString(fmt.Sprintf(defaultGateway, gatewayClassName))
300-
Expect(err).NotTo(HaveOccurred(), "creating Gateway")
301-
time.Sleep(5 * time.Second)
302-
303-
By("check Gateway condition")
304-
gwyaml, err := s.GetResourceYaml("Gateway", "apisix")
305-
Expect(err).NotTo(HaveOccurred(), "getting Gateway yaml")
306-
Expect(gwyaml).To(ContainSubstring(`status: "True"`), "checking Gateway condition status")
307-
Expect(gwyaml).To(ContainSubstring("message: the gateway has been accepted by the apisix-ingress-controller"), "checking Gateway condition message")
308-
})
309-
AfterEach(func() {
310-
_ = s.DeleteResource("Gateway", "apisix")
311-
})
312-
313-
It("dataplane unavailable", func() {
314-
if os.Getenv("PROVIDER_TYPE") == adc.BackendModeAPI7EE {
315-
Skip("skip for api7ee mode because it use dashboard admin api")
316-
}
317-
By("Create HTTPRoute")
318-
err := s.CreateResourceFromString(httproute)
319-
Expect(err).NotTo(HaveOccurred(), "creating HTTPRoute")
320-
321-
By("check route in APISIX")
322-
s.RequestAssert(&scaffold.RequestAssert{
323-
Method: "GET",
324-
Path: "/get",
325-
Host: "httpbin",
326-
Check: scaffold.WithExpectedStatus(200),
327-
})
328-
329-
s.Deployer.ScaleDataplane(0)
330-
331-
By("check ApisixRoute status")
332-
s.RetryAssertion(func() string {
333-
output, _ := s.GetOutputFromString("httproute", "httpbin", "-o", "yaml")
334-
return output
335-
}).WithTimeout(80 * time.Second).
336-
Should(
337-
And(
338-
ContainSubstring(`status: "False"`),
339-
ContainSubstring(`reason: SyncFailed`),
340-
),
341-
)
342-
343-
s.Deployer.ScaleDataplane(1)
344-
345-
By("check ApisixRoute status after scaling up")
346-
s.RetryAssertion(func() string {
347-
output, _ := s.GetOutputFromString("httproute", "httpbin", "-o", "yaml")
348-
return output
349-
}).WithTimeout(80 * time.Second).
350-
Should(
351-
And(
352-
ContainSubstring(`status: "True"`),
353-
ContainSubstring(`reason: Accepted`),
354-
),
355-
)
356-
357-
By("check route in APISIX")
358-
s.RequestAssert(&scaffold.RequestAssert{
359-
Method: "GET",
360-
Path: "/get",
361-
Host: "httpbin",
362-
Check: scaffold.WithExpectedStatus(200),
363-
})
364-
})
365-
})
366223
})

test/e2e/crds/v2/tls.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ spec:
5353
`
5454

5555
const ingressClassYamlTls = `
56-
apiVersion: networking.k8s.io/v1
56+
apiVersion: networking.k8s.io/%s
5757
kind: IngressClass
5858
metadata:
5959
name: apisix-tls
@@ -63,8 +63,6 @@ spec:
6363
apiGroup: "apisix.apache.org"
6464
kind: "GatewayProxy"
6565
name: "apisix-proxy-tls"
66-
namespace: "default"
67-
scope: "Namespace"
6866
`
6967

7068
const apisixRouteYamlTls = `
@@ -107,7 +105,7 @@ var _ = Describe("Test ApisixTls", Label("apisix.apache.org", "v2", "apisixtls")
107105
time.Sleep(5 * time.Second)
108106

109107
By("create IngressClass")
110-
ingressClass := fmt.Sprintf(ingressClassYaml, framework.IngressVersion)
108+
ingressClass := fmt.Sprintf(ingressClassYamlTls, framework.IngressVersion)
111109
err = s.CreateResourceFromStringWithNamespace(ingressClass, "")
112110
Expect(err).NotTo(HaveOccurred(), "creating IngressClass")
113111
time.Sleep(5 * time.Second)

0 commit comments

Comments
 (0)