|
18 | 18 | package v1alpha1 |
19 | 19 |
|
20 | 20 | import ( |
| 21 | + "context" |
21 | 22 | "fmt" |
| 23 | + "time" |
22 | 24 |
|
23 | 25 | . "github.com/onsi/ginkgo/v2" |
24 | 26 | . "github.com/onsi/gomega" |
| 27 | + "k8s.io/apimachinery/pkg/util/wait" |
25 | 28 |
|
| 29 | + "github.com/apache/apisix-ingress-controller/internal/provider/adc" |
| 30 | + "github.com/apache/apisix-ingress-controller/test/e2e/framework" |
26 | 31 | "github.com/apache/apisix-ingress-controller/test/e2e/scaffold" |
27 | 32 | ) |
28 | 33 |
|
29 | 34 | var _ = Describe("Test Consumer", Label("apisix.apache.org", "v1alpha1", "consumer"), func() { |
30 | 35 | s := scaffold.NewDefaultScaffold() |
31 | 36 |
|
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 = ` |
33 | 55 | apiVersion: apisix.apache.org/v1alpha1 |
34 | 56 | kind: GatewayProxy |
35 | 57 | metadata: |
|
45 | 67 | adminKey: |
46 | 68 | value: "%s" |
47 | 69 | ` |
| 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 | + } |
48 | 76 |
|
49 | 77 | var defaultGatewayClass = ` |
50 | 78 | apiVersion: gateway.networking.k8s.io/v1 |
@@ -152,7 +180,7 @@ spec: |
152 | 180 | ` |
153 | 181 |
|
154 | 182 | BeforeEach(func() { |
155 | | - s.ApplyDefaultGatewayResource(defaultGatewayProxy, defaultGatewayClass, defaultGateway, defaultHTTPRoute) |
| 183 | + s.ApplyDefaultGatewayResource(getGatewayProxySpec(), defaultGatewayClass, defaultGateway, defaultHTTPRoute) |
156 | 184 | }) |
157 | 185 |
|
158 | 186 | It("limit-count plugin", func() { |
@@ -248,7 +276,7 @@ spec: |
248 | 276 | ` |
249 | 277 |
|
250 | 278 | BeforeEach(func() { |
251 | | - s.ApplyDefaultGatewayResource(defaultGatewayProxy, defaultGatewayClass, defaultGateway, defaultHTTPRoute) |
| 279 | + s.ApplyDefaultGatewayResource(getGatewayProxySpec(), defaultGatewayClass, defaultGateway, defaultHTTPRoute) |
252 | 280 | }) |
253 | 281 |
|
254 | 282 | It("Create/Update/Delete", func() { |
@@ -397,7 +425,7 @@ spec: |
397 | 425 | ` |
398 | 426 |
|
399 | 427 | BeforeEach(func() { |
400 | | - s.ApplyDefaultGatewayResource(defaultGatewayProxy, defaultGatewayClass, defaultGateway, defaultHTTPRoute) |
| 428 | + s.ApplyDefaultGatewayResource(getGatewayProxySpec(), defaultGatewayClass, defaultGateway, defaultHTTPRoute) |
401 | 429 | }) |
402 | 430 | It("Create/Update/Delete", func() { |
403 | 431 | err := s.CreateResourceFromString(keyAuthSecret) |
@@ -518,7 +546,7 @@ spec: |
518 | 546 | ` |
519 | 547 |
|
520 | 548 | BeforeEach(func() { |
521 | | - s.ApplyDefaultGatewayResource(defaultGatewayProxy, defaultGatewayClass, defaultGateway, defaultHTTPRoute) |
| 549 | + s.ApplyDefaultGatewayResource(getGatewayProxySpec(), defaultGatewayClass, defaultGateway, defaultHTTPRoute) |
522 | 550 | }) |
523 | 551 |
|
524 | 552 | It("Should sync consumer when GatewayProxy is updated", func() { |
@@ -611,10 +639,10 @@ spec: |
611 | 639 | ` |
612 | 640 |
|
613 | 641 | BeforeEach(func() { |
614 | | - s.ApplyDefaultGatewayResource(defaultGatewayProxy, defaultGatewayClass, defaultGateway, defaultHTTPRoute) |
| 642 | + s.ApplyDefaultGatewayResource(getGatewayProxySpec(), defaultGatewayClass, defaultGateway, defaultHTTPRoute) |
615 | 643 | }) |
616 | 644 |
|
617 | | - It("Should sync Consumer during startup", func() { |
| 645 | + FIt("Should sync Consumer during startup", func() { |
618 | 646 | Expect(s.CreateResourceFromString(consumer2)).NotTo(HaveOccurred(), "creating unused consumer") |
619 | 647 | s.ResourceApplied("Consumer", "consumer-sample", consumer1, 1) |
620 | 648 |
|
@@ -644,6 +672,17 @@ spec: |
644 | 672 | s.Deployer.ScaleDataplane(1) |
645 | 673 | s.Deployer.ScaleIngress(1) |
646 | 674 |
|
| 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") |
647 | 686 | s.RequestAssert(&scaffold.RequestAssert{ |
648 | 687 | Method: "GET", |
649 | 688 | Path: "/get", |
|
0 commit comments