Skip to content

Commit ac861d9

Browse files
committed
fix: r
Signed-off-by: Ashing Zheng <[email protected]>
1 parent 073e6fd commit ac861d9

File tree

5 files changed

+88
-17
lines changed

5 files changed

+88
-17
lines changed

test/e2e/crds/v1alpha1/backendtrafficpolicy.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,32 @@ import (
2323
. "github.com/onsi/ginkgo/v2"
2424
. "github.com/onsi/gomega"
2525

26+
"github.com/apache/apisix-ingress-controller/internal/provider/adc"
27+
"github.com/apache/apisix-ingress-controller/test/e2e/framework"
2628
"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
2729
)
2830

2931
var _ = Describe("Test BackendTrafficPolicy base on HTTPRoute", Label("apisix.apache.org", "v1alpha1", "backendtrafficpolicy"), func() {
3032
s := scaffold.NewDefaultScaffold()
3133

32-
var defaultGatewayProxy = `
34+
var gatewayProxyYaml = `
35+
apiVersion: apisix.apache.org/v1alpha1
36+
kind: GatewayProxy
37+
metadata:
38+
name: apisix-proxy-config
39+
spec:
40+
provider:
41+
type: ControlPlane
42+
controlPlane:
43+
service:
44+
name: %s
45+
port: 9180
46+
auth:
47+
type: AdminKey
48+
adminKey:
49+
value: "%s"
50+
`
51+
var gatewayProxyYamlAPI7 = `
3352
apiVersion: apisix.apache.org/v1alpha1
3453
kind: GatewayProxy
3554
metadata:
@@ -45,6 +64,12 @@ spec:
4564
adminKey:
4665
value: "%s"
4766
`
67+
getGatewayProxySpec := func() string {
68+
if s.Deployer.Name() == adc.BackendModeAPI7EE {
69+
return fmt.Sprintf(gatewayProxyYamlAPI7, s.Deployer.GetAdminEndpoint(), s.AdminKey())
70+
}
71+
return fmt.Sprintf(gatewayProxyYaml, framework.ProviderType, s.AdminKey())
72+
}
4873

4974
var defaultGatewayClass = `
5075
apiVersion: gateway.networking.k8s.io/v1
@@ -125,7 +150,7 @@ spec:
125150
`
126151

127152
BeforeEach(func() {
128-
s.ApplyDefaultGatewayResource(defaultGatewayProxy, defaultGatewayClass, defaultGateway, defaultHTTPRoute)
153+
s.ApplyDefaultGatewayResource(getGatewayProxySpec(), defaultGatewayClass, defaultGateway, defaultHTTPRoute)
129154
})
130155
It("should rewrite upstream host", func() {
131156
s.ResourceApplied("BackendTrafficPolicy", "httpbin", createUpstreamHost, 1)

test/e2e/crds/v1alpha1/consumer.go

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,40 @@
1818
package v1alpha1
1919

2020
import (
21+
"context"
2122
"fmt"
23+
"time"
2224

2325
. "github.com/onsi/ginkgo/v2"
2426
. "github.com/onsi/gomega"
27+
"k8s.io/apimachinery/pkg/util/wait"
2528

29+
"github.com/apache/apisix-ingress-controller/internal/provider/adc"
30+
"github.com/apache/apisix-ingress-controller/test/e2e/framework"
2631
"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
2732
)
2833

2934
var _ = Describe("Test Consumer", Label("apisix.apache.org", "v1alpha1", "consumer"), func() {
3035
s := scaffold.NewDefaultScaffold()
3136

32-
var defaultGatewayProxy = `
37+
var gatewayProxyYaml = `
38+
apiVersion: apisix.apache.org/v1alpha1
39+
kind: GatewayProxy
40+
metadata:
41+
name: apisix-proxy-config
42+
spec:
43+
provider:
44+
type: ControlPlane
45+
controlPlane:
46+
service:
47+
name: %s
48+
port: 9180
49+
auth:
50+
type: AdminKey
51+
adminKey:
52+
value: "%s"
53+
`
54+
var gatewayProxyYamlAPI7 = `
3355
apiVersion: apisix.apache.org/v1alpha1
3456
kind: GatewayProxy
3557
metadata:
@@ -45,6 +67,12 @@ spec:
4567
adminKey:
4668
value: "%s"
4769
`
70+
getGatewayProxySpec := func() string {
71+
if s.Deployer.Name() == adc.BackendModeAPI7EE {
72+
return fmt.Sprintf(gatewayProxyYamlAPI7, s.Deployer.GetAdminEndpoint(), s.AdminKey())
73+
}
74+
return fmt.Sprintf(gatewayProxyYaml, framework.ProviderType, s.AdminKey())
75+
}
4876

4977
var defaultGatewayClass = `
5078
apiVersion: gateway.networking.k8s.io/v1
@@ -152,7 +180,7 @@ spec:
152180
`
153181

154182
BeforeEach(func() {
155-
s.ApplyDefaultGatewayResource(defaultGatewayProxy, defaultGatewayClass, defaultGateway, defaultHTTPRoute)
183+
s.ApplyDefaultGatewayResource(getGatewayProxySpec(), defaultGatewayClass, defaultGateway, defaultHTTPRoute)
156184
})
157185

158186
It("limit-count plugin", func() {
@@ -248,7 +276,7 @@ spec:
248276
`
249277

250278
BeforeEach(func() {
251-
s.ApplyDefaultGatewayResource(defaultGatewayProxy, defaultGatewayClass, defaultGateway, defaultHTTPRoute)
279+
s.ApplyDefaultGatewayResource(getGatewayProxySpec(), defaultGatewayClass, defaultGateway, defaultHTTPRoute)
252280
})
253281

254282
It("Create/Update/Delete", func() {
@@ -397,7 +425,7 @@ spec:
397425
`
398426

399427
BeforeEach(func() {
400-
s.ApplyDefaultGatewayResource(defaultGatewayProxy, defaultGatewayClass, defaultGateway, defaultHTTPRoute)
428+
s.ApplyDefaultGatewayResource(getGatewayProxySpec(), defaultGatewayClass, defaultGateway, defaultHTTPRoute)
401429
})
402430
It("Create/Update/Delete", func() {
403431
err := s.CreateResourceFromString(keyAuthSecret)
@@ -518,7 +546,7 @@ spec:
518546
`
519547

520548
BeforeEach(func() {
521-
s.ApplyDefaultGatewayResource(defaultGatewayProxy, defaultGatewayClass, defaultGateway, defaultHTTPRoute)
549+
s.ApplyDefaultGatewayResource(getGatewayProxySpec(), defaultGatewayClass, defaultGateway, defaultHTTPRoute)
522550
})
523551

524552
It("Should sync consumer when GatewayProxy is updated", func() {
@@ -611,10 +639,10 @@ spec:
611639
`
612640

613641
BeforeEach(func() {
614-
s.ApplyDefaultGatewayResource(defaultGatewayProxy, defaultGatewayClass, defaultGateway, defaultHTTPRoute)
642+
s.ApplyDefaultGatewayResource(getGatewayProxySpec(), defaultGatewayClass, defaultGateway, defaultHTTPRoute)
615643
})
616644

617-
It("Should sync Consumer during startup", func() {
645+
FIt("Should sync Consumer during startup", func() {
618646
Expect(s.CreateResourceFromString(consumer2)).NotTo(HaveOccurred(), "creating unused consumer")
619647
s.ResourceApplied("Consumer", "consumer-sample", consumer1, 1)
620648

@@ -644,6 +672,17 @@ spec:
644672
s.Deployer.ScaleDataplane(1)
645673
s.Deployer.ScaleIngress(1)
646674

675+
By("check pod ready")
676+
err := wait.PollUntilContextTimeout(context.Background(), time.Second, 60*time.Second, true, func(ctx context.Context) (done bool, err error) {
677+
endpoints := s.GetEndpoints(s.Namespace(), framework.ProviderType)
678+
if len(endpoints.Subsets) != 1 || len(endpoints.Subsets[0].Addresses) != 1 {
679+
return false, nil
680+
}
681+
return true, nil
682+
})
683+
Expect(err).NotTo(HaveOccurred(), "check pods ready")
684+
685+
By("check consumer sync")
647686
s.RequestAssert(&scaffold.RequestAssert{
648687
Method: "GET",
649688
Path: "/get",

test/e2e/framework/manifests/ingress.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ data:
341341
# The period between two consecutive syncs.
342342
# The default value is 0 seconds, which means the controller will not sync.
343343
# If you want to enable the sync, set it to a positive value.
344-
init_sync_delay: {{ .InitSyncDelay | default "1m" }}
344+
init_sync_delay: {{ .InitSyncDelay | default "20m" }}
345345
---
346346
apiVersion: v1
347347
kind: Service

test/e2e/scaffold/assertion.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,7 @@ func WithExpectedHeaders(expectedHeaders map[string]string) ResponseCheckFunc {
150150
}
151151

152152
func (s *Scaffold) RequestAssert(r *RequestAssert) bool {
153-
if r.Client == nil {
154-
r.Client = s.NewAPISIXClient()
155-
}
153+
r.Client = s.NewAPISIXClient()
156154
if r.Method == "" {
157155
if len(r.Body) > 0 {
158156
r.Method = "POST"
@@ -188,7 +186,18 @@ func (s *Scaffold) RequestAssert(r *RequestAssert) bool {
188186
if r.BasicAuth != nil {
189187
req = req.WithBasicAuth(r.BasicAuth.Username, r.BasicAuth.Password)
190188
}
191-
expResp := req.Expect()
189+
var err error
190+
expResp, err := func() (*httpexpect.Response, error) {
191+
defer func() {
192+
if rec := recover(); rec != nil {
193+
err = fmt.Errorf("panic in Expect(): %v", rec)
194+
}
195+
}()
196+
return req.Expect(), nil
197+
}()
198+
if err != nil {
199+
return err
200+
}
192201

193202
resp := &HTTPResponse{
194203
Response: expResp.Raw(),

test/e2e/scaffold/k8s.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,7 @@ func (s *Scaffold) ApplyDefaultGatewayResource(
203203
defaultGateway string,
204204
defaultHTTPRoute string,
205205
) {
206-
By("create GatewayProxy")
207-
gatewayProxy := fmt.Sprintf(defaultGatewayProxy, s.Deployer.GetAdminEndpoint(), s.AdminKey())
208-
err := s.CreateResourceFromString(gatewayProxy)
206+
err := s.CreateResourceFromString(defaultGatewayProxy)
209207
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy")
210208
time.Sleep(5 * time.Second)
211209

0 commit comments

Comments
 (0)