diff --git a/.github/workflows/apisix-conformance-test.yml b/.github/workflows/apisix-conformance-test.yml index 2dceb9231..a60d9a405 100644 --- a/.github/workflows/apisix-conformance-test.yml +++ b/.github/workflows/apisix-conformance-test.yml @@ -56,7 +56,7 @@ jobs: go install sigs.k8s.io/kind@v0.23.0 - name: Login to Registry - uses: docker/login-action@v1 + uses: docker/login-action@v3 with: registry: ${{ secrets.DOCKER_REGISTRY }} username: ${{ secrets.DOCKER_USERNAME }} diff --git a/.github/workflows/apisix-e2e-test.yml b/.github/workflows/apisix-e2e-test.yml index cfd92e8b3..8c8fcb10e 100644 --- a/.github/workflows/apisix-e2e-test.yml +++ b/.github/workflows/apisix-e2e-test.yml @@ -57,12 +57,16 @@ jobs: go install sigs.k8s.io/kind@v0.23.0 - name: Login to Registry - uses: docker/login-action@v1 + uses: docker/login-action@v3 with: registry: ${{ secrets.DOCKER_REGISTRY }} username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} + - name: Install ginkgo + run: | + make install-ginkgo + - name: Build images env: TAG: dev @@ -103,4 +107,4 @@ jobs: TEST_LABEL: ${{ matrix.cases_subset }} TEST_ENV: CI run: | - make e2e-test + make ginkgo-e2e-test diff --git a/.github/workflows/conformance-test.yml b/.github/workflows/conformance-test.yml index 3db73b43c..2550f4139 100644 --- a/.github/workflows/conformance-test.yml +++ b/.github/workflows/conformance-test.yml @@ -69,14 +69,14 @@ jobs: with: go-version: "1.23" - name: Login to Registry - uses: docker/login-action@v1 + uses: docker/login-action@v3 with: registry: ${{ secrets.DOCKER_REGISTRY }} username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Login to Private Registry - uses: docker/login-action@v1 + uses: docker/login-action@v3 with: registry: hkccr.ccs.tencentyun.com username: ${{ secrets.PRIVATE_DOCKER_USERNAME }} diff --git a/.github/workflows/e2e-test-k8s.yml b/.github/workflows/e2e-test-k8s.yml index e880cf391..be281c86d 100644 --- a/.github/workflows/e2e-test-k8s.yml +++ b/.github/workflows/e2e-test-k8s.yml @@ -15,7 +15,7 @@ # specific language governing permissions and limitations # under the License. -name: E2E Test For Kubernetes +name: API7EE E2E Test For Kubernetes 1.18 on: push: @@ -57,14 +57,14 @@ jobs: ./get_helm.sh - name: Login to Registry - uses: docker/login-action@v1 + uses: docker/login-action@v3 with: registry: ${{ secrets.DOCKER_REGISTRY }} username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Login to Private Registry - uses: docker/login-action@v1 + uses: docker/login-action@v3 with: registry: hkccr.ccs.tencentyun.com username: ${{ secrets.PRIVATE_DOCKER_USERNAME }} diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index 5de928cb3..1bfadd3ff 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -15,7 +15,7 @@ # specific language governing permissions and limitations # under the License. -name: E2E Test +name: API7EE E2E Test on: push: @@ -29,15 +29,21 @@ concurrency: cancel-in-progress: true jobs: - prepare: - name: Prepare + e2e-test: + strategy: + matrix: + cases_subset: + - apisix.apache.org + - networking.k8s.io + fail-fast: false runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 + with: + submodules: recursive - name: Setup Go Env - id: go uses: actions/setup-go@v4 with: go-version: "1.23" @@ -51,31 +57,15 @@ jobs: curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 chmod 700 get_helm.sh ./get_helm.sh - - e2e-test: - needs: - - prepare - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - submodules: recursive - - - name: Setup Go Env - uses: actions/setup-go@v4 - with: - go-version: "1.23" - - name: Login to Registry - uses: docker/login-action@v1 + uses: docker/login-action@v3 with: registry: ${{ secrets.DOCKER_REGISTRY }} username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Login to Private Registry - uses: docker/login-action@v1 + uses: docker/login-action@v3 with: registry: hkccr.ccs.tencentyun.com username: ${{ secrets.PRIVATE_DOCKER_USERNAME }} @@ -121,6 +111,7 @@ jobs: env: API7_EE_LICENSE: ${{ secrets.API7_EE_LICENSE }} PROVIDER_TYPE: api7ee + TEST_LABEL: ${{ matrix.cases_subset }} TEST_ENV: CI run: | make e2e-test diff --git a/.github/workflows/push-docker-v2-dev.yaml b/.github/workflows/push-docker-v2-dev.yaml index 53d91f4dc..d6b26cd46 100644 --- a/.github/workflows/push-docker-v2-dev.yaml +++ b/.github/workflows/push-docker-v2-dev.yaml @@ -44,7 +44,7 @@ jobs: # uses: docker/setup-buildx-action@v3 - name: Login to Registry - uses: docker/login-action@v1 + uses: docker/login-action@v3 with: registry: ${{ secrets.DOCKER_REGISTRY }} username: ${{ secrets.DOCKER_USERNAME }} diff --git a/Makefile b/Makefile index ec6ed84ce..2dc916d6d 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ ADC_VERSION ?= 0.20.0 GINKGO_VERSION ?= 2.20.0 TEST_TIMEOUT ?= 80m TEST_DIR ?= ./test/e2e/ -E2E_NODES ?= 2 +E2E_NODES ?= 4 # CRD Reference Documentation CRD_REF_DOCS_VERSION ?= v0.1.0 @@ -49,7 +49,7 @@ INGRESS_VERSION ?= v1 export KUBECONFIG = /tmp/$(KIND_NAME).kubeconfig -# go +# go VERSYM="github.com/apache/apisix-ingress-controller/internal/version._buildVersion" GITSHASYM="github.com/apache/apisix-ingress-controller/internal/version._buildGitRevision" BUILDOSSYM="github.com/apache/apisix-ingress-controller/internal/version._buildOS" @@ -146,7 +146,7 @@ download-api7ee3-chart: .PHONY: ginkgo-e2e-test ginkgo-e2e-test: - @ginkgo -cover -coverprofile=coverage.txt -r --randomize-all --randomize-suites --trace --focus=$(E2E_FOCUS) --nodes=$(E2E_NODES) $(TEST_DIR) + @ginkgo -cover -coverprofile=coverage.txt -r --randomize-all --randomize-suites --trace --focus=$(E2E_FOCUS) --nodes=$(E2E_NODES) --label-filter="$(TEST_LABEL)" $(TEST_DIR) .PHONY: install-ginkgo install-ginkgo: diff --git a/internal/controller/apisixglobalrule_controller.go b/internal/controller/apisixglobalrule_controller.go index d00db78cd..54fceb4a3 100644 --- a/internal/controller/apisixglobalrule_controller.go +++ b/internal/controller/apisixglobalrule_controller.go @@ -98,7 +98,7 @@ func (r *ApisixGlobalRuleReconciler) Reconcile(ctx context.Context, req ctrl.Req // process IngressClass parameters if they reference GatewayProxy if err := ProcessIngressClassParameters(tctx, r.Client, r.Log, &globalRule, ingressClass); err != nil { r.Log.Error(err, "failed to process IngressClass parameters", "ingressClass", ingressClass.Name) - return ctrl.Result{}, err + return ctrl.Result{}, client.IgnoreNotFound(err) } // Sync the global rule to APISIX diff --git a/internal/controller/apisixtls_controller.go b/internal/controller/apisixtls_controller.go index f5a0cc064..4cea079c0 100644 --- a/internal/controller/apisixtls_controller.go +++ b/internal/controller/apisixtls_controller.go @@ -145,7 +145,7 @@ func (r *ApisixTlsReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( Reason: string(apiv2.ConditionReasonInvalidSpec), Message: err.Error(), }) - return ctrl.Result{}, err + return ctrl.Result{}, client.IgnoreNotFound(err) } // process ApisixTls validation @@ -159,7 +159,7 @@ func (r *ApisixTlsReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( Reason: string(apiv2.ConditionReasonInvalidSpec), Message: err.Error(), }) - return ctrl.Result{}, err + return ctrl.Result{}, client.IgnoreNotFound(err) } if err := r.Provider.Update(ctx, tctx, &tls); err != nil { diff --git a/internal/controller/consumer_controller.go b/internal/controller/consumer_controller.go index 7869ad6b4..20907a753 100644 --- a/internal/controller/consumer_controller.go +++ b/internal/controller/consumer_controller.go @@ -19,6 +19,7 @@ package controller import ( "context" + "fmt" "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" @@ -36,6 +37,7 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" "github.com/apache/apisix-ingress-controller/api/v1alpha1" + "github.com/apache/apisix-ingress-controller/internal/controller/config" "github.com/apache/apisix-ingress-controller/internal/controller/indexer" "github.com/apache/apisix-ingress-controller/internal/controller/status" "github.com/apache/apisix-ingress-controller/internal/manager/readiness" @@ -208,8 +210,10 @@ func (r *ConsumerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c gateway, err := r.getGateway(ctx, consumer) if err != nil { - r.Log.Error(err, "failed to get gateway", "consumer", consumer) - statusErr = err + r.Log.V(1).Info("no matching Gateway available", + "gatewayRef", consumer.Spec.GatewayRef, + "error", err.Error()) + return ctrl.Result{}, nil } rk := utils.NamespacedNameKind(consumer) @@ -295,8 +299,17 @@ func (r *ConsumerReconciler) getGateway(ctx context.Context, consumer *v1alpha1. Name: consumer.Spec.GatewayRef.Name, Namespace: ns, }, gateway); err != nil { - r.Log.Error(err, "failed to get gateway", "gateway", consumer.Spec.GatewayRef.Name) - return nil, err + return nil, fmt.Errorf("failed to get gateway %s/%s: %w", ns, consumer.Spec.GatewayRef.Name, err) + } + gatewayClass := gatewayv1.GatewayClass{} + if err := r.Get(ctx, client.ObjectKey{ + Name: string(gateway.Spec.GatewayClassName), + }, &gatewayClass); err != nil { + return nil, fmt.Errorf("failed to retrieve gatewayclass for gateway: %w", err) + } + + if string(gatewayClass.Spec.ControllerName) != config.ControllerConfig.ControllerName { + return nil, fmt.Errorf("gateway %s/%s is not managed by this controller", gateway.Namespace, gateway.Name) } return gateway, nil } diff --git a/internal/controller/ingressclass_controller.go b/internal/controller/ingressclass_controller.go index 444c39b1d..b0cea10e9 100644 --- a/internal/controller/ingressclass_controller.go +++ b/internal/controller/ingressclass_controller.go @@ -98,7 +98,7 @@ func (r *IngressClassReconciler) Reconcile(ctx context.Context, req ctrl.Request if err := ProcessIngressClassParameters(tctx, r.Client, r.Log, ingressClass, ingressClass); err != nil { r.Log.Error(err, "failed to process infrastructure for ingressclass", "ingressclass", ingressClass.GetName()) - return ctrl.Result{}, err + return ctrl.Result{}, client.IgnoreNotFound(err) } if err := r.Provider.Update(ctx, tctx, ingressClass); err != nil { diff --git a/test/conformance/apisix/suite_test.go b/test/conformance/apisix/suite_test.go index 2d5dc6fe6..75b45cad1 100644 --- a/test/conformance/apisix/suite_test.go +++ b/test/conformance/apisix/suite_test.go @@ -125,9 +125,7 @@ func TestMain(m *testing.M) { f := framework.NewFramework() // init newDeployer function - scaffold.NewDeployer = func(s *scaffold.Scaffold) scaffold.Deployer { - return scaffold.NewAPISIXDeployer(s) - } + scaffold.NewDeployer = scaffold.NewAPISIXDeployer // Check and delete specific namespaces if they exist kubectl := k8s.NewKubectlOptions("", "", "default") @@ -140,13 +138,16 @@ func TestMain(m *testing.M) { k8s.CreateNamespace(GinkgoT(), kubectl, namespace) defer k8s.DeleteNamespace(GinkgoT(), kubectl, namespace) - s := scaffold.NewScaffold(&scaffold.Options{ - ControllerName: "apisix.apache.org/apisix-ingress-controller", + adminkey := getEnvOrDefault("APISIX_ADMIN_KEY", "edd1c9f034335f136f87ad84b625c8f1") + controllerName := "apisix.apache.org/apisix-ingress-controller" + s := scaffold.NewScaffold(scaffold.Options{ + ControllerName: controllerName, SkipHooks: true, - APISIXAdminAPIKey: getEnvOrDefault("APISIX_ADMIN_KEY", "edd1c9f034335f136f87ad84b625c8f1"), + APISIXAdminAPIKey: adminkey, }) s.Deployer.DeployDataplane(scaffold.DeployDataplaneOptions{ + AdminKey: adminkey, Namespace: namespace, SkipCreateTunnels: true, ServiceType: "LoadBalancer", @@ -162,7 +163,7 @@ func TestMain(m *testing.M) { address := svc.Status.LoadBalancer.Ingress[0].IP f.DeployIngress(framework.IngressDeployOpts{ - ControllerName: s.GetControllerName(), + ControllerName: controllerName, Namespace: namespace, StatusAddress: address, InitSyncDelay: 20 * time.Minute, @@ -174,7 +175,7 @@ func TestMain(m *testing.M) { defaultGatewayProxyOpts = GatewayProxyOpts{ StatusAddress: address, - AdminKey: s.AdminKey(), + AdminKey: adminkey, AdminEndpoint: adminEndpoint, } diff --git a/test/e2e/crds/v1alpha1/backendtrafficpolicy.go b/test/e2e/crds/v1alpha1/backendtrafficpolicy.go index dcdf24d80..bfb2ef890 100644 --- a/test/e2e/crds/v1alpha1/backendtrafficpolicy.go +++ b/test/e2e/crds/v1alpha1/backendtrafficpolicy.go @@ -19,51 +19,30 @@ package v1alpha1 import ( "fmt" + "time" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "k8s.io/apimachinery/pkg/types" "github.com/apache/apisix-ingress-controller/test/e2e/scaffold" ) var _ = Describe("Test BackendTrafficPolicy base on HTTPRoute", Label("apisix.apache.org", "v1alpha1", "backendtrafficpolicy"), func() { - s := scaffold.NewDefaultScaffold() - - var defaultGatewayClass = ` -apiVersion: gateway.networking.k8s.io/v1 -kind: GatewayClass -metadata: - name: %s -spec: - controllerName: %s -` - - var defaultGateway = ` -apiVersion: gateway.networking.k8s.io/v1 -kind: Gateway -metadata: - name: apisix -spec: - gatewayClassName: %s - listeners: - - name: http1 - protocol: HTTP - port: 80 - infrastructure: - parametersRef: - group: apisix.apache.org - kind: GatewayProxy - name: apisix-proxy-config -` + var ( + s = scaffold.NewDefaultScaffold() + err error + ) var defaultHTTPRoute = ` apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin + namespace: %s spec: parentRefs: - - name: apisix + - name: %s hostnames: - "httpbin.org" rules: @@ -108,8 +87,25 @@ spec: ` BeforeEach(func() { - s.ApplyDefaultGatewayResource(s.GetGatewayProxySpec(), defaultGatewayClass, defaultGateway, defaultHTTPRoute) + By("create GatewayProxy") + err = s.CreateResourceFromString(s.GetGatewayProxySpec()) + Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy") + time.Sleep(5 * time.Second) + + By("create GatewayClass") + err = s.CreateResourceFromString(s.GetGatewayClassYaml()) + Expect(err).NotTo(HaveOccurred(), "creating GatewayClass") + time.Sleep(5 * time.Second) + + By("create Gateway") + err = s.CreateResourceFromString(s.GetGatewayYaml()) + Expect(err).NotTo(HaveOccurred(), "creating Gateway") + time.Sleep(5 * time.Second) + + By("create HTTPRoute") + s.ApplyHTTPRoute(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin"}, fmt.Sprintf(defaultHTTPRoute, s.Namespace(), s.Namespace())) }) + It("should rewrite upstream host", func() { s.ResourceApplied("BackendTrafficPolicy", "httpbin", createUpstreamHost, 1) s.RequestAssert(&scaffold.RequestAssert{ @@ -166,27 +162,8 @@ spec: }) var _ = Describe("Test BackendTrafficPolicy base on Ingress", Label("apisix.apache.org", "v1alpha1", "backendtrafficpolicy"), func() { - s := scaffold.NewScaffold(&scaffold.Options{ - ControllerName: "apisix.apache.org/apisix-ingress-controller", - }) + s := scaffold.NewDefaultScaffold() - var defaultGatewayProxy = ` -apiVersion: apisix.apache.org/v1alpha1 -kind: GatewayProxy -metadata: - name: apisix-proxy-config - namespace: default -spec: - provider: - type: ControlPlane - controlPlane: - endpoints: - - %s - auth: - type: AdminKey - adminKey: - value: "%s" -` var defaultIngressClass = ` apiVersion: networking.k8s.io/v1 kind: IngressClass @@ -195,12 +172,12 @@ metadata: annotations: ingressclass.kubernetes.io/is-default-class: "true" spec: - controller: "apisix.apache.org/apisix-ingress-controller" + controller: %s parameters: apiGroup: "apisix.apache.org" kind: "GatewayProxy" name: "apisix-proxy-config" - namespace: "default" + namespace: %s scope: "Namespace" ` @@ -224,12 +201,12 @@ spec: ` var beforeEach = func() { By("create GatewayProxy") - gatewayProxy := fmt.Sprintf(defaultGatewayProxy, s.Deployer.GetAdminEndpoint(), s.AdminKey()) - err := s.CreateResourceFromStringWithNamespace(gatewayProxy, "default") + err := s.CreateResourceFromString(s.GetGatewayProxySpec()) Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy") + time.Sleep(5 * time.Second) By("create IngressClass with GatewayProxy reference") - err = s.CreateResourceFromStringWithNamespace(defaultIngressClass, "") + err = s.CreateResourceFromString(fmt.Sprintf(defaultIngressClass, s.GetControllerName(), s.Namespace())) Expect(err).NotTo(HaveOccurred(), "creating IngressClass with GatewayProxy") By("create Ingress with GatewayProxy IngressClass") @@ -237,12 +214,14 @@ spec: Expect(err).NotTo(HaveOccurred(), "creating Ingress with GatewayProxy IngressClass") } - Context("Rewrite Upstream Host", func() { + // Tests concerning the default ingress class need to be run serially + Context("Rewrite Upstream Host", Serial, func() { var createUpstreamHost = ` apiVersion: apisix.apache.org/v1alpha1 kind: BackendTrafficPolicy metadata: name: httpbin + namespace: %s spec: targetRefs: - name: httpbin-service-e2e-test @@ -257,6 +236,7 @@ apiVersion: apisix.apache.org/v1alpha1 kind: BackendTrafficPolicy metadata: name: httpbin + namespace: %s spec: targetRefs: - name: httpbin-service-e2e-test @@ -276,19 +256,20 @@ spec: "Host": "httpbin.org", }, } - s.ResourceApplied("BackendTrafficPolicy", "httpbin", createUpstreamHost, 1) + + s.ResourceApplied("BackendTrafficPolicy", "httpbin", fmt.Sprintf(createUpstreamHost, s.Namespace()), 1) s.RequestAssert(reqAssert.SetChecks( scaffold.WithExpectedStatus(200), scaffold.WithExpectedBodyContains("httpbin.example.com"), )) - s.ResourceApplied("BackendTrafficPolicy", "httpbin", updateUpstreamHost, 2) + s.ResourceApplied("BackendTrafficPolicy", "httpbin", fmt.Sprintf(updateUpstreamHost, s.Namespace()), 2) s.RequestAssert(reqAssert.SetChecks( scaffold.WithExpectedStatus(200), scaffold.WithExpectedBodyContains("httpbin.update.example.com"), )) - err := s.DeleteResourceFromString(createUpstreamHost) + err := s.DeleteResourceFromString(fmt.Sprintf(createUpstreamHost, s.Namespace())) Expect(err).NotTo(HaveOccurred(), "deleting BackendTrafficPolicy") s.RequestAssert(reqAssert.SetChecks( diff --git a/test/e2e/crds/v1alpha1/consumer.go b/test/e2e/crds/v1alpha1/consumer.go index 415bd0b8e..27b3aab5e 100644 --- a/test/e2e/crds/v1alpha1/consumer.go +++ b/test/e2e/crds/v1alpha1/consumer.go @@ -24,13 +24,34 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "k8s.io/apimachinery/pkg/types" "github.com/apache/apisix-ingress-controller/test/e2e/framework" "github.com/apache/apisix-ingress-controller/test/e2e/scaffold" ) var _ = Describe("Test Consumer", Label("apisix.apache.org", "v1alpha1", "consumer"), func() { - s := scaffold.NewDefaultScaffold() + var ( + s = scaffold.NewDefaultScaffold() + err error + ) + + var defaultGatewayProxy = ` +apiVersion: apisix.apache.org/v1alpha1 +kind: GatewayProxy +metadata: + name: %s +spec: + provider: + type: ControlPlane + controlPlane: + endpoints: + - %s + auth: + type: AdminKey + adminKey: + value: "%s" +` var defaultGatewayClass = ` apiVersion: gateway.networking.k8s.io/v1 @@ -45,7 +66,7 @@ spec: apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: - name: apisix + name: %s spec: gatewayClassName: %s listeners: @@ -56,7 +77,7 @@ spec: parametersRef: group: apisix.apache.org kind: GatewayProxy - name: apisix-proxy-config + name: %s ` var defaultHTTPRoute = ` @@ -80,7 +101,7 @@ metadata: name: httpbin spec: parentRefs: - - name: apisix + - name: %s hostnames: - "httpbin.org" rules: @@ -99,6 +120,29 @@ spec: port: 80 ` + BeforeEach(func() { + gatewayName := s.Namespace() + By("create GatewayProxy") + gatewayProxyName := s.Namespace() + err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defaultGatewayProxy, gatewayProxyName, s.Deployer.GetAdminEndpoint(), s.AdminKey()), s.Namespace()) + Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy") + time.Sleep(time.Second) + + By("create GatewayClass") + gatewayClassName := s.Namespace() + err = s.CreateResourceFromString(fmt.Sprintf(defaultGatewayClass, gatewayClassName, s.GetControllerName())) + Expect(err).NotTo(HaveOccurred(), "creating GatewayClass") + time.Sleep(time.Second) + + By("create Gateway") + err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defaultGateway, gatewayName, gatewayClassName, gatewayProxyName), s.Namespace()) + Expect(err).NotTo(HaveOccurred(), "creating Gateway") + time.Sleep(time.Second) + + By("create HTTPRoute") + s.ApplyHTTPRoute(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin"}, fmt.Sprintf(defaultHTTPRoute, gatewayName)) + }) + Context("Consumer plugins", func() { var limitCountConsumer = ` apiVersion: apisix.apache.org/v1alpha1 @@ -107,7 +151,7 @@ metadata: name: consumer-sample spec: gatewayRef: - name: apisix + name: %s credentials: - type: key-auth name: key-auth-sample @@ -129,7 +173,7 @@ metadata: name: consumer-sample2 spec: gatewayRef: - name: apisix + name: %s credentials: - type: key-auth name: key-auth-sample @@ -137,13 +181,9 @@ spec: key: sample-key2 ` - BeforeEach(func() { - s.ApplyDefaultGatewayResource(s.GetGatewayProxySpec(), defaultGatewayClass, defaultGateway, defaultHTTPRoute) - }) - It("limit-count plugin", func() { - s.ResourceApplied("Consumer", "consumer-sample", limitCountConsumer, 1) - s.ResourceApplied("Consumer", "consumer-sample2", unlimitConsumer, 1) + s.ResourceApplied("Consumer", "consumer-sample", fmt.Sprintf(limitCountConsumer, s.Namespace()), 1) + s.ResourceApplied("Consumer", "consumer-sample2", fmt.Sprintf(unlimitConsumer, s.Namespace()), 1) s.RequestAssert(&scaffold.RequestAssert{ Method: "GET", @@ -198,7 +238,7 @@ metadata: name: consumer-sample spec: gatewayRef: - name: apisix + name: %s credentials: - type: basic-auth name: basic-auth-sample @@ -220,7 +260,7 @@ metadata: name: consumer-sample spec: gatewayRef: - name: apisix + name: %s credentials: - type: basic-auth name: basic-auth-sample @@ -233,12 +273,8 @@ spec: key: consumer-key ` - BeforeEach(func() { - s.ApplyDefaultGatewayResource(s.GetGatewayProxySpec(), defaultGatewayClass, defaultGateway, defaultHTTPRoute) - }) - It("Create/Update/Delete", func() { - s.ResourceApplied("Consumer", "consumer-sample", defaultCredential, 1) + s.ResourceApplied("Consumer", "consumer-sample", fmt.Sprintf(defaultCredential, s.Namespace()), 1) s.RequestAssert(&scaffold.RequestAssert{ Method: "GET", @@ -272,7 +308,7 @@ spec: }) By("update Consumer") - s.ResourceApplied("Consumer", "consumer-sample", updateCredential, 2) + s.ResourceApplied("Consumer", "consumer-sample", fmt.Sprintf(updateCredential, s.Namespace()), 2) s.RequestAssert(&scaffold.RequestAssert{ Method: "GET", @@ -316,7 +352,7 @@ spec: }) By("delete Consumer") - err := s.DeleteResourceFromString(updateCredential) + err := s.DeleteResourceFromString(fmt.Sprintf(updateCredential, s.Namespace())) Expect(err).NotTo(HaveOccurred(), "deleting Consumer") s.RequestAssert(&scaffold.RequestAssert{ @@ -366,7 +402,7 @@ metadata: name: consumer-sample spec: gatewayRef: - name: apisix + name: %s credentials: - type: basic-auth name: basic-auth-sample @@ -381,16 +417,12 @@ spec: config: key: sample-key2 ` - - BeforeEach(func() { - s.ApplyDefaultGatewayResource(s.GetGatewayProxySpec(), defaultGatewayClass, defaultGateway, defaultHTTPRoute) - }) It("Create/Update/Delete", func() { err := s.CreateResourceFromString(keyAuthSecret) Expect(err).NotTo(HaveOccurred(), "creating key-auth secret") err = s.CreateResourceFromString(basicAuthSecret) Expect(err).NotTo(HaveOccurred(), "creating basic-auth secret") - s.ResourceApplied("Consumer", "consumer-sample", defaultConsumer, 1) + s.ResourceApplied("Consumer", "consumer-sample", fmt.Sprintf(defaultConsumer, s.Namespace()), 1) s.RequestAssert(&scaffold.RequestAssert{ Method: "GET", @@ -442,7 +474,7 @@ spec: }) By("delete consumer") - err = s.DeleteResourceFromString(defaultConsumer) + err = s.DeleteResourceFromString(fmt.Sprintf(defaultConsumer, s.Namespace())) Expect(err).NotTo(HaveOccurred(), "deleting consumer") s.RequestAssert(&scaffold.RequestAssert{ @@ -478,7 +510,7 @@ metadata: name: consumer-sample spec: gatewayRef: - name: apisix + name: %s credentials: - type: basic-auth name: basic-auth-sample @@ -490,7 +522,7 @@ spec: apiVersion: apisix.apache.org/v1alpha1 kind: GatewayProxy metadata: - name: apisix-proxy-config + name: %s spec: provider: type: ControlPlane @@ -503,12 +535,8 @@ spec: value: "%s" ` - BeforeEach(func() { - s.ApplyDefaultGatewayResource(s.GetGatewayProxySpec(), defaultGatewayClass, defaultGateway, defaultHTTPRoute) - }) - It("Should sync consumer when GatewayProxy is updated", func() { - s.ResourceApplied("Consumer", "consumer-sample", defaultCredential, 1) + s.ResourceApplied("Consumer", "consumer-sample", fmt.Sprintf(defaultCredential, s.Namespace()), 1) // verify basic-auth works s.RequestAssert(&scaffold.RequestAssert{ @@ -547,8 +575,8 @@ spec: }) By("update GatewayProxy with new admin key") - updatedProxy := fmt.Sprintf(updatedGatewayProxy, s.Deployer.GetAdminEndpoint(resources.DataplaneService), resources.AdminAPIKey) - err = s.CreateResourceFromString(updatedProxy) + updatedProxy := fmt.Sprintf(updatedGatewayProxy, s.Namespace(), s.Deployer.GetAdminEndpoint(resources.DataplaneService), resources.AdminAPIKey) + err = s.CreateResourceFromStringWithNamespace(updatedProxy, s.Namespace()) Expect(err).NotTo(HaveOccurred(), "updating GatewayProxy") By("verify Consumer works for additional gateway group") @@ -574,7 +602,7 @@ metadata: name: consumer-sample spec: gatewayRef: - name: apisix + name: %s credentials: - type: key-auth name: key-auth-sample @@ -595,17 +623,12 @@ spec: config: key: sample-key2 ` - - BeforeEach(func() { - s.ApplyDefaultGatewayResource(s.GetGatewayProxySpec(), defaultGatewayClass, defaultGateway, defaultHTTPRoute) - }) - It("Should sync Consumer during startup", func() { if os.Getenv("PROVIDER_TYPE") == framework.ProviderTypeAPI7EE { Skip("skipping test in API7EE mode") } Expect(s.CreateResourceFromString(consumer2)).NotTo(HaveOccurred(), "creating unused consumer") - s.ResourceApplied("Consumer", "consumer-sample", consumer1, 1) + s.ResourceApplied("Consumer", "consumer-sample", fmt.Sprintf(consumer1, s.Namespace()), 1) s.RequestAssert(&scaffold.RequestAssert{ Method: "GET", diff --git a/test/e2e/crds/v1alpha1/gatewayproxy.go b/test/e2e/crds/v1alpha1/gatewayproxy.go index 69911cc01..112db6e34 100644 --- a/test/e2e/crds/v1alpha1/gatewayproxy.go +++ b/test/e2e/crds/v1alpha1/gatewayproxy.go @@ -63,6 +63,7 @@ spec: headers: "X-Pod-Hostname": "$hostname" ` + const gatewayProxySpecAPI7 = ` apiVersion: apisix.apache.org/v1alpha1 kind: GatewayProxy @@ -86,31 +87,6 @@ spec: "X-Pod-Hostname": "$hostname" ` - const gatewayClassSpec = ` -apiVersion: gateway.networking.k8s.io/v1 -kind: GatewayClass -metadata: - name: %s -spec: - controllerName: %s -` - const gatewaySpec = ` -apiVersion: gateway.networking.k8s.io/v1 -kind: Gateway -metadata: - name: apisix -spec: - gatewayClassName: %s - listeners: - - name: http1 - protocol: HTTP - port: 80 - infrastructure: - parametersRef: - group: apisix.apache.org - kind: GatewayProxy - name: apisix-proxy-config -` const httpRouteSpec = ` apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute @@ -118,7 +94,7 @@ metadata: name: httpbin spec: parentRefs: - - name: apisix + - name: %s hostnames: - "httpbin.org" rules: @@ -130,7 +106,9 @@ spec: - name: httpbin-service-e2e-test port: 80 ` + BeforeEach(func() { + gatewayName := s.Namespace() By("create GatewayProxy") if s.Deployer.Name() == framework.ProviderTypeAPI7EE { err = s.CreateResourceFromString(fmt.Sprintf(gatewayProxySpecAPI7, s.Deployer.GetAdminEndpoint(), s.AdminKey())) @@ -138,25 +116,24 @@ spec: err = s.CreateResourceFromString(fmt.Sprintf(gatewayProxySpec, framework.ProviderType, s.AdminKey())) } Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy") - time.Sleep(time.Second) + time.Sleep(5 * time.Second) By("create GatewayClass") - gatewayClassName := fmt.Sprintf("apisix-%d", time.Now().Unix()) - err = s.CreateResourceFromString(fmt.Sprintf(gatewayClassSpec, gatewayClassName, s.GetControllerName())) + err = s.CreateResourceFromString(s.GetGatewayClassYaml()) Expect(err).NotTo(HaveOccurred(), "creating GatewayClass") - time.Sleep(time.Second) + time.Sleep(5 * time.Second) By("create Gateway") - err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(gatewaySpec, gatewayClassName), s.Namespace()) + err = s.CreateResourceFromString(s.GetGatewayYaml()) Expect(err).NotTo(HaveOccurred(), "creating Gateway") - time.Sleep(time.Second) + time.Sleep(5 * time.Second) By("create HTTPRoute") - s.ApplyHTTPRoute(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin"}, httpRouteSpec) + s.ApplyHTTPRoute(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin"}, fmt.Sprintf(httpRouteSpec, gatewayName)) Eventually(func() int { return s.NewAPISIXClient().GET("/get").WithHost("httpbin.org").Expect().Raw().StatusCode - }).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) + }).WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) }) Context("Test GatewayProxy update configs", func() { @@ -207,10 +184,10 @@ spec: keyword string ) - if framework.ProviderType == framework.ProviderTypeAPISIX { - keyword = fmt.Sprintf(`{"config.ServerAddrs": ["%s"]}`, s.Deployer.GetAdminEndpoint()) - } else { + if framework.ProviderType == framework.ProviderTypeAPISIXStandalone { keyword = fmt.Sprintf(`{"config.ServerAddrs": ["http://%s:9180"]}`, s.GetPodIP(s.Namespace(), "app.kubernetes.io/name=apisix")) + } else { + keyword = fmt.Sprintf(`{"config.ServerAddrs": ["%s"]}`, s.Deployer.GetAdminEndpoint()) } By(fmt.Sprintf("wait for keyword: %s", keyword)) diff --git a/test/e2e/crds/v2/basic.go b/test/e2e/crds/v2/basic.go index 65b4d6195..7b197e107 100644 --- a/test/e2e/crds/v2/basic.go +++ b/test/e2e/crds/v2/basic.go @@ -31,42 +31,9 @@ import ( "github.com/apache/apisix-ingress-controller/test/e2e/scaffold" ) -const gatewayProxyYaml = ` -apiVersion: apisix.apache.org/v1alpha1 -kind: GatewayProxy -metadata: - name: apisix-proxy-config - namespace: default -spec: - provider: - type: ControlPlane - controlPlane: - endpoints: - - %s - auth: - type: AdminKey - adminKey: - value: "%s" -` - -const ingressClassYaml = ` -apiVersion: networking.k8s.io/%s -kind: IngressClass -metadata: - name: apisix -spec: - controller: "apisix.apache.org/apisix-ingress-controller" - parameters: - apiGroup: "apisix.apache.org" - kind: "GatewayProxy" - name: "apisix-proxy-config" -` - var _ = Describe("APISIX Standalone Basic Tests", Label("apisix.apache.org", "v2", "basic"), func() { var ( - s = scaffold.NewScaffold(&scaffold.Options{ - ControllerName: "apisix.apache.org/apisix-ingress-controller", - }) + s = scaffold.NewDefaultScaffold() applier = framework.NewApplier(s.GinkgoT, s.K8sClient, s.CreateResourceFromString) ) @@ -97,47 +64,13 @@ var _ = Describe("APISIX Standalone Basic Tests", Label("apisix.apache.org", "v2 Context("IngressClass Annotations", func() { It("Basic tests", func() { - const gatewayProxyYaml = ` -apiVersion: apisix.apache.org/v1alpha1 -kind: GatewayProxy -metadata: - name: apisix-proxy-config -spec: - provider: - type: ControlPlane - controlPlane: - endpoints: - - %s - auth: - type: AdminKey - adminKey: - value: "%s" -` - - const ingressClassYaml = ` -apiVersion: networking.k8s.io/%s -kind: IngressClass -metadata: - name: apisix - annotations: - apisix.apache.org/parameters-namespace: %s -spec: - controller: apisix.apache.org/apisix-ingress-controller - parameters: - apiGroup: apisix.apache.org - kind: GatewayProxy - name: apisix-proxy-config -` - By("create GatewayProxy") - gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Deployer.GetAdminEndpoint(), s.AdminKey()) - err := s.CreateResourceFromString(gatewayProxy) + err := s.CreateResourceFromString(s.GetGatewayProxySpec()) Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy") time.Sleep(5 * time.Second) By("create IngressClass") - ingressClass := fmt.Sprintf(ingressClassYaml, framework.IngressVersion, s.Namespace()) - err = s.CreateResourceFromStringWithNamespace(ingressClass, "") + err = s.CreateResourceFromStringWithNamespace(s.GetIngressClassYaml(), "") Expect(err).NotTo(HaveOccurred(), "creating IngressClass") time.Sleep(5 * time.Second) @@ -147,7 +80,7 @@ kind: ApisixRoute metadata: name: default spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule0 match: @@ -165,13 +98,15 @@ spec: By("apply ApisixRoute") var apisixRoute apiv2.ApisixRoute - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apisixRoute, fmt.Sprintf(apisixRouteSpec, "/get")) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apisixRoute, + fmt.Sprintf(apisixRouteSpec, s.Namespace(), "/get")) By("verify ApisixRoute works") Eventually(request).WithArguments("/get").WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) By("update ApisixRoute") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apisixRoute, fmt.Sprintf(apisixRouteSpec, "/headers")) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apisixRoute, + fmt.Sprintf(apisixRouteSpec, s.Namespace(), "/headers")) Eventually(request).WithArguments("/get").WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusNotFound)) s.RequestAssert(&scaffold.RequestAssert{ Method: "GET", diff --git a/test/e2e/crds/v2/consumer.go b/test/e2e/crds/v2/consumer.go index 20f5a228e..7a0425c13 100644 --- a/test/e2e/crds/v2/consumer.go +++ b/test/e2e/crds/v2/consumer.go @@ -35,22 +35,18 @@ type Headers map[string]string var _ = Describe("Test ApisixConsumer", Label("apisix.apache.org", "v2", "apisixconsumer"), func() { var ( - s = scaffold.NewScaffold(&scaffold.Options{ - ControllerName: "apisix.apache.org/apisix-ingress-controller", - }) + s = scaffold.NewDefaultScaffold() applier = framework.NewApplier(s.GinkgoT, s.K8sClient, s.CreateResourceFromString) ) BeforeEach(func() { By("create GatewayProxy") - gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Deployer.GetAdminEndpoint(), s.AdminKey()) - err := s.CreateResourceFromStringWithNamespace(gatewayProxy, "default") + err := s.CreateResourceFromString(s.GetGatewayProxySpec()) Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy") time.Sleep(5 * time.Second) By("create IngressClass") - ingressClass := fmt.Sprintf(ingressClassYaml, framework.IngressVersion) - err = s.CreateResourceFromStringWithNamespace(ingressClass, "") + err = s.CreateResourceFromStringWithNamespace(s.GetIngressClassYaml(), "") Expect(err).NotTo(HaveOccurred(), "creating IngressClass") time.Sleep(5 * time.Second) }) @@ -63,7 +59,7 @@ kind: ApisixConsumer metadata: name: test-consumer spec: - ingressClassName: apisix + ingressClassName: %s authParameter: keyAuth: value: @@ -75,7 +71,7 @@ kind: ApisixRoute metadata: name: default spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule0 match: @@ -116,7 +112,7 @@ kind: ApisixConsumer metadata: name: test-consumer spec: - ingressClassName: apisix + ingressClassName: %s authParameter: keyAuth: secretRef: @@ -129,10 +125,10 @@ spec: It("Basic tests", func() { By("apply ApisixRoute") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, defaultApisixRoute) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, fmt.Sprintf(defaultApisixRoute, s.Namespace())) By("apply ApisixConsumer") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-consumer"}, &apiv2.ApisixConsumer{}, keyAuth) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-consumer"}, &apiv2.ApisixConsumer{}, fmt.Sprintf(keyAuth, s.Namespace())) By("verify ApisixRoute with ApisixConsumer") Eventually(request).WithArguments("/get", Headers{ @@ -158,14 +154,16 @@ spec: It("SecretRef tests", func() { By("apply ApisixRoute") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, defaultApisixRoute) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, + fmt.Sprintf(defaultApisixRoute, s.Namespace())) By("apply Secret") err := s.CreateResourceFromString(secret) Expect(err).ShouldNot(HaveOccurred(), "creating Secret for ApisixConsumer") By("apply ApisixConsumer") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-consumer"}, &apiv2.ApisixConsumer{}, keyAuthWiwhSecret) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-consumer"}, &apiv2.ApisixConsumer{}, + fmt.Sprintf(keyAuthWiwhSecret, s.Namespace())) By("verify ApisixRoute with ApisixConsumer") Eventually(request).WithArguments("/get", Headers{ @@ -210,7 +208,7 @@ kind: ApisixConsumer metadata: name: test-consumer spec: - ingressClassName: apisix + ingressClassName: %s authParameter: basicAuth: value: @@ -223,7 +221,7 @@ kind: ApisixRoute metadata: name: default spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule0 match: @@ -268,7 +266,7 @@ kind: ApisixConsumer metadata: name: test-consumer spec: - ingressClassName: apisix + ingressClassName: %s authParameter: basicAuth: secretRef: @@ -278,10 +276,10 @@ spec: It("Basic tests", func() { By("apply ApisixRoute") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, defaultApisixRoute) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, fmt.Sprintf(defaultApisixRoute, s.Namespace())) By("apply ApisixConsumer") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-consumer"}, &apiv2.ApisixConsumer{}, basicAuth) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-consumer"}, &apiv2.ApisixConsumer{}, fmt.Sprintf(basicAuth, s.Namespace())) By("verify ApisixRoute with ApisixConsumer") s.RequestAssert(&scaffold.RequestAssert{ @@ -332,14 +330,16 @@ spec: It("SecretRef tests", func() { By("apply ApisixRoute") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, defaultApisixRoute) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, + fmt.Sprintf(defaultApisixRoute, s.Namespace())) By("apply Secret") err := s.CreateResourceFromString(secret) Expect(err).ShouldNot(HaveOccurred(), "creating Secret for ApisixConsumer") By("apply ApisixConsumer") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-consumer"}, &apiv2.ApisixConsumer{}, basicAuthWithSecret) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-consumer"}, + &apiv2.ApisixConsumer{}, fmt.Sprintf(basicAuthWithSecret, s.Namespace())) By("verify ApisixRoute with ApisixConsumer") s.RequestAssert(&scaffold.RequestAssert{ diff --git a/test/e2e/crds/v2/globalrule.go b/test/e2e/crds/v2/globalrule.go index 65bc47801..01c0637c7 100644 --- a/test/e2e/crds/v2/globalrule.go +++ b/test/e2e/crds/v2/globalrule.go @@ -25,22 +25,19 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/apache/apisix-ingress-controller/test/e2e/framework" "github.com/apache/apisix-ingress-controller/test/e2e/scaffold" ) var _ = Describe("Test GlobalRule", Label("apisix.apache.org", "v2", "apisixglobalrule"), func() { - s := scaffold.NewScaffold(&scaffold.Options{ - ControllerName: "apisix.apache.org/apisix-ingress-controller", - }) + s := scaffold.NewDefaultScaffold() - var defaultRoute = ` + var defaultRouteSpec = ` apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: default spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule0 match: @@ -56,19 +53,17 @@ spec: Context("ApisixGlobalRule Basic Operations", func() { BeforeEach(func() { By("create GatewayProxy") - gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Deployer.GetAdminEndpoint(), s.AdminKey()) - err := s.CreateResourceFromStringWithNamespace(gatewayProxy, "default") + err := s.CreateResourceFromString(s.GetGatewayProxySpec()) Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy") time.Sleep(5 * time.Second) By("create IngressClass") - ingressClass := fmt.Sprintf(ingressClassYaml, framework.IngressVersion) - err = s.CreateResourceFromStringWithNamespace(ingressClass, "") + err = s.CreateResourceFromStringWithNamespace(s.GetIngressClassYaml(), "") Expect(err).NotTo(HaveOccurred(), "creating IngressClass") time.Sleep(5 * time.Second) By("create ApisixRoute") - err = s.CreateResourceFromString(defaultRoute) + err = s.CreateResourceFromString(fmt.Sprintf(defaultRouteSpec, s.Namespace())) Expect(err).NotTo(HaveOccurred(), "creating ApisixRoute") time.Sleep(5 * time.Second) @@ -78,7 +73,7 @@ spec: GET("/get"). WithHost("globalrule.example.com"). Expect().Raw().StatusCode - }).WithTimeout(8 * time.Second).ProbeEvery(time.Second). + }).WithTimeout(20 * time.Second).ProbeEvery(time.Second). Should(Equal(http.StatusOK)) }) @@ -89,7 +84,7 @@ kind: ApisixGlobalRule metadata: name: test-global-rule-response-rewrite spec: - ingressClassName: apisix + ingressClassName: %s plugins: - name: response-rewrite enable: true @@ -100,7 +95,7 @@ spec: ` By("create ApisixGlobalRule with response-rewrite plugin") - err := s.CreateResourceFromString(globalRuleYaml) + err := s.CreateResourceFromString(fmt.Sprintf(globalRuleYaml, s.Namespace())) Expect(err).NotTo(HaveOccurred(), "creating ApisixGlobalRule") By("verify ApisixGlobalRule status condition") @@ -141,7 +136,7 @@ kind: ApisixGlobalRule metadata: name: test-global-rule-update spec: - ingressClassName: apisix + ingressClassName: %s plugins: - name: response-rewrite enable: true @@ -156,7 +151,7 @@ kind: ApisixGlobalRule metadata: name: test-global-rule-update spec: - ingressClassName: apisix + ingressClassName: %s plugins: - name: response-rewrite enable: true @@ -167,7 +162,7 @@ spec: ` By("create initial ApisixGlobalRule") - err := s.CreateResourceFromString(globalRuleYaml) + err := s.CreateResourceFromString(fmt.Sprintf(globalRuleYaml, s.Namespace())) Expect(err).NotTo(HaveOccurred(), "creating ApisixGlobalRule") By("verify initial ApisixGlobalRule status condition") @@ -187,7 +182,7 @@ spec: resp.Header("X-New-Header").IsEmpty() By("update ApisixGlobalRule") - err = s.CreateResourceFromString(updatedGlobalRuleYaml) + err = s.CreateResourceFromString(fmt.Sprintf(updatedGlobalRuleYaml, s.Namespace())) Expect(err).NotTo(HaveOccurred(), "updating ApisixGlobalRule") By("verify updated ApisixGlobalRule status condition") @@ -219,7 +214,7 @@ kind: ApisixGlobalRule metadata: name: test-global-rule-proxy-rewrite spec: - ingressClassName: apisix + ingressClassName: %s plugins: - name: proxy-rewrite enable: true @@ -235,7 +230,7 @@ kind: ApisixGlobalRule metadata: name: test-global-rule-response-rewrite-multi spec: - ingressClassName: apisix + ingressClassName: %s plugins: - name: response-rewrite enable: true @@ -246,11 +241,11 @@ spec: ` By("create ApisixGlobalRule with proxy-rewrite plugin") - err := s.CreateResourceFromString(proxyRewriteGlobalRuleYaml) + err := s.CreateResourceFromString(fmt.Sprintf(proxyRewriteGlobalRuleYaml, s.Namespace())) Expect(err).NotTo(HaveOccurred(), "creating ApisixGlobalRule with proxy-rewrite") By("create ApisixGlobalRule with response-rewrite plugin") - err = s.CreateResourceFromString(responseRewriteGlobalRuleYaml) + err = s.CreateResourceFromString(fmt.Sprintf(responseRewriteGlobalRuleYaml, s.Namespace())) Expect(err).NotTo(HaveOccurred(), "creating ApisixGlobalRule with response-rewrite") By("verify both ApisixGlobalRule status conditions") diff --git a/test/e2e/crds/v2/pluginconfig.go b/test/e2e/crds/v2/pluginconfig.go index ff50d5ccd..250bb5a26 100644 --- a/test/e2e/crds/v2/pluginconfig.go +++ b/test/e2e/crds/v2/pluginconfig.go @@ -31,56 +31,21 @@ import ( "github.com/apache/apisix-ingress-controller/test/e2e/scaffold" ) -const gatewayProxyYamlPluginConfig = ` -apiVersion: apisix.apache.org/v1alpha1 -kind: GatewayProxy -metadata: - name: apisix-proxy-config - namespace: default -spec: - provider: - type: ControlPlane - controlPlane: - endpoints: - - %s - auth: - type: AdminKey - adminKey: - value: "%s" -` - -const ingressClassYamlPluginConfig = ` -apiVersion: networking.k8s.io/%s -kind: IngressClass -metadata: - name: apisix -spec: - controller: "apisix.apache.org/apisix-ingress-controller" - parameters: - apiGroup: "apisix.apache.org" - kind: "GatewayProxy" - name: "apisix-proxy-config" -` - var _ = Describe("Test ApisixPluginConfig", Label("apisix.apache.org", "v2", "apisixpluginconfig"), func() { var ( - s = scaffold.NewScaffold(&scaffold.Options{ - ControllerName: "apisix.apache.org/apisix-ingress-controller", - }) + s = scaffold.NewDefaultScaffold() applier = framework.NewApplier(s.GinkgoT, s.K8sClient, s.CreateResourceFromString) ) Context("Test ApisixPluginConfig", func() { BeforeEach(func() { By("create GatewayProxy") - gatewayProxy := fmt.Sprintf(gatewayProxyYamlPluginConfig, s.Deployer.GetAdminEndpoint(), s.AdminKey()) - err := s.CreateResourceFromStringWithNamespace(gatewayProxy, "default") + err := s.CreateResourceFromString(s.GetGatewayProxySpec()) Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy") time.Sleep(5 * time.Second) By("create IngressClass") - ingressClass := fmt.Sprintf(ingressClassYamlPluginConfig, framework.IngressVersion) - err = s.CreateResourceFromStringWithNamespace(ingressClass, "") + err = s.CreateResourceFromStringWithNamespace(s.GetIngressClassYaml(), "") Expect(err).NotTo(HaveOccurred(), "creating IngressClass") time.Sleep(5 * time.Second) }) @@ -92,7 +57,7 @@ kind: ApisixPluginConfig metadata: name: test-plugin-config spec: - ingressClassName: apisix + ingressClassName: %s plugins: - name: response-rewrite enable: true @@ -108,7 +73,7 @@ kind: ApisixRoute metadata: name: test-route spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule0 match: @@ -122,17 +87,19 @@ spec: By("apply ApisixPluginConfig") var apisixPluginConfig apiv2.ApisixPluginConfig - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-plugin-config"}, &apisixPluginConfig, apisixPluginConfigSpec) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-plugin-config"}, + &apisixPluginConfig, fmt.Sprintf(apisixPluginConfigSpec, s.Namespace())) By("apply ApisixRoute that references ApisixPluginConfig") var apisixRoute apiv2.ApisixRoute - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-route"}, &apisixRoute, apisixRouteSpec) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-route"}, + &apisixRoute, fmt.Sprintf(apisixRouteSpec, s.Namespace())) By("verify ApisixRoute works with plugin config") request := func() int { return s.NewAPISIXClient().GET("/get").Expect().Raw().StatusCode } - Eventually(request).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) + Eventually(request).WithTimeout(30 * time.Second).ProbeEvery(1 * time.Second).Should(Equal(http.StatusOK)) By("verify plugin from ApisixPluginConfig works") resp := s.NewAPISIXClient().GET("/get").Expect().Status(http.StatusOK) @@ -147,7 +114,7 @@ spec: err = s.DeleteResource("ApisixPluginConfig", "test-plugin-config") Expect(err).ShouldNot(HaveOccurred(), "deleting ApisixPluginConfig") - Eventually(request).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusNotFound)) + Eventually(request).WithTimeout(30 * time.Second).ProbeEvery(1 * time.Second).Should(Equal(http.StatusNotFound)) }) It("Test ApisixPluginConfig update", func() { @@ -157,7 +124,7 @@ kind: ApisixPluginConfig metadata: name: test-plugin-config-update spec: - ingressClassName: apisix + ingressClassName: %s plugins: - name: response-rewrite enable: true @@ -172,7 +139,7 @@ kind: ApisixPluginConfig metadata: name: test-plugin-config-update spec: - ingressClassName: apisix + ingressClassName: %s plugins: - name: response-rewrite enable: true @@ -188,7 +155,7 @@ kind: ApisixRoute metadata: name: test-route-update spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule0 match: @@ -202,24 +169,27 @@ spec: By("apply initial ApisixPluginConfig") var apisixPluginConfig apiv2.ApisixPluginConfig - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-plugin-config-update"}, &apisixPluginConfig, apisixPluginConfigSpecV1) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-plugin-config-update"}, + &apisixPluginConfig, fmt.Sprintf(apisixPluginConfigSpecV1, s.Namespace())) By("apply ApisixRoute that references ApisixPluginConfig") var apisixRoute apiv2.ApisixRoute - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-route-update"}, &apisixRoute, apisixRouteSpec) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-route-update"}, + &apisixRoute, fmt.Sprintf(apisixRouteSpec, s.Namespace())) By("verify initial plugin config works") request := func() int { return s.NewAPISIXClient().GET("/get").Expect().Raw().StatusCode } - Eventually(request).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) + Eventually(request).WithTimeout(30 * time.Second).ProbeEvery(1 * time.Second).Should(Equal(http.StatusOK)) resp := s.NewAPISIXClient().GET("/get").Expect().Status(http.StatusOK) resp.Header("X-Version").IsEqual("v1") resp.Header("X-Updated").IsEmpty() By("update ApisixPluginConfig") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-plugin-config-update"}, &apisixPluginConfig, apisixPluginConfigSpecV2) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-plugin-config-update"}, + &apisixPluginConfig, fmt.Sprintf(apisixPluginConfigSpecV2, s.Namespace())) time.Sleep(5 * time.Second) By("verify updated plugin config works") @@ -241,7 +211,7 @@ kind: ApisixPluginConfig metadata: name: test-plugin-config-disabled spec: - ingressClassName: apisix + ingressClassName: %s plugins: - name: response-rewrite enable: false @@ -261,7 +231,7 @@ kind: ApisixRoute metadata: name: test-route-disabled spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule0 match: @@ -275,17 +245,19 @@ spec: By("apply ApisixPluginConfig with disabled plugin") var apisixPluginConfig apiv2.ApisixPluginConfig - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-plugin-config-disabled"}, &apisixPluginConfig, apisixPluginConfigSpec) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-plugin-config-disabled"}, + &apisixPluginConfig, fmt.Sprintf(apisixPluginConfigSpec, s.Namespace())) By("apply ApisixRoute that references ApisixPluginConfig") var apisixRoute apiv2.ApisixRoute - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-route-disabled"}, &apisixRoute, apisixRouteSpec) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-route-disabled"}, + &apisixRoute, fmt.Sprintf(apisixRouteSpec, s.Namespace())) By("verify ApisixRoute works") request := func() int { return s.NewAPISIXClient().GET("/get").Expect().Raw().StatusCode } - Eventually(request).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) + Eventually(request).WithTimeout(60 * time.Second).ProbeEvery(2 * time.Second).Should(Equal(http.StatusOK)) By("verify disabled plugin is not applied") resp := s.NewAPISIXClient().GET("/get").Expect().Status(http.StatusOK) @@ -308,7 +280,7 @@ kind: ApisixPluginConfig metadata: name: test-plugin-config-override spec: - ingressClassName: apisix + ingressClassName: %s plugins: - name: response-rewrite enable: true @@ -324,7 +296,7 @@ kind: ApisixRoute metadata: name: test-route-override spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule0 match: @@ -345,17 +317,19 @@ spec: By("apply ApisixPluginConfig") var apisixPluginConfig apiv2.ApisixPluginConfig - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-plugin-config-override"}, &apisixPluginConfig, apisixPluginConfigSpec) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-plugin-config-override"}, + &apisixPluginConfig, fmt.Sprintf(apisixPluginConfigSpec, s.Namespace())) By("apply ApisixRoute with overriding plugins") var apisixRoute apiv2.ApisixRoute - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-route-override"}, &apisixRoute, apisixRouteSpec) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-route-override"}, + &apisixRoute, fmt.Sprintf(apisixRouteSpec, s.Namespace())) By("verify ApisixRoute works") request := func() int { return s.NewAPISIXClient().GET("/get").Expect().Raw().StatusCode } - Eventually(request).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) + Eventually(request).WithTimeout(30 * time.Second).ProbeEvery(1 * time.Second).Should(Equal(http.StatusOK)) By("verify route plugins override plugin config") resp := s.NewAPISIXClient().GET("/get").Expect().Status(http.StatusOK) @@ -370,7 +344,7 @@ spec: Expect(err).ShouldNot(HaveOccurred(), "deleting ApisixPluginConfig") }) - It("Test cross-namespace ApisixPluginConfig reference", func() { + It("Test cross-namespace ApisixPluginConfig reference", Serial, func() { const crossNamespaceApisixPluginConfigSpec = ` apiVersion: apisix.apache.org/v2 kind: ApisixPluginConfig @@ -378,7 +352,7 @@ metadata: name: cross-ns-plugin-config namespace: default spec: - ingressClassName: apisix + ingressClassName: %s plugins: - name: response-rewrite enable: true @@ -394,7 +368,7 @@ kind: ApisixRoute metadata: name: test-route-cross-ns spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule0 match: @@ -408,19 +382,20 @@ spec: ` By("apply ApisixPluginConfig in default namespace") - err := s.CreateResourceFromStringWithNamespace(crossNamespaceApisixPluginConfigSpec, "default") + err := s.CreateResourceFromStringWithNamespace(fmt.Sprintf(crossNamespaceApisixPluginConfigSpec, s.Namespace()), "default") Expect(err).NotTo(HaveOccurred(), "creating default/cross-ns-plugin-config") time.Sleep(5 * time.Second) By("apply ApisixRoute in test namespace that references ApisixPluginConfig in default namespace") var apisixRoute apiv2.ApisixRoute - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-route-cross-ns"}, &apisixRoute, apisixRouteSpec) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-route-cross-ns"}, + &apisixRoute, fmt.Sprintf(apisixRouteSpec, s.Namespace())) By("verify cross-namespace reference works") request := func() int { return s.NewAPISIXClient().GET("/get").Expect().Raw().StatusCode } - Eventually(request).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) + Eventually(request).WithTimeout(30 * time.Second).ProbeEvery(1 * time.Second).Should(Equal(http.StatusOK)) resp := s.NewAPISIXClient().GET("/get").Expect().Status(http.StatusOK) resp.Header("X-Cross-Namespace").IsEqual("true") @@ -429,7 +404,7 @@ spec: By("delete resources") err = s.DeleteResource("ApisixRoute", "test-route-cross-ns") Expect(err).ShouldNot(HaveOccurred(), "deleting ApisixRoute") - err = s.DeleteResourceFromStringWithNamespace(crossNamespaceApisixPluginConfigSpec, "default") + err = s.DeleteResourceFromStringWithNamespace(fmt.Sprintf(crossNamespaceApisixPluginConfigSpec, s.Namespace()), "default") Expect(err).ShouldNot(HaveOccurred(), "deleting ApisixPluginConfig") }) @@ -452,7 +427,7 @@ kind: ApisixPluginConfig metadata: name: test-plugin-config-secret spec: - ingressClassName: apisix + ingressClassName: %s plugins: - name: response-rewrite enable: true @@ -468,7 +443,7 @@ kind: ApisixRoute metadata: name: test-route-secret spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule0 match: @@ -481,22 +456,24 @@ spec: ` By("apply Secret") - err := s.CreateResourceFromStringWithNamespace(secretSpec, s.Namespace()) + err := s.CreateResourceFromString(secretSpec) Expect(err).NotTo(HaveOccurred(), "creating Secret") By("apply ApisixPluginConfig with SecretRef") var apisixPluginConfig apiv2.ApisixPluginConfig - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-plugin-config-secret"}, &apisixPluginConfig, apisixPluginConfigSpec) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-plugin-config-secret"}, + &apisixPluginConfig, fmt.Sprintf(apisixPluginConfigSpec, s.Namespace())) By("apply ApisixRoute that references ApisixPluginConfig") var apisixRoute apiv2.ApisixRoute - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-route-secret"}, &apisixRoute, apisixRouteSpec) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-route-secret"}, + &apisixRoute, fmt.Sprintf(apisixRouteSpec, s.Namespace())) By("verify ApisixRoute works with SecretRef") request := func() int { return s.NewAPISIXClient().GET("/get").Expect().Raw().StatusCode } - Eventually(request).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) + Eventually(request).WithTimeout(30 * time.Second).ProbeEvery(1 * time.Second).Should(Equal(http.StatusOK)) resp := s.NewAPISIXClient().GET("/get").Expect().Status(http.StatusOK) resp.Header("X-Secret-Ref").IsEqual("true") diff --git a/test/e2e/crds/v2/route.go b/test/e2e/crds/v2/route.go index 1db18b8be..edf408de5 100644 --- a/test/e2e/crds/v2/route.go +++ b/test/e2e/crds/v2/route.go @@ -42,26 +42,10 @@ import ( var _ = Describe("Test ApisixRoute", Label("apisix.apache.org", "v2", "apisixroute"), func() { var ( - s = scaffold.NewScaffold(&scaffold.Options{ - ControllerName: "apisix.apache.org/apisix-ingress-controller", - }) + s = scaffold.NewDefaultScaffold() applier = framework.NewApplier(s.GinkgoT, s.K8sClient, s.CreateResourceFromString) ) - const ingressClassYaml = ` -apiVersion: networking.k8s.io/%s -kind: IngressClass -metadata: - name: apisix - annotations: - apisix.apache.org/parameters-namespace: %s -spec: - controller: "apisix.apache.org/apisix-ingress-controller" - parameters: - apiGroup: "apisix.apache.org" - kind: "GatewayProxy" - name: "apisix-proxy-config" -` BeforeEach(func() { By("create GatewayProxy") err := s.CreateResourceFromString(s.GetGatewayProxySpec()) @@ -69,8 +53,7 @@ spec: time.Sleep(5 * time.Second) By("create IngressClass") - ingressClass := fmt.Sprintf(ingressClassYaml, framework.IngressVersion, s.Namespace()) - err = s.CreateResourceFromStringWithNamespace(ingressClass, "") + err = s.CreateResourceFromStringWithNamespace(s.GetIngressClassYaml(), "") Expect(err).NotTo(HaveOccurred(), "creating IngressClass") time.Sleep(5 * time.Second) }) @@ -83,8 +66,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: default + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule0 match: @@ -102,25 +86,22 @@ spec: By("apply ApisixRoute") var apisixRoute apiv2.ApisixRoute - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apisixRoute, fmt.Sprintf(apisixRouteSpec, "/get")) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, + &apisixRoute, fmt.Sprintf(apisixRouteSpec, s.Namespace(), s.Namespace(), "/get")) By("verify ApisixRoute works") - Eventually(request).WithArguments("/get").WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) + Eventually(request).WithArguments("/get").WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) By("update ApisixRoute") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apisixRoute, fmt.Sprintf(apisixRouteSpec, "/headers")) - Eventually(request).WithArguments("/get").WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusNotFound)) - s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/headers", - Host: "httpbin", - Check: scaffold.WithExpectedStatus(http.StatusOK), - }) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, + &apisixRoute, fmt.Sprintf(apisixRouteSpec, s.Namespace(), s.Namespace(), "/headers")) + Eventually(request).WithArguments("/get").WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusNotFound)) + s.NewAPISIXClient().GET("/headers").WithHost("httpbin").Expect().Status(http.StatusOK) By("delete ApisixRoute") err := s.DeleteResource("ApisixRoute", "default") Expect(err).ShouldNot(HaveOccurred(), "deleting ApisixRoute") - Eventually(request).WithArguments("/headers").WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusNotFound)) + Eventually(request).WithArguments("/headers").WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusNotFound)) By("request /metrics endpoint from controller") @@ -157,8 +138,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: default + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule0 match: @@ -179,16 +161,18 @@ spec: ` By("apply ApisixRoute without plugins") var apisixRoute apiv2.ApisixRoute - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apisixRoute, apisixRouteSpecPart0) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, + &apisixRoute, fmt.Sprintf(apisixRouteSpecPart0, s.Namespace(), s.Namespace())) By("verify ApisixRoute works") request := func() int { return s.NewAPISIXClient().GET("/get").Expect().Raw().StatusCode } - Eventually(request).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) + Eventually(request).WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) By("apply ApisixRoute with plugins") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apisixRoute, apisixRouteSpecPart0+apisixRouteSpecPart1) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, + &apisixRoute, fmt.Sprintf(apisixRouteSpecPart0, s.Namespace(), s.Namespace())+apisixRouteSpecPart1) time.Sleep(5 * time.Second) By("verify plugin works") @@ -197,10 +181,17 @@ spec: resp.Header("X-Global-Test").IsEqual("enabled") By("remove plugin") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apisixRoute, apisixRouteSpecPart0) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, + &apisixRoute, fmt.Sprintf(apisixRouteSpecPart0, s.Namespace(), s.Namespace())) time.Sleep(5 * time.Second) By("verify no plugin works") + s.RequestAssert(&scaffold.RequestAssert{ + Method: "GET", + Path: "/get", + Check: scaffold.WithExpectedStatus(http.StatusOK), + }) + resp = s.NewAPISIXClient().GET("/get").Expect().Status(http.StatusOK) resp.Header("X-Global-Rule").IsEmpty() resp.Header("X-Global-Test").IsEmpty() @@ -212,8 +203,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: default + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule0 match: @@ -231,7 +223,8 @@ spec: ` By("apply ApisixRoute") var apisixRoute apiv2.ApisixRoute - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apisixRoute, apisixRouteSpec) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, + &apisixRoute, fmt.Sprintf(apisixRouteSpec, s.Namespace(), s.Namespace())) By("verify ApisixRoute works") request := func() int { @@ -239,7 +232,7 @@ spec: WithHeader("X-Foo", "bar"). Expect().Raw().StatusCode } - Eventually(request).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) + Eventually(request).WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) s.NewAPISIXClient().GET("/get").Expect().Status(http.StatusNotFound) }) @@ -252,8 +245,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: default + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule0 match: @@ -281,7 +275,8 @@ spec: ` By("apply ApisixRoute") var apisixRoute apiv2.ApisixRoute - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apisixRoute, apisixRouteSpec) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, + &apisixRoute, fmt.Sprintf(apisixRouteSpec, s.Namespace(), s.Namespace())) By("verify ApisixRoute works") request := func() int { @@ -289,7 +284,7 @@ spec: WithJSON(map[string]string{"foo": "bar"}). Expect().Raw().StatusCode } - Eventually(request).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) + Eventually(request).WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) s.NewAPISIXClient().GET("/get").Expect().Status(http.StatusNotFound) }) @@ -299,8 +294,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: default + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule0 match: @@ -318,9 +314,10 @@ spec: By("apply ApisixRoute") var apisixRoute apiv2.ApisixRoute - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apisixRoute, fmt.Sprintf(apisixRouteSpec, "/get")) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, + &apisixRoute, fmt.Sprintf(apisixRouteSpec, s.Namespace(), s.Namespace(), "/get")) - Eventually(request).WithArguments("/get").WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusServiceUnavailable)) + Eventually(request).WithArguments("/get").WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusServiceUnavailable)) }) It("Test ApisixRoute resolveGranularity", func() { @@ -329,8 +326,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: default + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule0 match: @@ -350,13 +348,14 @@ spec: ` By("apply ApisixRoute") var apisixRoute apiv2.ApisixRoute - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apisixRoute, apisixRouteSpec) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, + &apisixRoute, fmt.Sprintf(apisixRouteSpec, s.Namespace(), s.Namespace())) By("verify ApisixRoute works") request := func() int { return s.NewAPISIXClient().GET("/get").Expect().Raw().StatusCode } - Eventually(request).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) + Eventually(request).WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) By("assert that the request is proxied to the Service ClusterIP") service, err := s.GetServiceByName("httpbin-service-e2e-test") @@ -371,8 +370,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: default + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule0 match: @@ -390,8 +390,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixUpstream metadata: name: httpbin-service-e2e-test + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s subsets: - name: test-subset labels: @@ -402,8 +403,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixUpstream metadata: name: httpbin-service-e2e-test + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s subsets: - name: test-subset labels: @@ -414,18 +416,21 @@ spec: } By("apply ApisixRoute") var apisixRoute apiv2.ApisixRoute - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apisixRoute, apisixRouteSpec) - Eventually(request).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, + &apisixRoute, fmt.Sprintf(apisixRouteSpec, s.Namespace(), s.Namespace())) + Eventually(request).WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) // no pod matches the subset label "unknown-key: unknown-value" so there will be no node in the upstream, // to request the route will get http.StatusServiceUnavailable - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin-service-e2e-test"}, new(apiv2.ApisixUpstream), apisixUpstreamSpec0) - Eventually(request).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusServiceUnavailable)) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin-service-e2e-test"}, + new(apiv2.ApisixUpstream), fmt.Sprintf(apisixUpstreamSpec0, s.Namespace(), s.Namespace())) + Eventually(request).WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusServiceUnavailable)) // the pod matches the subset label "app: httpbin-deployment-e2e-test", // to request the route will be OK - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin-service-e2e-test"}, new(apiv2.ApisixUpstream), apisixUpstreamSpec1) - Eventually(request).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin-service-e2e-test"}, + new(apiv2.ApisixUpstream), fmt.Sprintf(apisixUpstreamSpec1, s.Namespace(), s.Namespace())) + Eventually(request).WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) }) It("Multiple ApisixRoute with same prefix name", func() { @@ -434,8 +439,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: %s + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule0 match: @@ -452,7 +458,8 @@ spec: for _, id := range []string{"11111", "1111", "111", "11", "1"} { name := fmt.Sprintf("route-%s", id) host := fmt.Sprintf("httpbin-%s", id) - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: name}, &apisixRoute, fmt.Sprintf(apisixRouteSpec, name, host)) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: name}, + &apisixRoute, fmt.Sprintf(apisixRouteSpec, name, s.Namespace(), s.Namespace(), host)) } By("verify ApisixRoute works") @@ -460,7 +467,7 @@ spec: host := fmt.Sprintf("httpbin-%s", id) Eventually(func() int { return s.NewAPISIXClient().GET("/get").WithHost(host).Expect().Raw().StatusCode - }).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) + }).WithTimeout(30 * time.Second).ProbeEvery(1 * time.Second).Should(Equal(http.StatusOK)) } }) }) @@ -473,7 +480,7 @@ kind: ApisixRoute metadata: name: route1 spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule1 match: @@ -492,7 +499,7 @@ kind: ApisixRoute metadata: name: route2 spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule2 match: @@ -511,11 +518,11 @@ spec: By("apply first ApisixRoute") var apisixRoute1 apiv2.ApisixRoute - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "route1"}, &apisixRoute1, apisixRouteSpec1) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "route1"}, &apisixRoute1, fmt.Sprintf(apisixRouteSpec1, s.Namespace())) By("apply second ApisixRoute") var apisixRoute2 apiv2.ApisixRoute - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "route2"}, &apisixRoute2, apisixRouteSpec2) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "route2"}, &apisixRoute2, fmt.Sprintf(apisixRouteSpec2, s.Namespace())) By("verify both ApisixRoutes work") Eventually(request).WithArguments("/get").WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) @@ -552,8 +559,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: default + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule0 match: @@ -567,8 +575,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixUpstream metadata: name: default-upstream + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s externalNodes: - type: Service name: httpbin-service-e2e-test @@ -578,8 +587,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixUpstream metadata: name: default-upstream + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s externalNodes: - type: Service name: alias-httpbin-service-e2e-test @@ -594,21 +604,24 @@ spec: externalName: httpbin-service-e2e-test ` By("create Service, ApisixUpstream and ApisixRoute") - err := s.CreateResourceFromString(serviceSpec) + err := s.CreateResourceFromStringWithNamespace(serviceSpec, s.Namespace()) Expect(err).ShouldNot(HaveOccurred(), "apply service") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default-upstream"}, new(apiv2.ApisixUpstream), apisixUpstreamSpec0) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default-upstream"}, + new(apiv2.ApisixUpstream), fmt.Sprintf(apisixUpstreamSpec0, s.Namespace(), s.Namespace())) - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, new(apiv2.ApisixRoute), apisixRouteSpec) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, + new(apiv2.ApisixRoute), fmt.Sprintf(apisixRouteSpec, s.Namespace(), s.Namespace())) By("verify that the ApisixUpstream reference a Service which is not ExternalName should not request OK") request := func(path string) int { return s.NewAPISIXClient().GET(path).WithHost("httpbin").Expect().Raw().StatusCode } - Eventually(request).WithArguments("/get").WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusServiceUnavailable)) + Eventually(request).WithArguments("/get").WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusServiceUnavailable)) By("verify that ApisixUpstream reference a Service which is ExternalName should request OK") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default-upstream"}, new(apiv2.ApisixUpstream), apisixUpstreamSpec1) - Eventually(request).WithArguments("/get").WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default-upstream"}, + new(apiv2.ApisixUpstream), fmt.Sprintf(apisixUpstreamSpec1, s.Namespace(), s.Namespace())) + Eventually(request).WithArguments("/get").WithTimeout(30 * time.Second).ProbeEvery(1 * time.Second).Should(Equal(http.StatusOK)) }) It("Test a Mix of Backends and Upstreams", func() { @@ -618,8 +631,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixUpstream metadata: name: default-upstream + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s externalNodes: - type: Domain name: httpbin-service-e2e-test @@ -632,8 +646,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: default + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule0 match: @@ -653,16 +668,18 @@ spec: "X-Upstream-Host": "$upstream_addr" ` By("apply ApisixUpstream") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default-upstream"}, new(apiv2.ApisixUpstream), apisixUpstreamSpec) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default-upstream"}, + new(apiv2.ApisixUpstream), fmt.Sprintf(apisixUpstreamSpec, s.Namespace(), s.Namespace())) By("apply ApisixRoute") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, new(apiv2.ApisixRoute), apisixRouteSpec) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, + new(apiv2.ApisixRoute), fmt.Sprintf(apisixRouteSpec, s.Namespace(), s.Namespace())) By("verify ApisixRoute works") request := func(path string) int { return s.NewAPISIXClient().GET(path).Expect().Raw().StatusCode } - Eventually(request).WithArguments("/get").WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) + Eventually(request).WithArguments("/get").WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) By("verify the backends and the upstreams work commonly") // .backends -> Service httpbin-service-e2e-test -> Endpoint httpbin-service-e2e-test, so the $upstream_addr value we get is the Endpoint IP. @@ -695,8 +712,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: default + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule0 match: @@ -721,8 +739,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixUpstream metadata: name: httpbin-service-e2e-test + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s passHost: rewrite upstreamHost: hello.httpbin.org loadbalancer: @@ -738,7 +757,8 @@ spec: } By("apply apisixroute") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, new(apiv2.ApisixRoute), apisixRouteSpec) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, + new(apiv2.ApisixRoute), fmt.Sprintf(apisixRouteSpec, s.Namespace(), s.Namespace())) By("verify ApisixRoute works") // expect upstream host is "httpbin" @@ -746,7 +766,8 @@ spec: Expect(err).ShouldNot(HaveOccurred(), "verify ApisixRoute works") By("apply apisixupstream") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin-service-e2e-test"}, new(apiv2.ApisixUpstream), apisixUpstreamSpec) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin-service-e2e-test"}, + new(apiv2.ApisixUpstream), fmt.Sprintf(apisixUpstreamSpec, s.Namespace(), s.Namespace())) By("verify backend implicit reference to apisixupstream works") // expect upstream host is "hello.httpbin.org" which is rewritten by the apisixupstream @@ -768,8 +789,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: default + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule1 match: @@ -786,7 +808,8 @@ spec: weight: 5 ` By("apply ApisixRoute with traffic split") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, new(apiv2.ApisixRoute), apisixRouteSpec) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, new(apiv2.ApisixRoute), + fmt.Sprintf(apisixRouteSpec, s.Namespace(), s.Namespace())) By("send requests to verify traffic split") var ( hitHttpbinCnt = 0 @@ -825,8 +848,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: default + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule1 match: @@ -843,7 +867,8 @@ spec: weight: 0 ` By("apply ApisixRoute with zero-weight backend") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, new(apiv2.ApisixRoute), apisixRouteSpec) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, new(apiv2.ApisixRoute), + fmt.Sprintf(apisixRouteSpec, s.Namespace(), s.Namespace())) By("wait for route to be ready") s.RequestAssert(&scaffold.RequestAssert{ Method: "GET", @@ -866,8 +891,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: default + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule1 match: @@ -884,7 +910,8 @@ spec: weight: 5 ` By("apply ApisixRoute with traffic split") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, new(apiv2.ApisixRoute), apisixRouteSpec) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, + new(apiv2.ApisixRoute), fmt.Sprintf(apisixRouteSpec, s.Namespace(), s.Namespace())) verifyRequest := func() int { return s.NewAPISIXClient().GET("/get").WithHost("httpbin.org").Expect().Raw().StatusCode } @@ -911,8 +938,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: default + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule0 match: @@ -930,8 +958,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: route2 + namespace: %s spec: - ingressClassName: apisix-nonexistent + ingressClassName: %s-nonexistent http: - name: rule0 match: @@ -965,9 +994,11 @@ spec: Skip("skipping test in API7EE mode") } By("apply ApisixRoute") - Expect(s.CreateResourceFromString(route2)).ShouldNot(HaveOccurred(), "apply ApisixRoute with nonexistent ingressClassName") - Expect(s.CreateResourceFromString(route3)).ShouldNot(HaveOccurred(), "apply ApisixRoute without ingressClassName") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, route) + Expect(s.CreateResourceFromStringWithNamespace(fmt.Sprintf(route2, s.Namespace(), s.Namespace()), s.Namespace())). + ShouldNot(HaveOccurred(), "apply ApisixRoute with nonexistent ingressClassName") + Expect(s.CreateResourceFromStringWithNamespace(route3, s.Namespace())).ShouldNot(HaveOccurred(), "apply ApisixRoute without ingressClassName") + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, + &apiv2.ApisixRoute{}, fmt.Sprintf(route, s.Namespace(), s.Namespace())) s.RequestAssert(&scaffold.RequestAssert{ Method: "GET", @@ -1050,8 +1081,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: websocket-route + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule1 match: @@ -1070,8 +1102,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: websocket-route + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule1 match: @@ -1085,7 +1118,7 @@ spec: ` By("create WebSocket server resources") - err := s.CreateResourceFromString(websocketServerResources) + err := s.CreateResourceFromStringWithNamespace(websocketServerResources, s.Namespace()) Expect(err).ShouldNot(HaveOccurred(), "creating WebSocket server resources") By("create ApisixRoute without WebSocker") @@ -1093,9 +1126,9 @@ spec: applier.MustApplyAPIv2( types.NamespacedName{Namespace: s.Namespace(), Name: "websocket-route"}, &apisixRouteWithoutWS, - apisixRouteSpec2, + fmt.Sprintf(apisixRouteSpec2, s.Namespace(), s.Namespace()), ) - time.Sleep(8 * time.Second) + time.Sleep(12 * time.Second) By("verify WebSocket connection fails without WebSocket enabled") u := url.URL{ @@ -1107,13 +1140,12 @@ spec: _, resp, _ := websocket.DefaultDialer.Dial(u.String(), headers) // should receive 200 instead of 101 Expect(resp.StatusCode).Should(Equal(http.StatusOK)) - By("apply ApisixRoute for WebSocket") var apisixRoute apiv2.ApisixRoute applier.MustApplyAPIv2( types.NamespacedName{Namespace: s.Namespace(), Name: "websocket-route"}, &apisixRoute, - apisixRouteSpec, + fmt.Sprintf(apisixRouteSpec, s.Namespace(), s.Namespace()), ) By("wait for WebSocket server to be ready") time.Sleep(10 * time.Second) @@ -1150,13 +1182,7 @@ spec: }) Context("Test ApisixRoute with External Services", func() { - const ( - externalServiceName = "ext-httpbin" - upstreamName = "httpbin-upstream" - routeName = "httpbin-route" - ) - - createExternalService := func(externalName string) { + createExternalService := func(externalName string, externalServiceName string) { By(fmt.Sprintf("create ExternalName service: %s -> %s", externalServiceName, externalName)) svcSpec := fmt.Sprintf(` apiVersion: v1 @@ -1167,23 +1193,24 @@ spec: type: ExternalName externalName: %s `, externalServiceName, externalName) - err := s.CreateResourceFromString(svcSpec) + err := s.CreateResourceFromStringWithNamespace(svcSpec, s.Namespace()) Expect(err).ShouldNot(HaveOccurred(), "creating ExternalName service") } - createApisixUpstream := func(externalType apiv2.ApisixUpstreamExternalType, name string) { + createApisixUpstream := func(externalType apiv2.ApisixUpstreamExternalType, name string, upstreamName string) { By(fmt.Sprintf("create ApisixUpstream: type=%s, name=%s", externalType, name)) upstreamSpec := fmt.Sprintf(` apiVersion: apisix.apache.org/v2 kind: ApisixUpstream metadata: name: %s + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s externalNodes: - type: %s name: %s -`, upstreamName, externalType, name) +`, upstreamName, s.Namespace(), s.Namespace(), externalType, name) var upstream apiv2.ApisixUpstream applier.MustApplyAPIv2( types.NamespacedName{Namespace: s.Namespace(), Name: upstreamName}, @@ -1192,15 +1219,16 @@ spec: ) } - createApisixRoute := func() { + createApisixRoute := func(routeName string, upstreamName string) { By("create ApisixRoute referencing ApisixUpstream") routeSpec := fmt.Sprintf(` apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: %s + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule1 match: @@ -1210,7 +1238,7 @@ spec: - /ip upstreams: - name: %s -`, routeName, upstreamName) +`, routeName, s.Namespace(), s.Namespace(), upstreamName) var route apiv2.ApisixRoute applier.MustApplyAPIv2( types.NamespacedName{Namespace: s.Namespace(), Name: routeName}, @@ -1219,15 +1247,16 @@ spec: ) } - createApisixRouteWithHostRewrite := func(host string) { + createApisixRouteWithHostRewrite := func(routeName string, host string, upstreamName string) { By("create ApisixRoute with host rewrite") routeSpec := fmt.Sprintf(` apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: %s + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule1 match: @@ -1242,7 +1271,7 @@ spec: enable: true config: host: %s -`, routeName, upstreamName, host) +`, routeName, s.Namespace(), s.Namespace(), upstreamName, host) var route apiv2.ApisixRoute applier.MustApplyAPIv2( types.NamespacedName{Namespace: s.Namespace(), Name: routeName}, @@ -1258,26 +1287,33 @@ spec: WithHost("httpbin.org"). Expect().Raw().StatusCode } - Eventually(request).WithTimeout(30 * time.Second).ProbeEvery(2 * time.Second). + Eventually(request).WithTimeout(30 * time.Second).ProbeEvery(1 * time.Second). Should(Equal(http.StatusOK)) } It("access third-party service directly", func() { - createApisixUpstream(apiv2.ExternalTypeDomain, "httpbin.org") - createApisixRoute() + upstreamName := s.Namespace() + routeName := s.Namespace() + createApisixUpstream(apiv2.ExternalTypeDomain, "httpbin.org", upstreamName) + createApisixRoute(routeName, upstreamName) verifyAccess() }) It("access third-party service with host rewrite", func() { - createApisixUpstream(apiv2.ExternalTypeDomain, "httpbin.org") - createApisixRouteWithHostRewrite("httpbin.org") + upstreamName := s.Namespace() + routeName := s.Namespace() + createApisixUpstream(apiv2.ExternalTypeDomain, "httpbin.org", upstreamName) + createApisixRouteWithHostRewrite(routeName, "httpbin.org", upstreamName) verifyAccess() }) It("access external domain via ExternalName service", func() { - createExternalService("httpbin.org") - createApisixUpstream(apiv2.ExternalTypeService, externalServiceName) - createApisixRoute() + externalServiceName := s.Namespace() + upstreamName := s.Namespace() + routeName := s.Namespace() + createExternalService("httpbin.org", externalServiceName) + createApisixUpstream(apiv2.ExternalTypeService, externalServiceName, upstreamName) + createApisixRoute(routeName, upstreamName) verifyAccess() }) @@ -1288,22 +1324,28 @@ spec: fqdn := fmt.Sprintf("%s.%s.svc.cluster.local", "httpbin-service-e2e-test", s.Namespace()) By("setup external service and route") - createExternalService(fqdn) - createApisixUpstream(apiv2.ExternalTypeService, externalServiceName) - createApisixRoute() + externalServiceName := s.Namespace() + upstreamName := s.Namespace() + routeName := s.Namespace() + createExternalService(fqdn, externalServiceName) + createApisixUpstream(apiv2.ExternalTypeService, externalServiceName, upstreamName) + createApisixRoute(routeName, upstreamName) verifyAccess() }) Context("complex scenarios", func() { It("multiple external services in one upstream", func() { + upstreamName := s.Namespace() + routeName := s.Namespace() By("create ApisixUpstream with multiple external nodes") upstreamSpec := ` apiVersion: apisix.apache.org/v2 kind: ApisixUpstream metadata: - name: httpbin-upstream + name: %s + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s externalNodes: - type: Domain name: httpbin.org @@ -1314,10 +1356,10 @@ spec: applier.MustApplyAPIv2( types.NamespacedName{Namespace: s.Namespace(), Name: upstreamName}, &upstream, - upstreamSpec, + fmt.Sprintf(upstreamSpec, upstreamName, s.Namespace(), s.Namespace()), ) - createApisixRoute() + createApisixRoute(routeName, upstreamName) By("verify access to multiple services") time.Sleep(7 * time.Second) @@ -1342,13 +1384,15 @@ spec: }) It("should be able to use backends and upstreams together", func() { + upstreamName := s.Namespace() + routeName := s.Namespace() upstreamSpec := ` apiVersion: apisix.apache.org/v2 kind: ApisixUpstream metadata: - name: httpbin-upstream + name: %s spec: - ingressClassName: apisix + ingressClassName: %s externalNodes: - type: Domain name: postman-echo.com @@ -1357,7 +1401,7 @@ spec: applier.MustApplyAPIv2( types.NamespacedName{Namespace: s.Namespace(), Name: upstreamName}, &upstream, - upstreamSpec, + fmt.Sprintf(upstreamSpec, upstreamName, s.Namespace()), ) By("create ApisixRoute with both backends and upstreams") routeSpec := fmt.Sprintf(` @@ -1365,8 +1409,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: %s + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule1 match: @@ -1380,7 +1425,7 @@ spec: resolveGranularity: service upstreams: - name: %s -`, routeName, upstreamName) +`, routeName, s.Namespace(), s.Namespace(), upstreamName) var route apiv2.ApisixRoute applier.MustApplyAPIv2( types.NamespacedName{Namespace: s.Namespace(), Name: routeName}, diff --git a/test/e2e/crds/v2/status.go b/test/e2e/crds/v2/status.go index 5a98cfa03..6b01a5d0b 100644 --- a/test/e2e/crds/v2/status.go +++ b/test/e2e/crds/v2/status.go @@ -36,8 +36,7 @@ import ( var _ = Describe("Test apisix.apache.org/v2 Status", Label("apisix.apache.org", "v2", "apisixroute"), func() { var ( - s = scaffold.NewScaffold(&scaffold.Options{ - ControllerName: "apisix.apache.org/apisix-ingress-controller", + s = scaffold.NewScaffold(scaffold.Options{ // for triggering the sync SyncPeriod: 3 * time.Second, }) @@ -52,22 +51,7 @@ var _ = Describe("Test apisix.apache.org/v2 Status", Label("apisix.apache.org", time.Sleep(5 * time.Second) By("create IngressClass") - const ingressClassYaml = ` -apiVersion: networking.k8s.io/%s -kind: IngressClass -metadata: - name: apisix - annotations: - apisix.apache.org/parameters-namespace: %s -spec: - controller: "apisix.apache.org/apisix-ingress-controller" - parameters: - apiGroup: "apisix.apache.org" - kind: "GatewayProxy" - name: "apisix-proxy-config" -` - ingressClass := fmt.Sprintf(ingressClassYaml, framework.IngressVersion, s.Namespace()) - err = s.CreateResourceFromStringWithNamespace(ingressClass, "") + err = s.CreateResourceFromStringWithNamespace(s.GetIngressClassYaml(), "") Expect(err).NotTo(HaveOccurred(), "creating IngressClass") time.Sleep(5 * time.Second) }) @@ -76,8 +60,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: default + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule0 match: @@ -94,8 +79,9 @@ apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: default + namespace: %s spec: - ingressClassName: apisix + ingressClassName: %s http: - name: rule0 match: @@ -134,13 +120,13 @@ spec: Skip("apisix standalone does not validate unknown plugins") } By("apply ApisixRoute with valid plugin") - err := s.CreateResourceFromString(arWithInvalidPlugin) + err := s.CreateResourceFromString(fmt.Sprintf(arWithInvalidPlugin, s.Namespace(), s.Namespace())) Expect(err).NotTo(HaveOccurred(), "creating ApisixRoute with valid plugin") By("check ApisixRoute status") if os.Getenv("PROVIDER_TYPE") == "apisix" { s.RetryAssertion(func() string { - output, _ := s.GetOutputFromString("ar", "default", "-o", "yaml") + output, _ := s.GetOutputFromString("ar", "default", "-o", "yaml", "-n", s.Namespace()) log.Printf("output: %s", output) return output }).Should( @@ -152,7 +138,7 @@ spec: ) } else { s.RetryAssertion(func() string { - output, _ := s.GetOutputFromString("ar", "default", "-o", "yaml") + output, _ := s.GetOutputFromString("ar", "default", "-o", "yaml", "-n", s.Namespace()) log.Printf("output: %s", output) return output }).Should( @@ -165,7 +151,7 @@ spec: } By("Update ApisixRoute") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, ar) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, fmt.Sprintf(ar, s.Namespace(), s.Namespace())) By("check route in APISIX") s.RequestAssert(&scaffold.RequestAssert{ @@ -181,7 +167,7 @@ spec: Skip("skip for api7ee mode because it use dashboard admin api") } By("apply ApisixRoute") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, ar) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, fmt.Sprintf(ar, s.Namespace(), s.Namespace())) By("check route in APISIX") s.RequestAssert(&scaffold.RequestAssert{ @@ -210,7 +196,7 @@ spec: By("check ApisixRoute status") s.RetryAssertion(func() string { - output, _ := s.GetOutputFromString("ar", "default", "-o", "yaml") + output, _ := s.GetOutputFromString("ar", "default", "-o", "yaml", "-n", s.Namespace()) return output }).WithTimeout(60 * time.Second). Should( @@ -233,7 +219,7 @@ spec: By("check ApisixRoute status after scaling up") s.RetryAssertion(func() string { - output, _ := s.GetOutputFromString("ar", "default", "-o", "yaml") + output, _ := s.GetOutputFromString("ar", "default", "-o", "yaml", "-n", s.Namespace()) return output }).WithTimeout(60 * time.Second). Should( @@ -254,9 +240,9 @@ spec: It("update the same status only once", func() { By("apply ApisixRoute") - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, ar) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, fmt.Sprintf(ar, s.Namespace(), s.Namespace())) - output, _ := s.GetOutputFromString("ar", "default", "-o", "yaml") + output, _ := s.GetOutputFromString("ar", "default", "-o", "yaml", "-n", s.Namespace()) var route apiv2.ApisixRoute err := yaml.Unmarshal([]byte(output), &route) @@ -267,7 +253,7 @@ spec: s.Deployer.ScaleIngress(0) s.Deployer.ScaleIngress(1) - output, _ = s.GetOutputFromString("ar", "default", "-o", "yaml") + output, _ = s.GetOutputFromString("ar", "default", "-o", "yaml", "-n", s.Namespace()) var route2 apiv2.ApisixRoute err = yaml.Unmarshal([]byte(output), &route2) diff --git a/test/e2e/crds/v2/tls.go b/test/e2e/crds/v2/tls.go index e519ee10e..5d5ae488b 100644 --- a/test/e2e/crds/v2/tls.go +++ b/test/e2e/crds/v2/tls.go @@ -34,44 +34,13 @@ import ( "github.com/apache/apisix-ingress-controller/test/e2e/scaffold" ) -const gatewayProxyYamlTls = ` -apiVersion: apisix.apache.org/v1alpha1 -kind: GatewayProxy -metadata: - name: apisix-proxy-tls - namespace: default -spec: - provider: - type: ControlPlane - controlPlane: - endpoints: - - %s - auth: - type: AdminKey - adminKey: - value: "%s" -` - -const ingressClassYamlTls = ` -apiVersion: networking.k8s.io/%s -kind: IngressClass -metadata: - name: apisix-tls -spec: - controller: "apisix.apache.org/apisix-ingress-controller" - parameters: - apiGroup: "apisix.apache.org" - kind: "GatewayProxy" - name: "apisix-proxy-tls" -` - const apisixRouteYamlTls = ` apiVersion: apisix.apache.org/v2 kind: ApisixRoute metadata: name: test-route-tls spec: - ingressClassName: apisix-tls + ingressClassName: %s http: - name: rule0 match: @@ -90,29 +59,25 @@ var Key = strings.TrimSpace(framework.TestServerKey) var _ = Describe("Test ApisixTls", Label("apisix.apache.org", "v2", "apisixtls"), func() { var ( - s = scaffold.NewScaffold(&scaffold.Options{ - ControllerName: "apisix.apache.org/apisix-ingress-controller", - }) + s = scaffold.NewDefaultScaffold() applier = framework.NewApplier(s.GinkgoT, s.K8sClient, s.CreateResourceFromString) ) Context("Test ApisixTls", func() { BeforeEach(func() { By("create GatewayProxy") - gatewayProxy := fmt.Sprintf(gatewayProxyYamlTls, s.Deployer.GetAdminEndpoint(), s.AdminKey()) - err := s.CreateResourceFromStringWithNamespace(gatewayProxy, "default") + err := s.CreateResourceFromString(s.GetGatewayProxySpec()) Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy") time.Sleep(5 * time.Second) By("create IngressClass") - ingressClass := fmt.Sprintf(ingressClassYamlTls, framework.IngressVersion) - err = s.CreateResourceFromStringWithNamespace(ingressClass, "") + err = s.CreateResourceFromStringWithNamespace(s.GetIngressClassYaml(), "") Expect(err).NotTo(HaveOccurred(), "creating IngressClass") time.Sleep(5 * time.Second) By("create ApisixRoute for TLS testing") var apisixRoute apiv2.ApisixRoute - applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-route-tls"}, &apisixRoute, apisixRouteYamlTls) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-route-tls"}, &apisixRoute, fmt.Sprintf(apisixRouteYamlTls, s.Namespace())) }) normalizePEM := func(s string) string { @@ -132,7 +97,7 @@ kind: ApisixTls metadata: name: test-tls spec: - ingressClassName: apisix-tls + ingressClassName: %s hosts: - api6.com secret: @@ -142,7 +107,7 @@ spec: By("apply ApisixTls") var apisixTls apiv2.ApisixTls - tlsSpec := fmt.Sprintf(apisixTlsSpec, s.Namespace()) + tlsSpec := fmt.Sprintf(apisixTlsSpec, s.Namespace(), s.Namespace()) applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-tls"}, &apisixTls, tlsSpec) By("verify TLS configuration in control plane") @@ -158,7 +123,7 @@ spec: return false } return true - }).WithTimeout(30 * time.Second).ProbeEvery(2 * time.Second).Should(BeTrue()) + }).WithTimeout(30 * time.Second).ProbeEvery(1 * time.Second).Should(BeTrue()) tls, err := s.DefaultDataplaneResource().SSL().List(context.Background()) assert.Nil(GinkgoT(), err, "list tls error") @@ -174,7 +139,7 @@ spec: WithHost("api6.com"). Expect(). Raw().StatusCode - }).WithTimeout(30 * time.Second).ProbeEvery(2 * time.Second).Should(Equal(http.StatusOK)) + }).WithTimeout(30 * time.Second).ProbeEvery(1 * time.Second).Should(Equal(http.StatusOK)) s.NewAPISIXHttpsClient("api6.com"). GET("/get"). @@ -206,7 +171,7 @@ kind: ApisixTls metadata: name: test-mtls spec: - ingressClassName: apisix-tls + ingressClassName: %s hosts: - api6.com secret: @@ -221,7 +186,7 @@ spec: By("apply ApisixTls with mTLS") var apisixTls apiv2.ApisixTls - tlsSpec := fmt.Sprintf(apisixTlsSpec, s.Namespace(), s.Namespace()) + tlsSpec := fmt.Sprintf(apisixTlsSpec, s.Namespace(), s.Namespace(), s.Namespace()) applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-mtls"}, &apisixTls, tlsSpec) By("verify mTLS configuration in control plane") @@ -238,7 +203,7 @@ spec: } // Check if client CA is configured return tls[0].Client != nil && tls[0].Client.CA != "" - }).WithTimeout(30 * time.Second).ProbeEvery(2 * time.Second).Should(BeTrue()) + }).WithTimeout(30 * time.Second).ProbeEvery(1 * time.Second).Should(BeTrue()) tls, err := s.DefaultDataplaneResource().SSL().List(context.Background()) assert.Nil(GinkgoT(), err, "list tls error") diff --git a/test/e2e/framework/assertion.go b/test/e2e/framework/assertion.go index 70d374fa4..32e9c2a93 100644 --- a/test/e2e/framework/assertion.go +++ b/test/e2e/framework/assertion.go @@ -123,7 +123,7 @@ func PollUntilAPIv2MustHaveStatus(cli client.Client, timeout time.Duration, nn t if err := apiv2.AddToScheme(cli.Scheme()); err != nil { return err } - return wait.PollUntilContextTimeout(context.Background(), time.Second, timeout, true, func(ctx context.Context) (done bool, err error) { + return wait.PollUntilContextTimeout(context.Background(), 2*time.Second, timeout, true, func(ctx context.Context) (done bool, err error) { if err := cli.Get(ctx, nn, obj); err != nil { return false, errors.Wrapf(err, "error fetching Object %s", nn) } @@ -179,7 +179,7 @@ type applier struct { func (a *applier) MustApplyAPIv2(nn types.NamespacedName, obj client.Object, spec string) { require.NoError(a.t, a.apply(spec), "creating %s", nn) - APIv2MustHaveCondition(a.t, a.cli, 8*time.Second, nn, obj, metav1.Condition{ + APIv2MustHaveCondition(a.t, a.cli, 90*time.Second, nn, obj, metav1.Condition{ Type: string(gatewayv1.RouteConditionAccepted), Status: metav1.ConditionTrue, Reason: string(gatewayv1.GatewayReasonAccepted), diff --git a/test/e2e/framework/ingress.go b/test/e2e/framework/ingress.go index cd018b433..e77db052a 100644 --- a/test/e2e/framework/ingress.go +++ b/test/e2e/framework/ingress.go @@ -60,7 +60,6 @@ func (f *Framework) DeployIngress(opts IngressDeployOpts) { f.GomegaT.Expect(err).ToNot(HaveOccurred(), "rendering ingress spec") kubectlOpts := k8s.NewKubectlOptions("", "", opts.Namespace) - k8s.KubectlApplyFromString(f.GinkgoT, kubectlOpts, buf.String()) err = WaitPodsAvailable(f.GinkgoT, kubectlOpts, metav1.ListOptions{ diff --git a/test/e2e/gatewayapi/controller.go b/test/e2e/gatewayapi/controller.go index d2a7bdd08..578e85980 100644 --- a/test/e2e/gatewayapi/controller.go +++ b/test/e2e/gatewayapi/controller.go @@ -34,7 +34,7 @@ var _ = Describe("Check if controller cache gets synced with correct resources", apiVersion: apisix.apache.org/v1alpha1 kind: GatewayProxy metadata: - name: apisix-proxy-config + name: %s spec: provider: type: ControlPlane @@ -73,7 +73,7 @@ spec: parametersRef: group: apisix.apache.org kind: GatewayProxy - name: apisix-proxy-config + name: %s ` var ResourceApplied = func(s *scaffold.Scaffold, resourType, resourceName, ns, resourceRaw string, observedGeneration int) { @@ -94,35 +94,30 @@ spec: ) time.Sleep(3 * time.Second) } - var beforeEach = func(s *scaffold.Scaffold, gatewayName string) { - err := s.CreateResourceFromString(fmt.Sprintf(` -kind: Namespace -apiVersion: v1 -metadata: - name: %s -`, gatewayName)) - Expect(err).NotTo(HaveOccurred(), "creating namespace") + var beforeEach = func(s *scaffold.Scaffold) { By(fmt.Sprintf("create GatewayClass for controller %s", s.GetControllerName())) By("create GatewayProxy") - gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Deployer.GetAdminEndpoint(), s.AdminKey()) - err = s.CreateResourceFromStringWithNamespace(gatewayProxy, gatewayName) + gatewayProxyName := s.Namespace() + gatewayName := s.Namespace() + gatewayProxy := fmt.Sprintf(gatewayProxyYaml, gatewayProxyName, s.Deployer.GetAdminEndpoint(), s.AdminKey()) + err := s.CreateResourceFromStringWithNamespace(gatewayProxy, gatewayName) Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy") time.Sleep(5 * time.Second) - gatewayClassName := fmt.Sprintf("apisix-%d", time.Now().Unix()) + gatewayClassName := s.Namespace() err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defautlGatewayClass, gatewayClassName, gatewayName, s.GetControllerName()), gatewayName) Expect(err).NotTo(HaveOccurred(), "creating GatewayClass") time.Sleep(10 * time.Second) By("check GatewayClass condition") - gcyaml, err := s.GetResourceYamlFromNamespace("GatewayClass", gatewayClassName, gatewayName) + gcyaml, err := s.GetResourceYamlFromNamespace("GatewayClass", gatewayClassName, s.Namespace()) Expect(err).NotTo(HaveOccurred(), "getting GatewayClass yaml") Expect(gcyaml).To(ContainSubstring(`status: "True"`), "checking GatewayClass condition status") Expect(gcyaml).To(ContainSubstring("message: the gatewayclass has been accepted by the apisix-ingress-controller"), "checking GatewayClass condition message") By("create Gateway") - err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defautlGateway, gatewayName, gatewayName, gatewayClassName), gatewayName) + err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defautlGateway, gatewayName, gatewayName, gatewayClassName, gatewayProxyName), gatewayName) Expect(err).NotTo(HaveOccurred(), "creating Gateway") time.Sleep(10 * time.Second) @@ -134,19 +129,15 @@ metadata: } Context("Create resource with first controller", func() { - s1 := scaffold.NewScaffold(&scaffold.Options{ - Name: "gateway1", - ControllerName: "apisix.apache.org/apisix-ingress-controller-1", - }) + s1 := scaffold.NewDefaultScaffold() var route1 = ` apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin - namespace: gateway1 spec: parentRefs: - - name: gateway1 + - name: %s hostnames: - httpbin.example rules: @@ -169,30 +160,31 @@ spec: weight: 50 ` BeforeEach(func() { - beforeEach(s1, "gateway1") + beforeEach(s1) }) It("Apply resource ", func() { - ResourceApplied(s1, "HTTPRoute", "httpbin", "gateway1", route1, 1) - routes, err := s1.DefaultDataplaneResource().Route().List(s1.Context) - Expect(err).NotTo(HaveOccurred()) - Expect(routes).To(HaveLen(1)) - assert.Equal(GinkgoT(), routes[0].Labels["k8s/controller-name"], "apisix.apache.org/apisix-ingress-controller-1") + ResourceApplied(s1, "HTTPRoute", "httpbin", s1.Namespace(), fmt.Sprintf(route1, s1.Namespace()), 1) + + s1.RetryAssertion(func() int { + routes, _ := s1.DefaultDataplaneResource().Route().List(s1.Context) + return len(routes) + }).WithInterval(3*time.Second).Should(Equal(1), "checking route count") + + routes, _ := s1.DefaultDataplaneResource().Route().List(s1.Context) + assert.Equal(GinkgoT(), routes[0].Labels["k8s/controller-name"], s1.GetControllerName()) }) }) Context("Create resource with second controller", func() { - s2 := scaffold.NewScaffold(&scaffold.Options{ - Name: "gateway2", - ControllerName: "apisix.apache.org/apisix-ingress-controller-2", - }) + s2 := scaffold.NewDefaultScaffold() var route2 = ` apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin2 - namespace: gateway2 + namespace: %s spec: parentRefs: - - name: gateway2 + - name: %s hostnames: - httpbin.example rules: @@ -215,14 +207,15 @@ spec: weight: 50 ` BeforeEach(func() { - beforeEach(s2, "gateway2") + beforeEach(s2) }) It("Apply resource ", func() { - ResourceApplied(s2, "HTTPRoute", "httpbin2", "gateway2", route2, 1) + ResourceApplied(s2, "HTTPRoute", "httpbin2", s2.Namespace(), fmt.Sprintf(route2, s2.Namespace(), s2.Namespace()), 1) + time.Sleep(5 * time.Second) routes, err := s2.DefaultDataplaneResource().Route().List(s2.Context) Expect(err).NotTo(HaveOccurred()) Expect(routes).To(HaveLen(1)) - assert.Equal(GinkgoT(), routes[0].Labels["k8s/controller-name"], "apisix.apache.org/apisix-ingress-controller-2") + assert.Equal(GinkgoT(), routes[0].Labels["k8s/controller-name"], s2.GetControllerName()) }) }) }) diff --git a/test/e2e/gatewayapi/gateway.go b/test/e2e/gatewayapi/gateway.go index 28b1c900f..3c17c09c9 100644 --- a/test/e2e/gatewayapi/gateway.go +++ b/test/e2e/gatewayapi/gateway.go @@ -43,15 +43,14 @@ func createSecret(s *scaffold.Scaffold, secretName string) { } var _ = Describe("Test Gateway", Label("networking.k8s.io", "gateway"), func() { - s := scaffold.NewScaffold(&scaffold.Options{ - ControllerName: "apisix.apache.org/apisix-ingress-controller", - }) + s := scaffold.NewDefaultScaffold() var gatewayProxyYaml = ` apiVersion: apisix.apache.org/v1alpha1 kind: GatewayProxy metadata: name: apisix-proxy-config + namespace: %s spec: provider: type: ControlPlane @@ -69,18 +68,18 @@ spec: apiVersion: gateway.networking.k8s.io/v1 kind: GatewayClass metadata: - name: apisix + name: %s spec: - controllerName: "apisix.apache.org/apisix-ingress-controller" + controllerName: "%s" ` var defaultGateway = ` apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: - name: apisix + name: %s spec: - gatewayClassName: apisix + gatewayClassName: %s listeners: - name: http1 protocol: HTTP @@ -111,31 +110,33 @@ spec: ` It("Create Gateway", func() { + gatewayClassName := s.Namespace() By("create GatewayProxy") - gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Deployer.GetAdminEndpoint(), s.AdminKey()) + gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Namespace(), s.Deployer.GetAdminEndpoint(), s.AdminKey()) err := s.CreateResourceFromString(gatewayProxy) Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy") time.Sleep(5 * time.Second) By("create GatewayClass") - err = s.CreateResourceFromStringWithNamespace(defaultGatewayClass, "") + err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defaultGatewayClass, gatewayClassName, s.GetControllerName()), "") Expect(err).NotTo(HaveOccurred(), "creating GatewayClass") time.Sleep(5 * time.Second) By("check GatewayClass condition") - gcyaml, err := s.GetResourceYaml("GatewayClass", "apisix") + gcyaml, err := s.GetResourceYaml("GatewayClass", gatewayClassName) Expect(err).NotTo(HaveOccurred(), "getting GatewayClass yaml") Expect(gcyaml).To(ContainSubstring(`status: "True"`), "checking GatewayClass condition status") Expect(gcyaml).To(ContainSubstring("message: the gatewayclass has been accepted by the apisix-ingress-controller"), "checking GatewayClass condition message") By("create Gateway") - err = s.CreateResourceFromStringWithNamespace(defaultGateway, s. + gatewayName := s.Namespace() + err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defaultGateway, gatewayName, gatewayClassName), s. Namespace()) Expect(err).NotTo(HaveOccurred(), "creating Gateway") time.Sleep(5 * time.Second) By("check Gateway condition") - gwyaml, err := s.GetResourceYaml("Gateway", "apisix") + gwyaml, err := s.GetResourceYaml("Gateway", gatewayName) Expect(err).NotTo(HaveOccurred(), "getting Gateway yaml") Expect(gwyaml).To(ContainSubstring(`status: "True"`), "checking Gateway condition status") Expect(gwyaml).To(ContainSubstring("message: the gateway has been accepted by the apisix-ingress-controller"), "checking Gateway condition message") @@ -155,7 +156,7 @@ spec: Context("Gateway SSL", func() { It("Check if SSL resource was created", func() { By("create GatewayProxy") - gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Deployer.GetAdminEndpoint(), s.AdminKey()) + gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Namespace(), s.Deployer.GetAdminEndpoint(), s.AdminKey()) err := s.CreateResourceFromString(gatewayProxy) Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy") time.Sleep(5 * time.Second) @@ -164,22 +165,23 @@ spec: secretName := _secretName host := "api6.com" createSecret(s, secretName) + gatewayClassName := s.Namespace() var defaultGatewayClass = ` apiVersion: gateway.networking.k8s.io/v1 kind: GatewayClass metadata: - name: apisix + name: %s spec: - controllerName: "apisix.apache.org/apisix-ingress-controller" + controllerName: "%s" ` var defaultGateway = fmt.Sprintf(` apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: - name: apisix + name: %s spec: - gatewayClassName: apisix + gatewayClassName: %s listeners: - name: http1 protocol: HTTPS @@ -195,9 +197,9 @@ spec: group: apisix.apache.org kind: GatewayProxy name: apisix-proxy-config -`, host, secretName) +`, s.Namespace(), gatewayClassName, host, secretName) By("create GatewayClass") - err = s.CreateResourceFromStringWithNamespace(defaultGatewayClass, "") + err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defaultGatewayClass, gatewayClassName, s.GetControllerName()), "") Expect(err).NotTo(HaveOccurred(), "creating GatewayClass") time.Sleep(5 * time.Second) @@ -216,20 +218,21 @@ spec: It("Gateway SSL with and without hostname", func() { By("create GatewayProxy") - gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Deployer.GetAdminEndpoint(), s.AdminKey()) + gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Namespace(), s.Deployer.GetAdminEndpoint(), s.AdminKey()) err := s.CreateResourceFromString(gatewayProxy) Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy") time.Sleep(5 * time.Second) secretName := _secretName createSecret(s, secretName) + gatewayClassName := s.Namespace() var defaultGatewayClass = ` apiVersion: gateway.networking.k8s.io/v1 kind: GatewayClass metadata: - name: apisix + name: %s spec: - controllerName: "apisix.apache.org/apisix-ingress-controller" + controllerName: "%s" ` var defaultGateway = fmt.Sprintf(` @@ -238,7 +241,7 @@ kind: Gateway metadata: name: same-namespace-with-https-listener spec: - gatewayClassName: apisix + gatewayClassName: %s listeners: - name: https port: 443 @@ -268,9 +271,9 @@ spec: group: apisix.apache.org kind: GatewayProxy name: apisix-proxy-config -`, secretName, secretName) +`, gatewayClassName, secretName, secretName) By("create GatewayClass") - err = s.CreateResourceFromStringWithNamespace(defaultGatewayClass, "") + err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defaultGatewayClass, gatewayClassName, s.GetControllerName()), "") Expect(err).NotTo(HaveOccurred(), "creating GatewayClass") time.Sleep(5 * time.Second) @@ -284,7 +287,7 @@ spec: assert.Len(GinkgoT(), tls, 1, "tls number not expect") assert.Len(GinkgoT(), tls[0].Certificates, 1, "length of certificates not expect") assert.Equal(GinkgoT(), Cert, tls[0].Certificates[0].Certificate, "tls cert not expect") - assert.Equal(GinkgoT(), tls[0].Labels["k8s/controller-name"], "apisix.apache.org/apisix-ingress-controller") + assert.Equal(GinkgoT(), tls[0].Labels["k8s/controller-name"], s.GetControllerName()) By("update secret") err = s.NewKubeTlsSecret(secretName, framework.TestCert, framework.TestKey) @@ -299,7 +302,7 @@ spec: return "" } return tls[0].Certificates[0].Certificate - }).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(framework.TestCert)) + }).WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(framework.TestCert)) }) }) }) diff --git a/test/e2e/gatewayapi/gatewayclass.go b/test/e2e/gatewayapi/gatewayclass.go index b8eae0cef..4ecc8c19e 100644 --- a/test/e2e/gatewayapi/gatewayclass.go +++ b/test/e2e/gatewayapi/gatewayclass.go @@ -18,6 +18,7 @@ package gatewayapi import ( + "fmt" "time" . "github.com/onsi/ginkgo/v2" @@ -27,18 +28,16 @@ import ( ) var _ = Describe("Test GatewayClass", Label("networking.k8s.io", "gatewayclass"), func() { - s := scaffold.NewScaffold(&scaffold.Options{ - ControllerName: "apisix.apache.org/apisix-ingress-controller", - }) + s := scaffold.NewDefaultScaffold() Context("Create GatewayClass", func() { var defautlGatewayClass = ` apiVersion: gateway.networking.k8s.io/v1 kind: GatewayClass metadata: - name: apisix + name: %s spec: - controllerName: "apisix.apache.org/apisix-ingress-controller" + controllerName: "%s" ` var noGatewayClass = ` @@ -53,27 +52,28 @@ spec: apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: - name: apisix + name: %s spec: - gatewayClassName: apisix + gatewayClassName: %s listeners: - name: http1 protocol: HTTP port: 80 ` It("Create GatewayClass", func() { + gatewayClassName := s.Namespace() By("create default GatewayClass") - err := s.CreateResourceFromStringWithNamespace(defautlGatewayClass, "") + err := s.CreateResourceFromString(fmt.Sprintf(defautlGatewayClass, gatewayClassName, s.GetControllerName())) Expect(err).NotTo(HaveOccurred(), "creating GatewayClass") time.Sleep(5 * time.Second) - gcyaml, err := s.GetResourceYaml("GatewayClass", "apisix") + gcyaml, err := s.GetResourceYaml("GatewayClass", gatewayClassName) Expect(err).NotTo(HaveOccurred(), "getting GatewayClass yaml") Expect(gcyaml).To(ContainSubstring(`status: "True"`), "checking GatewayClass condition status") Expect(gcyaml).To(ContainSubstring("message: the gatewayclass has been accepted by the apisix-ingress-controller"), "checking GatewayClass condition message") By("create GatewayClass with not accepted") - err = s.CreateResourceFromStringWithNamespace(noGatewayClass, "") + err = s.CreateResourceFromString(noGatewayClass) Expect(err).NotTo(HaveOccurred(), "creating GatewayClass") time.Sleep(5 * time.Second) @@ -84,28 +84,30 @@ spec: }) It("Delete GatewayClass", func() { + gatewayClassName := s.Namespace() By("create default GatewayClass") - err := s.CreateResourceFromStringWithNamespace(defautlGatewayClass, "") + err := s.CreateResourceFromString(fmt.Sprintf(defautlGatewayClass, gatewayClassName, s.GetControllerName())) Expect(err).NotTo(HaveOccurred(), "creating GatewayClass") Eventually(func() string { - spec, err := s.GetResourceYaml("GatewayClass", "apisix") + spec, err := s.GetResourceYaml("GatewayClass", gatewayClassName) Expect(err).NotTo(HaveOccurred(), "get resource yaml") return spec - }).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(ContainSubstring(`status: "True"`)) + }).WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(ContainSubstring(`status: "True"`)) By("create a Gateway") - err = s.CreateResourceFromStringWithNamespace(defaultGateway, s.Namespace()) + gatewayName := s.Namespace() + err = s.CreateResourceFromString(fmt.Sprintf(defaultGateway, gatewayName, gatewayClassName)) Expect(err).NotTo(HaveOccurred(), "creating Gateway") time.Sleep(time.Second) By("try to delete the GatewayClass") - _, err = s.RunKubectlAndGetOutput("delete", "GatewayClass", "apisix", "--wait=false") + _, err = s.RunKubectlAndGetOutput("delete", "GatewayClass", gatewayClassName, "--wait=false") Expect(err).NotTo(HaveOccurred()) - _, err = s.GetResourceYaml("GatewayClass", "apisix") + _, err = s.GetResourceYaml("GatewayClass", gatewayClassName) Expect(err).NotTo(HaveOccurred(), "get resource yaml") - output, err := s.RunKubectlAndGetOutput("describe", "GatewayClass", "apisix") + output, err := s.RunKubectlAndGetOutput("describe", "GatewayClass", gatewayClassName) Expect(err).NotTo(HaveOccurred(), "describe GatewayClass apisix") Expect(output).To(And( ContainSubstring("Warning"), @@ -115,15 +117,15 @@ spec: )) By("delete the Gateway") - err = s.DeleteResource("Gateway", "apisix") + err = s.DeleteResource("Gateway", gatewayName) Expect(err).NotTo(HaveOccurred(), "deleting Gateway") time.Sleep(time.Second) By("try to delete the GatewayClass again") - err = s.DeleteResource("GatewayClass", "apisix") + err = s.DeleteResource("GatewayClass", gatewayClassName) Expect(err).NotTo(HaveOccurred()) - _, err = s.GetResourceYaml("GatewayClass", "apisix") + _, err = s.GetResourceYaml("GatewayClass", gatewayClassName) Expect(err).To(HaveOccurred(), "get resource yaml") Expect(err.Error()).To(ContainSubstring("not found")) }) diff --git a/test/e2e/gatewayapi/gatewayproxy.go b/test/e2e/gatewayapi/gatewayproxy.go index f8fc56f77..1cad06eae 100644 --- a/test/e2e/gatewayapi/gatewayproxy.go +++ b/test/e2e/gatewayapi/gatewayproxy.go @@ -43,7 +43,7 @@ spec: apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: - name: apisix + name: %s spec: gatewayClassName: %s listeners: @@ -54,14 +54,14 @@ spec: parametersRef: group: apisix.apache.org kind: GatewayProxy - name: apisix-proxy-config + name: %s ` var gatewayProxyWithEnabledPlugin = ` apiVersion: apisix.apache.org/v1alpha1 kind: GatewayProxy metadata: - name: apisix-proxy-config + name: %s spec: provider: type: ControlPlane @@ -84,7 +84,7 @@ spec: apiVersion: apisix.apache.org/v1alpha1 kind: GatewayProxy metadata: - name: apisix-proxy-config + name: %s spec: provider: type: ControlPlane @@ -129,7 +129,7 @@ spec: BeforeEach(func() { By("Create GatewayClass") - gatewayClassName = fmt.Sprintf("apisix-%d", time.Now().Unix()) + gatewayClassName = s.Namespace() err := s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defaultGatewayClass, gatewayClassName, s.GetControllerName()), "") Expect(err).NotTo(HaveOccurred(), "creating GatewayClass") time.Sleep(5 * time.Second) @@ -141,17 +141,17 @@ spec: Expect(gcYaml).To(ContainSubstring("message: the gatewayclass has been accepted by the apisix-ingress-controller"), "checking GatewayClass condition message") By("Create GatewayProxy with enabled plugin") - err = s.CreateResourceFromString(fmt.Sprintf(gatewayProxyWithEnabledPlugin, s.Deployer.GetAdminEndpoint(), s.AdminKey())) + err = s.CreateResourceFromString(fmt.Sprintf(gatewayProxyWithEnabledPlugin, s.Namespace(), s.Deployer.GetAdminEndpoint(), s.AdminKey())) Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy with enabled plugin") time.Sleep(5 * time.Second) By("Create Gateway with GatewayProxy") - err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(gatewayWithProxy, gatewayClassName), s.Namespace()) + err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(gatewayWithProxy, s.Namespace(), gatewayClassName, s.Namespace()), s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating Gateway with GatewayProxy") time.Sleep(5 * time.Second) By("check Gateway condition") - gwyaml, err := s.GetResourceYaml("Gateway", "apisix") + gwyaml, err := s.GetResourceYaml("Gateway", s.Namespace()) Expect(err).NotTo(HaveOccurred(), "getting Gateway yaml") Expect(gwyaml).To(ContainSubstring(`status: "True"`), "checking Gateway condition status") Expect(gwyaml).To(ContainSubstring("message: the gateway has been accepted by the apisix-ingress-controller"), "checking Gateway condition message") @@ -160,7 +160,7 @@ spec: Context("Test Gateway with enabled GatewayProxy plugin", func() { It("Should apply plugin configuration when enabled", func() { By("Create HTTPRoute for Gateway with GatewayProxy") - s.ResourceApplied("HTTPRoute", "test-route", fmt.Sprintf(httpRouteForTest, "apisix"), 1) + s.ResourceApplied("HTTPRoute", "test-route", fmt.Sprintf(httpRouteForTest, s.Namespace()), 1) By("Check if the plugin is applied") s.RequestAssert(&scaffold.RequestAssert{ @@ -174,11 +174,11 @@ spec: }) By("Update GatewayProxy with disabled plugin") - err := s.CreateResourceFromString(fmt.Sprintf(gatewayProxyWithDisabledPlugin, s.Deployer.GetAdminEndpoint(), s.AdminKey())) + err := s.CreateResourceFromString(fmt.Sprintf(gatewayProxyWithDisabledPlugin, s.Namespace(), s.Deployer.GetAdminEndpoint(), s.AdminKey())) Expect(err).NotTo(HaveOccurred(), "updating GatewayProxy with disabled plugin") By("Create HTTPRoute for Gateway with GatewayProxy") - s.ResourceApplied("HTTPRoute", "test-route", fmt.Sprintf(httpRouteForTest, "apisix"), 1) + s.ResourceApplied("HTTPRoute", "test-route", fmt.Sprintf(httpRouteForTest, s.Namespace()), 1) By("Check if the plugin is not applied") s.RequestAssert(&scaffold.RequestAssert{ @@ -191,15 +191,12 @@ spec: }, }) - }) - }) - - Context("Test GatewayProxy with invalid endpoint", func() { - var gatewayProxyWithInvalidEndpoint = ` + By("should fail to apply GatewayProxy with invalid endpoint") + var gatewayProxyWithInvalidEndpoint = ` apiVersion: apisix.apache.org/v1alpha1 kind: GatewayProxy metadata: - name: apisix-proxy-config + name: %s spec: provider: type: ControlPlane @@ -212,13 +209,13 @@ spec: adminKey: value: "%s" ` - It("Should fail to apply GatewayProxy with invalid endpoint", func() { + By("Update GatewayProxy with invalid endpoint") - err := s.CreateResourceFromString(fmt.Sprintf(gatewayProxyWithInvalidEndpoint, s.Deployer.GetAdminEndpoint(), s.AdminKey())) + err = s.CreateResourceFromString(fmt.Sprintf(gatewayProxyWithInvalidEndpoint, s.Namespace(), s.Deployer.GetAdminEndpoint(), s.AdminKey())) Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy with enabled plugin") By("Create HTTPRoute") - s.ResourceApplied("HTTPRoute", "test-route", fmt.Sprintf(httpRouteForTest, "apisix"), 1) + s.ResourceApplied("HTTPRoute", "test-route", fmt.Sprintf(httpRouteForTest, s.Namespace()), 1) s.RequestAssert(&scaffold.RequestAssert{ Method: "GET", @@ -238,7 +235,7 @@ spec: apiVersion: apisix.apache.org/v1alpha1 kind: GatewayProxy metadata: - name: apisix-proxy-config + name: %s spec: provider: type: "InvalidType" @@ -247,7 +244,7 @@ spec: apiVersion: apisix.apache.org/v1alpha1 kind: GatewayProxy metadata: - name: apisix-proxy-config + name: %s spec: provider: type: "ControlPlane" @@ -256,7 +253,7 @@ spec: apiVersion: apisix.apache.org/v1alpha1 kind: GatewayProxy metadata: - name: apisix-proxy-config + name: %s spec: provider: type: "ControlPlane" @@ -271,25 +268,25 @@ spec: ) It("Should reject invalid provider type", func() { By("Create GatewayProxy with invalid provider type") - err := s.CreateResourceFromString(gatewayProxyWithInvalidProviderType) + err := s.CreateResourceFromString(fmt.Sprintf(gatewayProxyWithInvalidProviderType, s.Namespace())) Expect(err).To(HaveOccurred(), "creating GatewayProxy with invalid provider type") Expect(err.Error()).To(ContainSubstring("Invalid value")) }) It("Should reject missing controlPlane configuration", func() { By("Create GatewayProxy with missing controlPlane") - err := s.CreateResourceFromString(gatewayProxyWithMissingControlPlane) + err := s.CreateResourceFromString(fmt.Sprintf(gatewayProxyWithMissingControlPlane, s.Namespace())) Expect(err).To(HaveOccurred(), "creating GatewayProxy with missing controlPlane") Expect(err.Error()).To(ContainSubstring("controlPlane must be specified when type is ControlPlane")) }) It("Should accept valid provider configuration", func() { By("Create GatewayProxy with valid provider") - err := s.CreateResourceFromString(gatewayProxyWithValidProvider) + err := s.CreateResourceFromString(fmt.Sprintf(gatewayProxyWithValidProvider, s.Namespace())) Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy with valid provider") s.RetryAssertion(func() string { - gpYaml, _ := s.GetResourceYaml("GatewayProxy", "apisix-proxy-config") + gpYaml, _ := s.GetResourceYaml("GatewayProxy", s.Namespace()) return gpYaml }).Should(ContainSubstring(`"type":"ControlPlane"`), "checking GatewayProxy is applied") }) diff --git a/test/e2e/gatewayapi/httproute.go b/test/e2e/gatewayapi/httproute.go index 1057a6633..60a06a80d 100644 --- a/test/e2e/gatewayapi/httproute.go +++ b/test/e2e/gatewayapi/httproute.go @@ -49,28 +49,11 @@ spec: controllerName: %s ` - var defaultGateway = ` -apiVersion: gateway.networking.k8s.io/v1 -kind: Gateway -metadata: - name: apisix -spec: - gatewayClassName: %s - listeners: - - name: http1 - protocol: HTTP - port: 80 - infrastructure: - parametersRef: - group: apisix.apache.org - kind: GatewayProxy - name: apisix-proxy-config -` var defaultGatewayHTTPS = ` apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: - name: apisix + name: %s spec: gatewayClassName: %s listeners: @@ -91,15 +74,14 @@ spec: ` var beforeEachHTTP = func() { - Expect(s.CreateResourceFromString(s.GetGatewayProxySpec())). - NotTo(HaveOccurred(), "creating GatewayProxy") + By("create GatewayProxy") + Expect(s.CreateResourceFromString(s.GetGatewayProxySpec())).NotTo(HaveOccurred(), "creating GatewayProxy") - gatewayClassName := fmt.Sprintf("apisix-%d", time.Now().Nanosecond()) - Expect(s.CreateResourceFromStringWithNamespace(fmt.Sprintf(gatewayClassYaml, gatewayClassName, s.GetControllerName()), "")). - NotTo(HaveOccurred(), "creating GatewayClass") + By("create GatewayClass") + Expect(s.CreateResourceFromString(s.GetGatewayClassYaml())).NotTo(HaveOccurred(), "creating GatewayClass") s.RetryAssertion(func() string { - gcyaml, _ := s.GetResourceYaml("GatewayClass", gatewayClassName) + gcyaml, _ := s.GetResourceYaml("GatewayClass", s.Namespace()) return gcyaml }).Should( And( @@ -109,11 +91,10 @@ spec: "check GatewayClass condition", ) - Expect(s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defaultGateway, gatewayClassName), s.Namespace())). - NotTo(HaveOccurred(), "creating Gateway") + Expect(s.CreateResourceFromString(s.GetGatewayYaml())).NotTo(HaveOccurred(), "creating Gateway") s.RetryAssertion(func() string { - gcyaml, _ := s.GetResourceYaml("Gateway", "apisix") + gcyaml, _ := s.GetResourceYaml("Gateway", s.Namespace()) return gcyaml }).Should( And( @@ -133,12 +114,10 @@ spec: createSecret(s, secretName) By("create GatewayClass") - gatewayClassName := fmt.Sprintf("apisix-%d", time.Now().Nanosecond()) - Expect(s.CreateResourceFromStringWithNamespace(fmt.Sprintf(gatewayClassYaml, gatewayClassName, s.GetControllerName()), "")). - NotTo(HaveOccurred(), "creating GatewayClass") + Expect(s.CreateResourceFromString(s.GetGatewayClassYaml())).NotTo(HaveOccurred(), "creating GatewayClass") s.RetryAssertion(func() string { - gcyaml, _ := s.GetResourceYaml("GatewayClass", gatewayClassName) + gcyaml, _ := s.GetResourceYaml("GatewayClass", s.Namespace()) return gcyaml }).Should( And( @@ -149,11 +128,11 @@ spec: ) By("create Gateway") - err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defaultGatewayHTTPS, gatewayClassName), s.Namespace()) + err = s.CreateResourceFromString(fmt.Sprintf(defaultGatewayHTTPS, s.Namespace(), s.Namespace())) Expect(err).NotTo(HaveOccurred(), "creating Gateway") s.RetryAssertion(func() string { - gcyaml, _ := s.GetResourceYaml("Gateway", "apisix") + gcyaml, _ := s.GetResourceYaml("Gateway", s.Namespace()) return gcyaml }).Should( And( @@ -172,7 +151,7 @@ metadata: name: httpbin spec: parentRefs: - - name: apisix + - name: %s hostnames: - api6.com rules: @@ -189,18 +168,21 @@ spec: It("Create/Updtea/Delete HTTPRoute", func() { By("create HTTPRoute") - s.ResourceApplied("HTTPRoute", "httpbin", exactRouteByGet, 1) + gatewayName := s.Namespace() + s.ResourceApplied("HTTPRoute", "httpbin", fmt.Sprintf(exactRouteByGet, gatewayName), 1) By("access dataplane to check the HTTPRoute") s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/get", - Host: "api6.com", - Check: scaffold.WithExpectedStatus(200), + Method: "GET", + Path: "/get", + Host: "api6.com", + Check: scaffold.WithExpectedStatus(200), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) By("delete HTTPRoute") - err := s.DeleteResourceFromString(exactRouteByGet) + err := s.DeleteResourceFromString(fmt.Sprintf(exactRouteByGet, gatewayName)) Expect(err).NotTo(HaveOccurred(), "deleting HTTPRoute") s.RequestAssert(&scaffold.RequestAssert{ @@ -212,7 +194,7 @@ spec: }) }) - Context("HTTPRoute with Multiple Gateway", func() { + Context("HTTPRoute with Multiple Gateway", Serial, func() { var additionalGatewayGroupID string var additionalSvc *corev1.Service var additionalGatewayClassName string @@ -263,7 +245,7 @@ metadata: name: multi-gateway-route spec: parentRefs: - - name: apisix + - name: %s namespace: %s - name: additional-gateway namespace: %s @@ -294,7 +276,7 @@ spec: Expect(exists).To(BeTrue(), "additional gateway group should exist") By("Create additional GatewayClass") - additionalGatewayClassName = fmt.Sprintf("apisix-%d", time.Now().Unix()) + additionalGatewayClassName = fmt.Sprintf("additional-gatewayclass-%d", time.Now().Nanosecond()) err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(gatewayClassYaml, additionalGatewayClassName, s.GetControllerName()), "") Expect(err).NotTo(HaveOccurred(), "creating additional GatewayClass") @@ -323,15 +305,17 @@ spec: It("HTTPRoute should be accessible through both gateways", func() { By("Create HTTPRoute referencing both gateways") - multiGatewayRoute := fmt.Sprintf(multiGatewayHTTPRoute, s.Namespace(), additionalSvc.Namespace) + multiGatewayRoute := fmt.Sprintf(multiGatewayHTTPRoute, s.Namespace(), s.Namespace(), additionalSvc.Namespace) s.ResourceApplied("HTTPRoute", "multi-gateway-route", multiGatewayRoute, 1) By("Access through default gateway") s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/get", - Host: "httpbin.example", - Check: scaffold.WithExpectedStatus(http.StatusOK), + Method: "GET", + Path: "/get", + Host: "httpbin.example", + Check: scaffold.WithExpectedStatus(http.StatusOK), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) By("Access through additional gateway") @@ -339,11 +323,13 @@ spec: Expect(err).NotTo(HaveOccurred(), "creating client for additional gateway") s.RequestAssert(&scaffold.RequestAssert{ - Client: client, - Method: "GET", - Path: "/get", - Host: "httpbin-additional.example", - Check: scaffold.WithExpectedStatus(http.StatusOK), + Client: client, + Method: "GET", + Path: "/get", + Host: "httpbin-additional.example", + Check: scaffold.WithExpectedStatus(http.StatusOK), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) By("Delete Additional Gateway") @@ -352,10 +338,12 @@ spec: By("HTTPRoute should still be accessible through default gateway") s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/get", - Host: "httpbin.example", - Check: scaffold.WithExpectedStatus(http.StatusOK), + Method: "GET", + Path: "/get", + Host: "httpbin.example", + Check: scaffold.WithExpectedStatus(http.StatusOK), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) By("HTTPRoute should not be accessible through additional gateway") @@ -386,9 +374,10 @@ apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin + namespace: %s spec: parentRefs: - - name: apisix + - name: %s hostnames: - httpbin.external rules: @@ -407,7 +396,7 @@ metadata: name: httpbin spec: parentRefs: - - name: apisix + - name: %s hostnames: - httpbin.example rules: @@ -426,7 +415,7 @@ metadata: name: httpbin2 spec: parentRefs: - - name: apisix + - name: %s hostnames: - httpbin2.example rules: @@ -443,6 +432,7 @@ apiVersion: v1 kind: Service metadata: name: httpbin-multiple-port + namespace: %s spec: selector: app: httpbin-deployment-e2e-test @@ -465,9 +455,10 @@ apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin + namespace: %s spec: parentRefs: - - name: apisix + - name: %s hostnames: - httpbin.example rules: @@ -483,8 +474,9 @@ spec: BeforeEach(beforeEachHTTP) It("Create/Update/Delete HTTPRoute", func() { + gatewayName := s.Namespace() By("create HTTPRoute") - s.ResourceApplied("HTTPRoute", "httpbin", exactRouteByGet, 1) + s.ResourceApplied("HTTPRoute", "httpbin", fmt.Sprintf(exactRouteByGet, gatewayName), 1) By("access dataplane to check the HTTPRoute") s.RequestAssert(&scaffold.RequestAssert{ @@ -494,62 +486,73 @@ spec: }) s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/get", - Host: "httpbin.example", - Check: scaffold.WithExpectedStatus(http.StatusOK), + Method: "GET", + Path: "/get", + Host: "httpbin.example", + Check: scaffold.WithExpectedStatus(http.StatusOK), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) - Expect(s.DeleteResourceFromString(exactRouteByGet)). + Expect(s.DeleteResourceFromString(fmt.Sprintf(exactRouteByGet, gatewayName))). NotTo(HaveOccurred(), "deleting HTTPRoute") s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/get", - Host: "httpbin.example", - Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Method: "GET", + Path: "/get", + Host: "httpbin.example", + Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) }) It("Delete Gateway after apply HTTPRoute", func() { + gatewayName := s.Namespace() By("create HTTPRoute") - s.ResourceApplied("HTTPRoute", "httpbin", exactRouteByGet, 1) + s.ResourceApplied("HTTPRoute", "httpbin", fmt.Sprintf(exactRouteByGet, gatewayName), 1) By("access dataplane to check the HTTPRoute") s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/get", - Host: "httpbin.example", - Check: scaffold.WithExpectedStatus(http.StatusOK), + Method: "GET", + Path: "/get", + Host: "httpbin.example", + Check: scaffold.WithExpectedStatus(http.StatusOK), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) - Expect(s.DeleteResource("Gateway", "apisix")). + Expect(s.DeleteResource("Gateway", gatewayName)). NotTo(HaveOccurred(), "deleting Gateway") s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/get", - Host: "httpbin.example", - Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Method: "GET", + Path: "/get", + Host: "httpbin.example", + Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) }) It("Proxy External Service", func() { By("create HTTPRoute") - s.ResourceApplied("HTTPRoute", "httpbin", httprouteWithExternalName, 1) + s.ResourceApplied("HTTPRoute", "httpbin", fmt.Sprintf(httprouteWithExternalName, s.Namespace(), s.Namespace()), 1) By("checking the external service response") s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/get", - Host: "httpbin.external", - Check: scaffold.WithExpectedStatus(http.StatusOK), + Method: "GET", + Path: "/get", + Host: "httpbin.external", + Check: scaffold.WithExpectedStatus(http.StatusOK), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) }) It("Match Port", func() { By("create HTTPRoute") - s.ResourceApplied("HTTPRoute", "httpbin", invalidBackendPort, 1) + s.ResourceApplied("HTTPRoute", "httpbin", fmt.Sprintf(invalidBackendPort, s.Namespace(), s.Namespace(), s.Namespace()), 1) s.RetryAssertion(func() error { serviceResources, err := s.DefaultDataplaneResource().Service().List(context.Background()) @@ -574,23 +577,27 @@ spec: It("Delete HTTPRoute during restart", func() { By("create HTTPRoute httpbin") - s.ResourceApplied("HTTPRoute", "httpbin", exactRouteByGet, 1) + s.ResourceApplied("HTTPRoute", "httpbin", fmt.Sprintf(exactRouteByGet, s.Namespace()), 1) By("create HTTPRoute httpbin2") - s.ResourceApplied("HTTPRoute", "httpbin2", exactRouteByGet2, 1) + s.ResourceApplied("HTTPRoute", "httpbin2", fmt.Sprintf(exactRouteByGet2, s.Namespace()), 1) s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/get", - Host: "httpbin.example", - Check: scaffold.WithExpectedStatus(http.StatusOK), + Method: "GET", + Path: "/get", + Host: "httpbin.example", + Check: scaffold.WithExpectedStatus(http.StatusOK), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/get", - Host: "httpbin2.example", - Check: scaffold.WithExpectedStatus(http.StatusOK), + Method: "GET", + Path: "/get", + Host: "httpbin2.example", + Check: scaffold.WithExpectedStatus(http.StatusOK), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) s.Deployer.ScaleIngress(0) @@ -609,11 +616,12 @@ spec: }) s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/get", - Host: "httpbin2.example", - Timeout: 1 * time.Minute, - Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Method: "GET", + Path: "/get", + Host: "httpbin2.example", + Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) }) }) @@ -624,9 +632,10 @@ apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin + namespace: %s spec: parentRefs: - - name: apisix + - name: %s hostnames: - httpbin.example rules: @@ -643,9 +652,10 @@ apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin + namespace: %s spec: parentRefs: - - name: apisix + - name: %s hostnames: - httpbin.example rules: @@ -694,7 +704,7 @@ metadata: name: httpbin spec: parentRefs: - - name: apisix + - name: %s hostnames: - httpbin.example rules: @@ -714,7 +724,7 @@ metadata: name: httpbin spec: parentRefs: - - name: apisix + - name: %s hostnames: - httpbin.example rules: @@ -735,81 +745,97 @@ spec: It("HTTPRoute Exact Match", func() { By("create HTTPRoute") - s.ResourceApplied("HTTPRoute", "httpbin", exactRouteByGet, 1) + s.ResourceApplied("HTTPRoute", "httpbin", fmt.Sprintf(exactRouteByGet, s.Namespace(), s.Namespace()), 1) By("access daataplane to check the HTTPRoute") s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/get", - Host: "httpbin.example", - Check: scaffold.WithExpectedStatus(http.StatusOK), + Method: "GET", + Path: "/get", + Host: "httpbin.example", + Check: scaffold.WithExpectedStatus(http.StatusOK), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/get/xxx", - Host: "httpbin.example", - Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Method: "GET", + Path: "/get/xxx", + Host: "httpbin.example", + Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) }) It("HTTPRoute Prefix Match", func() { By("create HTTPRoute") - s.ResourceApplied("HTTPRoute", "httpbin", prefixRouteByStatus, 1) + s.ResourceApplied("HTTPRoute", "httpbin", fmt.Sprintf(prefixRouteByStatus, s.Namespace()), 1) By("access daataplane to check the HTTPRoute") s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/status/200", - Host: "httpbin.example", - Check: scaffold.WithExpectedStatus(http.StatusOK), + Method: "GET", + Path: "/status/200", + Host: "httpbin.example", + Check: scaffold.WithExpectedStatus(http.StatusOK), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/status/201", - Host: "httpbin.example", - Check: scaffold.WithExpectedStatus(http.StatusCreated), + Method: "GET", + Path: "/status/201", + Host: "httpbin.example", + Check: scaffold.WithExpectedStatus(http.StatusCreated), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) }) It("HTTPRoute Method Match", func() { By("create HTTPRoute") - s.ResourceApplied("HTTPRoute", "httpbin", methodRouteGETAndDELETEByAnything, 1) + s.ResourceApplied("HTTPRoute", "httpbin", fmt.Sprintf(methodRouteGETAndDELETEByAnything, s.Namespace()), 1) By("access daataplane to check the HTTPRoute") s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/anything", - Host: "httpbin.example", - Check: scaffold.WithExpectedStatus(http.StatusOK), + Method: "GET", + Path: "/anything", + Host: "httpbin.example", + Check: scaffold.WithExpectedStatus(http.StatusOK), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) s.RequestAssert(&scaffold.RequestAssert{ - Method: "DELETE", - Path: "/anything", - Host: "httpbin.example", - Check: scaffold.WithExpectedStatus(http.StatusOK), + Method: "DELETE", + Path: "/anything", + Host: "httpbin.example", + Check: scaffold.WithExpectedStatus(http.StatusOK), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) s.RequestAssert(&scaffold.RequestAssert{ - Method: "POST", - Path: "/anything", - Host: "httpbin.example", - Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Method: "POST", + Path: "/anything", + Host: "httpbin.example", + Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) }) It("HTTPRoute Vars Match", func() { By("create HTTPRoute") - s.ResourceApplied("HTTPRoute", "httpbin", varsRoute, 1) + s.ResourceApplied("HTTPRoute", "httpbin", fmt.Sprintf(varsRoute, s.Namespace(), s.Namespace()), 1) By("access dataplane to check the HTTPRoute") s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/get", - Host: "httpbin.example", - Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Method: "GET", + Path: "/get", + Host: "httpbin.example", + Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) s.RequestAssert(&scaffold.RequestAssert{ @@ -819,13 +845,15 @@ spec: Headers: map[string]string{ "X-Route-Name": "httpbin", }, - Check: scaffold.WithExpectedStatus(http.StatusOK), + Check: scaffold.WithExpectedStatus(http.StatusOK), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) }) It("HTTPRoutePolicy in effect", func() { By("create HTTPRoute") - s.ApplyHTTPRoute(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin"}, varsRoute) + s.ApplyHTTPRoute(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin"}, fmt.Sprintf(varsRoute, s.Namespace(), s.Namespace())) s.RequestAssert(&scaffold.RequestAssert{ Method: "GET", Path: "/get", @@ -833,12 +861,14 @@ spec: Headers: map[string]string{ "X-Route-Name": "httpbin", }, - Check: scaffold.WithExpectedStatus(http.StatusOK), + Check: scaffold.WithExpectedStatus(http.StatusOK), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) By("create HTTPRoutePolicy") s.ApplyHTTPRoutePolicy( - types.NamespacedName{Name: "apisix"}, + types.NamespacedName{Name: s.Namespace()}, types.NamespacedName{Namespace: s.Namespace(), Name: "http-route-policy-0"}, httpRoutePolicy, ) @@ -851,7 +881,9 @@ spec: Headers: map[string]string{ "X-Route-Name": "httpbin", }, - Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) s.RequestAssert(&scaffold.RequestAssert{ @@ -865,7 +897,9 @@ spec: "X-Route-Name": "httpbin", "X-HRP-Name": "http-route-policy-0", }, - Check: scaffold.WithExpectedStatus(http.StatusOK), + Check: scaffold.WithExpectedStatus(http.StatusOK), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) By("update HTTPRoutePolicy") @@ -887,7 +921,7 @@ spec: - new-hrp-name ` s.ApplyHTTPRoutePolicy( - types.NamespacedName{Name: "apisix"}, + types.NamespacedName{Name: s.Namespace()}, types.NamespacedName{Namespace: s.Namespace(), Name: "http-route-policy-0"}, changedHTTPRoutePolicy, ) @@ -904,7 +938,9 @@ spec: "X-Route-Name": "httpbin", "X-HRP-Name": "http-route-policy-0", }, - Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) // use the new vars can match the route @@ -916,7 +952,9 @@ spec: "X-Route-Name": "httpbin", "X-HRP-Name": "new-hrp-name", }, - Check: scaffold.WithExpectedStatus(http.StatusOK), + Check: scaffold.WithExpectedStatus(http.StatusOK), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) By("delete the HTTPRoutePolicy") @@ -925,7 +963,7 @@ spec: Eventually(func() string { _, err := s.GetResourceYaml("HTTPRoutePolicy", "http-route-policy-0") return err.Error() - }).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(ContainSubstring(`httproutepolicies.apisix.apache.org "http-route-policy-0" not found`)) + }).WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(ContainSubstring(`httproutepolicies.apisix.apache.org "http-route-policy-0" not found`)) // access the route without additional vars should be OK s.RequestAssert(&scaffold.RequestAssert{ Method: "GET", @@ -934,7 +972,9 @@ spec: Headers: map[string]string{ "X-Route-Name": "httpbin", }, - Check: scaffold.WithExpectedStatus(http.StatusOK), + Check: scaffold.WithExpectedStatus(http.StatusOK), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) }) @@ -1007,7 +1047,7 @@ spec: - http-route-policy-0 ` By("create HTTPRoute") - s.ApplyHTTPRoute(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin"}, varsRoute) + s.ApplyHTTPRoute(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin"}, fmt.Sprintf(varsRoute, s.Namespace(), s.Namespace())) By("create HTTPRoutePolices") for name, spec := range map[string]string{ @@ -1016,7 +1056,7 @@ spec: "http-route-policy-2": httpRoutePolicy2, } { s.ApplyHTTPRoutePolicy( - types.NamespacedName{Namespace: s.Namespace(), Name: "apisix"}, + types.NamespacedName{Namespace: s.Namespace(), Name: s.Namespace()}, types.NamespacedName{Namespace: s.Namespace(), Name: name}, spec, metav1.Condition{ @@ -1026,7 +1066,7 @@ spec: } for _, name := range []string{"http-route-policy-0", "http-route-policy-1", "http-route-policy-2"} { framework.HTTPRoutePolicyMustHaveCondition(s.GinkgoT, s.K8sClient, 10*time.Second, - types.NamespacedName{Namespace: s.Namespace(), Name: "apisix"}, + types.NamespacedName{Namespace: s.Namespace(), Name: s.Namespace()}, types.NamespacedName{Namespace: s.Namespace(), Name: name}, metav1.Condition{ Type: string(v1alpha2.PolicyConditionAccepted), @@ -1044,7 +1084,9 @@ spec: Headers: map[string]string{ "X-Route-Name": "httpbin", }, - Check: scaffold.WithExpectedStatus(http.StatusOK), + Check: scaffold.WithExpectedStatus(http.StatusOK), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) By("delete HTTPRoutePolicies") @@ -1052,7 +1094,7 @@ spec: Expect(err).NotTo(HaveOccurred(), "deleting HTTPRoutePolicy %s", "http-route-policy-2") for _, name := range []string{"http-route-policy-0", "http-route-policy-1"} { framework.HTTPRoutePolicyMustHaveCondition(s.GinkgoT, s.K8sClient, 10*time.Second, - types.NamespacedName{Namespace: s.Namespace(), Name: "apisix"}, + types.NamespacedName{Namespace: s.Namespace(), Name: s.Namespace()}, types.NamespacedName{Namespace: s.Namespace(), Name: name}, metav1.Condition{ Type: string(v1alpha2.PolicyConditionAccepted), @@ -1068,14 +1110,16 @@ spec: Headers: map[string]string{ "X-Route-Name": "httpbin", }, - Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) By("update HTTPRoutePolicy") - err = s.CreateResourceFromString(httpRoutePolicy1Priority20) + err = s.CreateResourceFromStringWithNamespace(httpRoutePolicy1Priority20, s.Namespace()) Expect(err).NotTo(HaveOccurred(), "update HTTPRoutePolicy's priority to 20") framework.HTTPRoutePolicyMustHaveCondition(s.GinkgoT, s.K8sClient, 10*time.Second, - types.NamespacedName{Namespace: s.Namespace(), Name: "apisix"}, + types.NamespacedName{Namespace: s.Namespace(), Name: s.Namespace()}, types.NamespacedName{Namespace: s.Namespace(), Name: "http-route-policy-1"}, metav1.Condition{ Type: string(v1alpha2.PolicyConditionAccepted), @@ -1083,7 +1127,7 @@ spec: ) for _, name := range []string{"http-route-policy-0", "http-route-policy-1"} { framework.HTTPRoutePolicyMustHaveCondition(s.GinkgoT, s.K8sClient, 10*time.Second, - types.NamespacedName{Namespace: s.Namespace(), Name: "apisix"}, + types.NamespacedName{Namespace: s.Namespace(), Name: s.Namespace()}, types.NamespacedName{Namespace: s.Namespace(), Name: name}, metav1.Condition{ Type: string(v1alpha2.PolicyConditionAccepted), @@ -1100,17 +1144,19 @@ spec: Headers: map[string]string{ "X-Route-Name": "httpbin", }, - Check: scaffold.WithExpectedStatus(http.StatusOK), + Check: scaffold.WithExpectedStatus(http.StatusOK), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) }) It("HTTPRoutePolicy status changes on HTTPRoute deleting", func() { By("create HTTPRoute") - s.ApplyHTTPRoute(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin"}, varsRoute) + s.ApplyHTTPRoute(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin"}, fmt.Sprintf(varsRoute, s.Namespace(), s.Namespace())) By("create HTTPRoutePolicy") s.ApplyHTTPRoutePolicy( - types.NamespacedName{Name: "apisix"}, + types.NamespacedName{Name: s.Namespace()}, types.NamespacedName{Namespace: s.Namespace(), Name: "http-route-policy-0"}, httpRoutePolicy, ) @@ -1123,7 +1169,9 @@ spec: Headers: map[string]string{ "X-Route-Name": "httpbin", }, - Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) s.RequestAssert(&scaffold.RequestAssert{ @@ -1137,7 +1185,9 @@ spec: "X-Route-Name": "httpbin", "X-HRP-Name": "http-route-policy-0", }, - Check: scaffold.WithExpectedStatus(http.StatusOK), + Check: scaffold.WithExpectedStatus(http.StatusOK), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) By("delete the HTTPRoute, assert the HTTPRoutePolicy's status will be changed") @@ -1155,7 +1205,9 @@ spec: "X-Route-Name": "httpbin", "X-HRP-Name": "http-route-policy-0", }, - Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) err := framework.PollUntilHTTPRoutePolicyHaveStatus(s.K8sClient, 8*time.Second, types.NamespacedName{Namespace: s.Namespace(), Name: "http-route-policy-0"}, @@ -1173,9 +1225,10 @@ apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin + namespace: %s spec: parentRefs: - - name: apisix + - name: %s hostnames: - httpbin.example rules: @@ -1204,9 +1257,10 @@ apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin + namespace: %s spec: parentRefs: - - name: apisix + - name: %s hostnames: - httpbin.example rules: @@ -1235,9 +1289,10 @@ apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin + namespace: %s spec: parentRefs: - - name: apisix + - name: %s hostnames: - httpbin.example rules: @@ -1257,9 +1312,10 @@ apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin + namespace: %s spec: parentRefs: - - name: apisix + - name: %s hostnames: - httpbin.example rules: @@ -1279,9 +1335,10 @@ apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin + namespace: %s spec: parentRefs: - - name: apisix + - name: %s hostnames: - httpbin.example rules: @@ -1305,9 +1362,10 @@ apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin + namespace: %s spec: parentRefs: - - name: apisix + - name: %s hostnames: - httpbin.example rules: @@ -1354,9 +1412,10 @@ apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin + namespace: %s spec: parentRefs: - - name: apisix + - name: %s hostnames: - httpbin.example rules: @@ -1379,7 +1438,7 @@ spec: It("HTTPRoute RequestHeaderModifier", func() { By("create HTTPRoute") - s.ResourceApplied("HTTPRoute", "httpbin", reqHeaderModifyByHeaders, 1) + s.ResourceApplied("HTTPRoute", "httpbin", fmt.Sprintf(reqHeaderModifyByHeaders, s.Namespace(), s.Namespace()), 1) By("access daataplane to check the HTTPRoute") s.RequestAssert(&scaffold.RequestAssert{ @@ -1396,12 +1455,14 @@ spec: scaffold.WithExpectedBodyContains(`"X-Req-Add": "test,add"`, `"X-Req-Set": "set"`), scaffold.WithExpectedBodyNotContains(`"X-Req-Removed": "remove"`), }, + Timeout: time.Second * 30, + Interval: time.Second * 2, }) }) It("HTTPRoute ResponseHeaderModifier", func() { By("create HTTPRoute") - s.ResourceApplied("HTTPRoute", "httpbin", respHeaderModifyByHeaders, 1) + s.ResourceApplied("HTTPRoute", "httpbin", fmt.Sprintf(respHeaderModifyByHeaders, s.Namespace(), s.Namespace()), 1) By("access daataplane to check the HTTPRoute") s.RequestAssert(&scaffold.RequestAssert{ @@ -1417,12 +1478,14 @@ spec: }), scaffold.WithExpectedBodyNotContains(`"X-Resp-Add": "add"`, `"X-Resp-Set": "set"`, `"Server"`), }, + Timeout: time.Second * 30, + Interval: time.Second * 2, }) }) It("HTTPRoute RequestRedirect", func() { By("create HTTPRoute") - s.ResourceApplied("HTTPRoute", "httpbin", httpsRedirectByHeaders, 1) + s.ResourceApplied("HTTPRoute", "httpbin", fmt.Sprintf(httpsRedirectByHeaders, s.Namespace(), s.Namespace()), 1) s.RequestAssert(&scaffold.RequestAssert{ Method: "GET", @@ -1432,10 +1495,12 @@ spec: scaffold.WithExpectedStatus(http.StatusFound), scaffold.WithExpectedHeader("Location", "https://httpbin.example:9443/headers"), }, + Timeout: time.Second * 30, + Interval: time.Second * 2, }) By("update HTTPRoute") - s.ResourceApplied("HTTPRoute", "httpbin", hostnameRedirectByHeaders, 2) + s.ResourceApplied("HTTPRoute", "httpbin", fmt.Sprintf(hostnameRedirectByHeaders, s.Namespace(), s.Namespace()), 2) s.RequestAssert(&scaffold.RequestAssert{ Method: "GET", @@ -1445,6 +1510,8 @@ spec: scaffold.WithExpectedStatus(http.StatusMovedPermanently), scaffold.WithExpectedHeader("Location", "http://httpbin.org/headers"), }, + Timeout: time.Second * 30, + Interval: time.Second * 2, }) }) @@ -1487,9 +1554,10 @@ apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin + namespace: %s spec: parentRefs: - - name: apisix + - name: %s hostnames: - httpbin.example rules: @@ -1507,7 +1575,7 @@ spec: - name: httpbin-service-e2e-test port: 80 ` - s.ResourceApplied("HTTPRoute", "httpbin", echoRoute, 1) + s.ResourceApplied("HTTPRoute", "httpbin", fmt.Sprintf(echoRoute, s.Namespace(), s.Namespace()), 1) s.RetryAssertion(func() string { resp := s.NewAPISIXClient().GET("/headers").WithHost("httpbin.example").Expect().Raw() @@ -1520,7 +1588,7 @@ spec: It("HTTPRoute URLRewrite with ReplaceFullPath And Hostname", func() { By("create HTTPRoute") - s.ResourceApplied("HTTPRoute", "httpbin", replaceFullPathAndHost, 1) + s.ResourceApplied("HTTPRoute", "httpbin", fmt.Sprintf(replaceFullPathAndHost, s.Namespace(), s.Namespace()), 1) By("/replace/201 should be rewritten to /headers") s.RequestAssert(&scaffold.RequestAssert{ @@ -1531,6 +1599,8 @@ spec: scaffold.WithExpectedStatus(http.StatusOK), scaffold.WithExpectedBodyContains("replace.example.org"), }, + Timeout: time.Second * 30, + Interval: time.Second * 2, }) By("/replace/500 should be rewritten to /headers") @@ -1542,19 +1612,23 @@ spec: scaffold.WithExpectedStatus(http.StatusOK), scaffold.WithExpectedBodyContains("replace.example.org"), }, + Timeout: time.Second * 30, + Interval: time.Second * 2, }) }) It("HTTPRoute URLRewrite with ReplacePrefixMatch", func() { By("create HTTPRoute") - s.ResourceApplied("HTTPRoute", "httpbin", replacePrefixMatch, 1) + s.ResourceApplied("HTTPRoute", "httpbin", fmt.Sprintf(replacePrefixMatch, s.Namespace(), s.Namespace()), 1) By("/replace/201 should be rewritten to /status/201") s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/replace/201", - Host: "httpbin.example", - Check: scaffold.WithExpectedStatus(http.StatusCreated), + Method: "GET", + Path: "/replace/201", + Host: "httpbin.example", + Check: scaffold.WithExpectedStatus(http.StatusCreated), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) By("/replace/500 should be rewritten to /status/500") @@ -1565,30 +1639,36 @@ spec: Checks: []scaffold.ResponseCheckFunc{ scaffold.WithExpectedStatus(http.StatusInternalServerError), }, + Timeout: time.Second * 30, + Interval: time.Second * 2, }) }) It("HTTPRoute ExtensionRef", func() { By("create HTTPRoute") - Expect(s.CreateResourceFromString(echoPlugin)). + Expect(s.CreateResourceFromStringWithNamespace(echoPlugin, s.Namespace())). NotTo(HaveOccurred(), "creating PluginConfig") - s.ResourceApplied("HTTPRoute", "httpbin", extensionRefEchoPlugin, 1) + s.ResourceApplied("HTTPRoute", "httpbin", fmt.Sprintf(extensionRefEchoPlugin, s.Namespace(), s.Namespace()), 1) s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/get", - Host: "httpbin.example", - Check: scaffold.WithExpectedBodyContains("Hello, World!!"), + Method: "GET", + Path: "/get", + Host: "httpbin.example", + Check: scaffold.WithExpectedBodyContains("Hello, World!!"), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) - Expect(s.CreateResourceFromString(echoPluginUpdated)). + Expect(s.CreateResourceFromStringWithNamespace(echoPluginUpdated, s.Namespace())). NotTo(HaveOccurred(), "updating PluginConfig") s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/get", - Host: "httpbin.example", - Check: scaffold.WithExpectedBodyContains("Updated"), + Method: "GET", + Path: "/get", + Host: "httpbin.example", + Check: scaffold.WithExpectedBodyContains("Updated"), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) }) }) @@ -1601,7 +1681,7 @@ metadata: name: httpbin spec: parentRefs: - - name: apisix + - name: %s hostnames: - httpbin.example rules: @@ -1624,7 +1704,7 @@ metadata: name: httpbin spec: parentRefs: - - name: apisix + - name: %s hostnames: - httpbin.example rules: @@ -1648,7 +1728,7 @@ spec: }) }) It("HTTPRoute Canary", func() { - s.ResourceApplied("HTTPRoute", "httpbin", sameWeiht, 1) + s.ResourceApplied("HTTPRoute", "httpbin", fmt.Sprintf(sameWeiht, s.Namespace()), 1) time.Sleep(5 * time.Second) s.RetryAssertion(func() int { @@ -1675,7 +1755,7 @@ spec: return hitNginxCnt - hitHttpbinCnt }).WithTimeout(2 * time.Minute).Should(BeNumerically("~", 0, 2)) - s.ResourceApplied("HTTPRoute", "httpbin", oneWeiht, 2) + s.ResourceApplied("HTTPRoute", "httpbin", fmt.Sprintf(oneWeiht, s.Namespace()), 2) s.RetryAssertion(func() int { var ( @@ -1713,7 +1793,7 @@ metadata: name: httpbin spec: parentRefs: - - name: apisix + - name: %s hostnames: - httpbin.example rules: @@ -1747,14 +1827,16 @@ spec: It("Should sync HTTPRoute when GatewayProxy is updated", func() { By("create HTTPRoute") - s.ResourceApplied("HTTPRoute", "httpbin", exactRouteByGet, 1) + s.ResourceApplied("HTTPRoute", "httpbin", fmt.Sprintf(exactRouteByGet, s.Namespace()), 1) By("verify HTTPRoute works") s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/get", - Host: "httpbin.example", - Check: scaffold.WithExpectedStatus(http.StatusOK), + Method: "GET", + Path: "/get", + Host: "httpbin.example", + Check: scaffold.WithExpectedStatus(http.StatusOK), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) By("create additional gateway group to get new admin key") @@ -1770,11 +1852,13 @@ spec: By("HTTPRoute not found for additional gateway group") s.RequestAssert(&scaffold.RequestAssert{ - Client: client, - Method: "GET", - Path: "/get", - Host: "httpbin.example", - Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Client: client, + Method: "GET", + Path: "/get", + Host: "httpbin.example", + Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) By("update GatewayProxy with new admin key") @@ -1784,11 +1868,13 @@ spec: By("verify HTTPRoute works for additional gateway group") s.RequestAssert(&scaffold.RequestAssert{ - Client: client, - Method: "GET", - Path: "/get", - Host: "httpbin.example", - Check: scaffold.WithExpectedStatus(http.StatusOK), + Client: client, + Method: "GET", + Path: "/get", + Host: "httpbin.example", + Check: scaffold.WithExpectedStatus(http.StatusOK), + Timeout: time.Second * 30, + Interval: time.Second * 2, }) }) }) @@ -1834,7 +1920,7 @@ metadata: name: lb-route spec: parentRefs: - - name: apisix + - name: %s rules: - matches: - path: @@ -1850,11 +1936,18 @@ spec: ` By("apply services and HTTPRoute") - err := s.CreateResourceFromString(servicesSpec) + err := s.CreateResourceFromStringWithNamespace(fmt.Sprintf(servicesSpec, s.Namespace()), s.Namespace()) Expect(err).ShouldNot(HaveOccurred(), "apply services and HTTPRoute") - time.Sleep(5 * time.Second) + time.Sleep(10 * time.Second) By("verify load balancing works") + s.RequestAssert(&scaffold.RequestAssert{ + Method: "GET", + Path: "/headers", + Check: scaffold.WithExpectedStatus(http.StatusOK), + Timeout: 1 * time.Minute, + Interval: 2 * time.Second, + }) // Test multiple requests to verify load balancing upstreamHosts := make(map[string]int) totalRequests := 20 @@ -1890,7 +1983,7 @@ metadata: name: httpbin spec: parentRefs: - - name: apisix + - name: %s hostnames: - httpbin rules: @@ -1925,19 +2018,23 @@ spec: It("Should sync ApisixRoute during startup", func() { By("apply ApisixRoute") Expect(s.CreateResourceFromString(route2)).ShouldNot(HaveOccurred(), "applying HTTPRoute with non-existent parent") - s.ResourceApplied("HTTPRoute", "httpbin", route, 1) + s.ResourceApplied("HTTPRoute", "httpbin", fmt.Sprintf(route, s.Namespace()), 1) s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/get", - Host: "httpbin", - Check: scaffold.WithExpectedStatus(http.StatusOK), + Method: "GET", + Path: "/get", + Host: "httpbin", + Check: scaffold.WithExpectedStatus(http.StatusOK), + Interval: time.Second * 2, + Timeout: 30 * time.Second, }) s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/get", - Host: "httpbin2", - Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Method: "GET", + Path: "/get", + Host: "httpbin2", + Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Interval: time.Second * 2, + Timeout: 30 * time.Second, }) By("restart controller and dataplane") @@ -1947,17 +2044,20 @@ spec: s.Deployer.ScaleIngress(1) s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/get", - Host: "httpbin", - Timeout: 1 * time.Minute, - Check: scaffold.WithExpectedStatus(http.StatusOK), + Method: "GET", + Path: "/get", + Host: "httpbin", + Check: scaffold.WithExpectedStatus(http.StatusOK), + Interval: time.Second * 2, + Timeout: 1 * time.Minute, }) s.RequestAssert(&scaffold.RequestAssert{ - Method: "GET", - Path: "/get", - Host: "httpbin2", - Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Method: "GET", + Path: "/get", + Host: "httpbin2", + Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Interval: time.Second * 2, + Timeout: 30 * time.Second, }) }) diff --git a/test/e2e/gatewayapi/status.go b/test/e2e/gatewayapi/status.go index 80081ea84..3c50499f3 100644 --- a/test/e2e/gatewayapi/status.go +++ b/test/e2e/gatewayapi/status.go @@ -33,8 +33,7 @@ import ( var _ = Describe("Test Gateway API Status", Label("networking.k8s.io", "httproute"), func() { var ( - s = scaffold.NewScaffold(&scaffold.Options{ - ControllerName: "apisix.apache.org/apisix-ingress-controller", + s = scaffold.NewScaffold(scaffold.Options{ // for triggering the sync SyncPeriod: 3 * time.Second, }) @@ -92,7 +91,7 @@ spec: time.Sleep(5 * time.Second) By("create GatewayClass") - gatewayClassName := fmt.Sprintf("apisix-%d", time.Now().Unix()) + gatewayClassName := s.Namespace() err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(gatewayClass, gatewayClassName, s.GetControllerName()), "") Expect(err).NotTo(HaveOccurred(), "creating GatewayClass") time.Sleep(5 * time.Second) diff --git a/test/e2e/ingress/ingress.go b/test/e2e/ingress/ingress.go index 6b537b989..ed0922cd8 100644 --- a/test/e2e/ingress/ingress.go +++ b/test/e2e/ingress/ingress.go @@ -47,16 +47,14 @@ func createSecret(s *scaffold.Scaffold, secretName string) { } var _ = Describe("Test Ingress", Label("networking.k8s.io", "ingress"), func() { - s := scaffold.NewScaffold(&scaffold.Options{ - ControllerName: "apisix.apache.org/apisix-ingress-controller", - }) + s := scaffold.NewDefaultScaffold() var gatewayProxyYaml = ` apiVersion: apisix.apache.org/v1alpha1 kind: GatewayProxy metadata: name: apisix-proxy-config - namespace: default + namespace: %s spec: provider: type: ControlPlane @@ -72,10 +70,10 @@ spec: Context("Ingress TLS", func() { It("Check if SSL resource was created", func() { By("create GatewayProxy") - gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Deployer.GetAdminEndpoint(), s.AdminKey()) + gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Namespace(), s.Deployer.GetAdminEndpoint(), s.AdminKey()) By("create GatewayProxy") - err := s.CreateResourceFromStringWithNamespace(gatewayProxy, "default") + err := s.CreateResourceFromStringWithNamespace(gatewayProxy, s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy") time.Sleep(5 * time.Second) @@ -87,14 +85,14 @@ spec: apiVersion: networking.k8s.io/v1 kind: IngressClass metadata: - name: apisix + name: %s spec: - controller: "apisix.apache.org/apisix-ingress-controller" + controller: "%s" parameters: apiGroup: "apisix.apache.org" kind: "GatewayProxy" name: "apisix-proxy-config" - namespace: "default" + namespace: "%s" scope: "Namespace" ` @@ -104,7 +102,7 @@ kind: Ingress metadata: name: apisix-ingress-tls spec: - ingressClassName: apisix + ingressClassName: %s tls: - hosts: - %s @@ -120,15 +118,15 @@ spec: name: httpbin-service-e2e-test port: number: 80 -`, host, secretName, host) +`, s.Namespace(), host, secretName, host) By("create IngressClass") - err = s.CreateResourceFromStringWithNamespace(defaultIngressClass, "") + err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defaultIngressClass, s.Namespace(), s.GetControllerName(), s.Namespace()), "") Expect(err).NotTo(HaveOccurred(), "creating IngressClass") time.Sleep(5 * time.Second) By("create Ingress with TLS") - err = s.CreateResourceFromString(tlsIngress) + err = s.CreateResourceFromStringWithNamespace(tlsIngress, s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating Ingress with TLS") time.Sleep(5 * time.Second) @@ -142,7 +140,8 @@ spec: }) }) - Context("IngressClass Selection", func() { + // Tests concerning the default ingress class need to be run serially + Context("IngressClass Selection", Serial, func() { var defaultIngressClass = ` apiVersion: networking.k8s.io/v1 kind: IngressClass @@ -151,12 +150,12 @@ metadata: annotations: ingressclass.kubernetes.io/is-default-class: "true" spec: - controller: "apisix.apache.org/apisix-ingress-controller" + controller: "%s" parameters: apiGroup: "apisix.apache.org" kind: "GatewayProxy" name: "apisix-proxy-config" - namespace: "default" + namespace: "%s" scope: "Namespace" ` @@ -164,7 +163,7 @@ spec: apiVersion: networking.k8s.io/v1 kind: Ingress metadata: - name: apisix-ingress-default + name: %s spec: rules: - host: default.example.com @@ -191,7 +190,7 @@ spec: apiVersion: networking.k8s.io/v1 kind: Ingress metadata: - name: apisix-ingress-external + name: %s spec: rules: - host: httpbin.external @@ -208,18 +207,18 @@ spec: It("Test IngressClass Selection", func() { By("create GatewayProxy") - gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Deployer.GetAdminEndpoint(), s.AdminKey()) - err := s.CreateResourceFromStringWithNamespace(gatewayProxy, "default") + gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Namespace(), s.Deployer.GetAdminEndpoint(), s.AdminKey()) + err := s.CreateResourceFromStringWithNamespace(gatewayProxy, s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy") time.Sleep(5 * time.Second) By("create Default IngressClass") - err = s.CreateResourceFromStringWithNamespace(defaultIngressClass, "") + err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defaultIngressClass, s.GetControllerName(), s.Namespace()), s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating Default IngressClass") time.Sleep(5 * time.Second) By("create Ingress without IngressClass") - err = s.CreateResourceFromString(defaultIngress) + err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defaultIngress, s.Namespace()), s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating Ingress without IngressClass") time.Sleep(5 * time.Second) @@ -233,79 +232,89 @@ spec: It("Proxy External Service", func() { By("create GatewayProxy") - gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Deployer.GetAdminEndpoint(), s.AdminKey()) - err := s.CreateResourceFromStringWithNamespace(gatewayProxy, "default") + gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Namespace(), s.Deployer.GetAdminEndpoint(), s.AdminKey()) + err := s.CreateResourceFromStringWithNamespace(gatewayProxy, s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy") time.Sleep(5 * time.Second) By("create Default IngressClass") - err = s.CreateResourceFromStringWithNamespace(defaultIngressClass, "") + err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defaultIngressClass, s.GetControllerName(), s.Namespace()), s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating Default IngressClass") time.Sleep(5 * time.Second) By("create Ingress") - err = s.CreateResourceFromString(ingressWithExternalName) + ingressName := s.Namespace() + "-external" + err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(ingressWithExternalName, ingressName), s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating Ingress without IngressClass") - time.Sleep(5 * time.Second) By("checking the external service response") - s.NewAPISIXClient(). - GET("/get"). - WithHost("httpbin.external"). - Expect(). - Status(http.StatusOK) + s.RequestAssert(&scaffold.RequestAssert{ + Method: "GET", + Path: "/get", + Host: "httpbin.external", + Check: scaffold.WithExpectedStatus(http.StatusOK), + Interval: time.Second * 10, + Timeout: 3 * time.Minute, + }) }) It("Delete Ingress during restart", func() { By("create GatewayProxy") - gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Deployer.GetAdminEndpoint(), s.AdminKey()) - err := s.CreateResourceFromStringWithNamespace(gatewayProxy, "default") + gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Namespace(), s.Deployer.GetAdminEndpoint(), s.AdminKey()) + err := s.CreateResourceFromStringWithNamespace(gatewayProxy, s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy") time.Sleep(5 * time.Second) By("create Default IngressClass") - err = s.CreateResourceFromStringWithNamespace(defaultIngressClass, "") + err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defaultIngressClass, s.GetControllerName(), s.Namespace()), s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating Default IngressClass") time.Sleep(5 * time.Second) By("create Ingress with ExternalName") - err = s.CreateResourceFromString(ingressWithExternalName) + ingressName := s.Namespace() + "-external" + err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(ingressWithExternalName, ingressName), s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating Ingress without IngressClass") time.Sleep(5 * time.Second) By("create Ingress") - err = s.CreateResourceFromString(defaultIngress) + err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defaultIngress, s.Namespace()), s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating Ingress without IngressClass") - time.Sleep(5 * time.Second) By("checking the external service response") - s.NewAPISIXClient(). - GET("/get"). - WithHost("httpbin.external"). - Expect(). - Status(http.StatusOK) - - s.NewAPISIXClient(). - GET("/get"). - WithHost("default.example.com"). - Expect(). - Status(200) - + s.RequestAssert(&scaffold.RequestAssert{ + Method: "GET", + Path: "/get", + Host: "httpbin.external", + Check: scaffold.WithExpectedStatus(http.StatusOK), + Interval: time.Second * 10, + Timeout: 3 * time.Minute, + }) + + s.RequestAssert(&scaffold.RequestAssert{ + Method: "GET", + Path: "/get", + Host: "default.example.com", + Check: scaffold.WithExpectedStatus(http.StatusOK), + Interval: time.Second * 2, + Timeout: time.Minute, + }) s.Deployer.ScaleIngress(0) By("delete Ingress") - err = s.DeleteResourceFromString(defaultIngress) + err = s.DeleteResourceFromStringWithNamespace(fmt.Sprintf(defaultIngress, s.Namespace()), s.Namespace()) Expect(err).NotTo(HaveOccurred(), "deleting Ingress without IngressClass") s.Deployer.ScaleIngress(1) time.Sleep(1 * time.Minute) - s.NewAPISIXClient(). - GET("/get"). - WithHost("httpbin.external"). - Expect(). - Status(http.StatusOK) - + s.RequestAssert(&scaffold.RequestAssert{ + Method: "GET", + Path: "/get", + Host: "httpbin.external", + Check: scaffold.WithExpectedStatus(http.StatusOK), + Interval: time.Second * 10, + Timeout: 3 * time.Minute, + }) s.NewAPISIXClient(). GET("/get"). WithHost("default.example.com"). @@ -314,13 +323,14 @@ spec: }) }) - Context("IngressClass with GatewayProxy", func() { + // Tests concerning the default ingress class need to be run serially + Context("IngressClass with GatewayProxy", Serial, func() { gatewayProxyYaml := ` apiVersion: apisix.apache.org/v1alpha1 kind: GatewayProxy metadata: name: apisix-proxy-config - namespace: default + namespace: %s spec: provider: type: ControlPlane @@ -344,7 +354,7 @@ apiVersion: apisix.apache.org/v1alpha1 kind: GatewayProxy metadata: name: apisix-proxy-config-with-secret - namespace: default + namespace: %s spec: provider: type: ControlPlane @@ -374,12 +384,12 @@ metadata: annotations: ingressclass.kubernetes.io/is-default-class: "true" spec: - controller: "apisix.apache.org/apisix-ingress-controller" + controller: "%s" parameters: apiGroup: "apisix.apache.org" kind: "GatewayProxy" name: "apisix-proxy-config" - namespace: "default" + namespace: "%s" scope: "Namespace" ` @@ -389,12 +399,12 @@ kind: IngressClass metadata: name: apisix-with-proxy-secret spec: - controller: "apisix.apache.org/apisix-ingress-controller" + controller: "%s" parameters: apiGroup: "apisix.apache.org" kind: "GatewayProxy" name: "apisix-proxy-config-with-secret" - namespace: "default" + namespace: "%s" scope: "Namespace" ` @@ -440,20 +450,20 @@ spec: It("Test IngressClass with GatewayProxy", func() { By("create GatewayProxy") - gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Deployer.GetAdminEndpoint(), s.AdminKey()) + gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Namespace(), s.Deployer.GetAdminEndpoint(), s.AdminKey()) By("create GatewayProxy") - err := s.CreateResourceFromStringWithNamespace(gatewayProxy, "default") + err := s.CreateResourceFromStringWithNamespace(gatewayProxy, s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy") time.Sleep(5 * time.Second) By("create IngressClass with GatewayProxy reference") - err = s.CreateResourceFromStringWithNamespace(ingressClassWithProxy, "") + err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(ingressClassWithProxy, s.GetControllerName(), s.Namespace()), "") Expect(err).NotTo(HaveOccurred(), "creating IngressClass with GatewayProxy") time.Sleep(5 * time.Second) By("create Ingress with GatewayProxy IngressClass") - err = s.CreateResourceFromString(testIngress) + err = s.CreateResourceFromStringWithNamespace(testIngress, s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating Ingress with GatewayProxy IngressClass") time.Sleep(5 * time.Second) @@ -473,28 +483,27 @@ apiVersion: v1 kind: Secret metadata: name: admin-secret - namespace: default type: Opaque stringData: admin-key: %s `, s.AdminKey()) - err := s.CreateResourceFromStringWithNamespace(adminSecret, "default") + err := s.CreateResourceFromStringWithNamespace(adminSecret, s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating admin secret") time.Sleep(5 * time.Second) By("create GatewayProxy with Secret reference") - gatewayProxy := fmt.Sprintf(gatewayProxyWithSecretYaml, s.Deployer.GetAdminEndpoint()) - err = s.CreateResourceFromStringWithNamespace(gatewayProxy, "default") + gatewayProxy := fmt.Sprintf(gatewayProxyWithSecretYaml, s.Namespace(), s.Deployer.GetAdminEndpoint()) + err = s.CreateResourceFromStringWithNamespace(gatewayProxy, s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy with Secret") time.Sleep(5 * time.Second) By("create IngressClass with GatewayProxy reference") - err = s.CreateResourceFromStringWithNamespace(ingressClassWithProxySecret, "") + err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(ingressClassWithProxySecret, s.GetControllerName(), s.Namespace()), "") Expect(err).NotTo(HaveOccurred(), "creating IngressClass with GatewayProxy") time.Sleep(5 * time.Second) By("create Ingress with GatewayProxy IngressClass") - err = s.CreateResourceFromString(testIngressWithSecret) + err = s.CreateResourceFromStringWithNamespace(testIngressWithSecret, s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating Ingress with GatewayProxy IngressClass") time.Sleep(5 * time.Second) @@ -515,7 +524,7 @@ apiVersion: apisix.apache.org/v1alpha1 kind: GatewayProxy metadata: name: apisix-proxy-config - namespace: default + namespace: %s spec: provider: type: ControlPlane @@ -526,21 +535,21 @@ spec: type: AdminKey adminKey: value: "%s" -`, s.Deployer.GetAdminEndpoint(), s.AdminKey()) +`, s.Namespace(), s.Deployer.GetAdminEndpoint(), s.AdminKey()) } const ingressClassSpec = ` apiVersion: networking.k8s.io/v1 kind: IngressClass metadata: - name: apisix + name: %s spec: - controller: "apisix.apache.org/apisix-ingress-controller" + controller: "%s" parameters: apiGroup: "apisix.apache.org" kind: "GatewayProxy" name: "apisix-proxy-config" - namespace: "default" + namespace: "%s" scope: "Namespace" ` const ingressSpec = ` @@ -549,7 +558,7 @@ kind: Ingress metadata: name: default spec: - ingressClassName: apisix + ingressClassName: %s rules: - host: example.com http: @@ -628,49 +637,49 @@ spec: ` BeforeEach(func() { By("create GatewayProxy") - err := s.CreateResourceFromStringWithNamespace(getGatewayProxySpec(), "default") + err := s.CreateResourceFromStringWithNamespace(getGatewayProxySpec(), s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy") time.Sleep(5 * time.Second) By("create IngressClass") - err = s.CreateResourceFromStringWithNamespace(ingressClassSpec, "") + err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(ingressClassSpec, s.Namespace(), s.GetControllerName(), s.Namespace()), s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating GatewayClass") time.Sleep(5 * time.Second) }) It("HTTPRoutePolicy targetRef an Ingress", func() { By("create Ingress") - err := s.CreateResourceFromString(ingressSpec) + err := s.CreateResourceFromStringWithNamespace(fmt.Sprintf(ingressSpec, s.Namespace()), s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating Ingress") By("request the route should be OK") Eventually(func() int { return s.NewAPISIXClient().GET("/get").WithHost("example.com").Expect().Raw().StatusCode }). - WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) + WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) By("create HTTPRoutePolicy") - err = s.CreateResourceFromString(httpRoutePolicySpec0) + err = s.CreateResourceFromStringWithNamespace(httpRoutePolicySpec0, s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating HTTPRoutePolicy") Eventually(func() string { spec, err := s.GetResourceYaml("HTTPRoutePolicy", "http-route-policy-0") Expect(err).NotTo(HaveOccurred(), "HTTPRoutePolicy status should be True") return spec }). - WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(ContainSubstring(`status: "True"`)) + WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(ContainSubstring(`status: "True"`)) By("request the route without vars should be Not Found") Eventually(func() int { return s.NewAPISIXClient().GET("/get").WithHost("example.com").Expect().Raw().StatusCode }). - WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusNotFound)) + WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusNotFound)) By("request the route with the correct vars should be OK") s.NewAPISIXClient().GET("/get").WithHost("example.com"). WithHeader("X-HRP-Name", "http-route-policy-0").Expect().Status(http.StatusOK) By("update the HTTPRoutePolicy") - err = s.CreateResourceFromString(httpRoutePolicySpec1) + err = s.CreateResourceFromStringWithNamespace(httpRoutePolicySpec1, s.Namespace()) Expect(err).NotTo(HaveOccurred(), "updating HTTPRoutePolicy") By("request with the old vars should be Not Found") @@ -678,44 +687,44 @@ spec: return s.NewAPISIXClient().GET("/get").WithHost("example.com"). WithHeader("X-HRP-Name", "http-route-policy-0").Expect().Raw().StatusCode }). - WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusNotFound)) + WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusNotFound)) By("request with the new vars should be OK") s.NewAPISIXClient().GET("/get").WithHost("example.com"). WithQuery("hrp_name", "http-route-policy-0").Expect().Status(http.StatusOK) By("update the HTTPRoutePolicy's targetRef") - err = s.CreateResourceFromString(httpRoutePolicySpec2) + err = s.CreateResourceFromStringWithNamespace(httpRoutePolicySpec2, s.Namespace()) Expect(err).NotTo(HaveOccurred(), "updating HTTPRoutePolicy") By("request the route without vars should be OK") Eventually(func() int { return s.NewAPISIXClient().GET("/get").WithHost("example.com").Expect().Raw().StatusCode }). - WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) + WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) By("revert the HTTPRoutePolicy") - err = s.CreateResourceFromString(httpRoutePolicySpec0) + err = s.CreateResourceFromStringWithNamespace(httpRoutePolicySpec0, s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating HTTPRoutePolicy") By("request the route without vars should be Not Found") Eventually(func() int { return s.NewAPISIXClient().GET("/get").WithHost("example.com").Expect().Raw().StatusCode }). - WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusNotFound)) + WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusNotFound)) By("request the route with the correct vars should be OK") s.NewAPISIXClient().GET("/get").WithHost("example.com"). WithHeader("X-HRP-Name", "http-route-policy-0").Expect().Status(http.StatusOK) By("apply conflict HTTPRoutePolicy") - err = s.CreateResourceFromString(httpRoutePolicySpec3) + err = s.CreateResourceFromStringWithNamespace(httpRoutePolicySpec3, s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating HTTPRoutePolicy") Eventually(func() string { spec, err := s.GetResourceYaml("HTTPRoutePolicy", "http-route-policy-1") Expect(err).NotTo(HaveOccurred(), "get HTTPRoutePolicy") return spec - }).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(ContainSubstring("reason: Conflicted")) + }).WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(ContainSubstring("reason: Conflicted")) By("delete the HTTPRoutePolicy") for _, name := range []string{"http-route-policy-0", "http-route-policy-1"} { @@ -727,23 +736,20 @@ spec: Eventually(func() int { return s.NewAPISIXClient().GET("/get").WithHost("example.com").Expect().Raw().StatusCode }). - WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) + WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) }) It("HTTPRoutePolicy status changes on Ingress deleting", func() { By("create Ingress") - err := s.CreateResourceFromString(ingressSpec) + err := s.CreateResourceFromStringWithNamespace(fmt.Sprintf(ingressSpec, s.Namespace()), s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating Ingress") By("create HTTPRoutePolicy") - s.ApplyHTTPRoutePolicy( - types.NamespacedName{Name: "apisix"}, - types.NamespacedName{Namespace: s.Namespace(), Name: "http-route-policy-0"}, - httpRoutePolicySpec0, - ) + err = s.CreateResourceFromStringWithNamespace(httpRoutePolicySpec0, s.Namespace()) + Expect(err).NotTo(HaveOccurred(), "creating HTTPRoutePolicy") By("delete ingress") - err = s.DeleteResource("Ingress", "default") + err = s.DeleteResourceFromStringWithNamespace(fmt.Sprintf(ingressSpec, s.Namespace()), s.Namespace()) Expect(err).NotTo(HaveOccurred(), "delete Ingress") err = framework.PollUntilHTTPRoutePolicyHaveStatus(s.K8sClient, 8*time.Second, @@ -763,14 +769,14 @@ spec: apiVersion: networking.k8s.io/v1 kind: IngressClass metadata: - name: apisix-ingress-class + name: %s spec: - controller: "apisix.apache.org/apisix-ingress-controller" + controller: "%s" parameters: apiGroup: "apisix.apache.org" kind: "GatewayProxy" name: "apisix-proxy-config" - namespace: "default" + namespace: "%s" scope: "Namespace" ` var ingress = ` @@ -779,7 +785,7 @@ kind: Ingress metadata: name: apisix-ingress spec: - ingressClassName: apisix-ingress-class + ingressClassName: %s rules: - host: ingress.example.com http: @@ -797,7 +803,7 @@ apiVersion: apisix.apache.org/v1alpha1 kind: GatewayProxy metadata: name: apisix-proxy-config - namespace: default + namespace: %s spec: provider: type: ControlPlane @@ -812,20 +818,20 @@ spec: BeforeEach(func() { By("create GatewayProxy") - gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Deployer.GetAdminEndpoint(), s.AdminKey()) - err := s.CreateResourceFromStringWithNamespace(gatewayProxy, "default") + gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Namespace(), s.Deployer.GetAdminEndpoint(), s.AdminKey()) + err := s.CreateResourceFromStringWithNamespace(gatewayProxy, s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy") time.Sleep(5 * time.Second) By("create IngressClass") - err = s.CreateResourceFromStringWithNamespace(ingressClass, "") + err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(ingressClass, s.Namespace(), s.GetControllerName(), s.Namespace()), s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating IngressClass") time.Sleep(5 * time.Second) }) It("Should sync Ingress when GatewayProxy is updated", func() { By("create Ingress") - err := s.CreateResourceFromString(ingress) + err := s.CreateResourceFromStringWithNamespace(fmt.Sprintf(ingress, s.Namespace()), s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating Ingress") time.Sleep(5 * time.Second) @@ -854,17 +860,15 @@ spec: Expect(exists).To(BeTrue(), "additional gateway group should exist") By("update GatewayProxy with new admin key") - updatedProxy := fmt.Sprintf(updatedGatewayProxy, s.Deployer.GetAdminEndpoint(resources.DataplaneService), resources.AdminAPIKey) - err = s.CreateResourceFromStringWithNamespace(updatedProxy, "default") + updatedProxy := fmt.Sprintf(updatedGatewayProxy, s.Namespace(), s.Deployer.GetAdminEndpoint(resources.DataplaneService), resources.AdminAPIKey) + err = s.CreateResourceFromStringWithNamespace(updatedProxy, s.Namespace()) Expect(err).NotTo(HaveOccurred(), "updating GatewayProxy") - time.Sleep(5 * time.Second) - + request := func(path string) int { + return client.GET(path).WithHost("ingress.example.com").Expect().Raw().StatusCode + } By("verify Ingress works for additional gateway group") - client. - GET("/get"). - WithHost("ingress.example.com"). - Expect(). - Status(200) + Eventually(request).WithArguments("/get").WithTimeout(20 * time.Second). + ProbeEvery(time.Second).Should(Equal(http.StatusOK)) }) }) @@ -906,9 +910,9 @@ spec: apiVersion: networking.k8s.io/v1 kind: IngressClass metadata: - name: apisix-ingress-class + name: %s spec: - controller: "apisix.apache.org/apisix-ingress-controller" + controller: "%s" parameters: apiGroup: "apisix.apache.org" kind: "GatewayProxy" @@ -922,7 +926,7 @@ kind: Ingress metadata: name: apisix-ingress spec: - ingressClassName: apisix-ingress-class + ingressClassName: %s rules: - host: ingress.example.com http: @@ -950,11 +954,11 @@ spec: Expect(err).NotTo(HaveOccurred(), "creating gateway proxy") By("create IngressClass") - err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(ingressClassSpec, s.Namespace()), s.Namespace()) + err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(ingressClassSpec, s.Namespace(), s.GetControllerName(), s.Namespace()), s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating IngressClass") By("creat Ingress") - err = s.CreateResourceFromStringWithNamespace(ingressSpec, s.Namespace()) + err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(ingressSpec, s.Namespace()), s.Namespace()) Expect(err).NotTo(HaveOccurred(), "creating Ingress") By("verify Ingress works") @@ -963,7 +967,7 @@ spec: GET("/get"). WithHost("ingress.example.com"). Expect().Raw().StatusCode - }).WithTimeout(8 * time.Second).ProbeEvery(time.Second). + }).WithTimeout(20 * time.Second).ProbeEvery(time.Second). Should(Equal(http.StatusOK)) s.NewAPISIXClient(). GET("/get"). @@ -997,14 +1001,14 @@ spec: GET("/get"). WithHost("ingress.example.com"). Expect().Raw().StatusCode - }).WithTimeout(8 * time.Second).ProbeEvery(time.Second). + }).WithTimeout(20 * time.Second).ProbeEvery(time.Second). Should(Equal(http.StatusOK)) Eventually(func() string { return client. GET("/get"). WithHost("ingress.example.com"). Expect().Raw().Header.Get("X-Proxy-Test") - }).WithTimeout(8 * time.Second).ProbeEvery(time.Second). + }).WithTimeout(20 * time.Second).ProbeEvery(time.Second). Should(Equal("enabled")) }) }) diff --git a/test/e2e/scaffold/adc.go b/test/e2e/scaffold/adc.go index cb926d079..27b0692c8 100644 --- a/test/e2e/scaffold/adc.go +++ b/test/e2e/scaffold/adc.go @@ -178,14 +178,16 @@ func (a *adcDataplaneResource) dumpResources(ctx context.Context) (*translator.T routes = append(routes, service.Routes...) } - return &translator.TranslateResult{ + result := &translator.TranslateResult{ Routes: routes, Services: resources.Services, SSL: resources.SSLs, GlobalRules: resources.GlobalRules, PluginMetadata: resources.PluginMetadata, Consumers: resources.Consumers, - }, nil + } + log.Debugw("dumped resources from adc", zap.Any("result", result)) + return result, nil } // adcRouteResource implements RouteResource diff --git a/test/e2e/scaffold/api7_deployer.go b/test/e2e/scaffold/api7_deployer.go index a87e5baed..b62ee04f9 100644 --- a/test/e2e/scaffold/api7_deployer.go +++ b/test/e2e/scaffold/api7_deployer.go @@ -46,22 +46,23 @@ func NewAPI7Deployer(s *Scaffold) Deployer { } func (s *API7Deployer) BeforeEach() { + s.runtimeOpts = s.opts var err error s.UploadLicense() - s.namespace = fmt.Sprintf("ingress-apisix-e2e-tests-%s-%d", s.opts.Name, time.Now().Nanosecond()) + s.namespace = fmt.Sprintf("ingress-apisix-e2e-tests-%s-%d", s.runtimeOpts.Name, time.Now().Nanosecond()) s.kubectlOptions = &k8s.KubectlOptions{ - ConfigPath: s.opts.Kubeconfig, + ConfigPath: s.runtimeOpts.Kubeconfig, Namespace: s.namespace, } - if s.opts.ControllerName == "" { - s.opts.ControllerName = fmt.Sprintf("%s/%s", DefaultControllerName, s.namespace) + if s.runtimeOpts.ControllerName == "" { + s.runtimeOpts.ControllerName = fmt.Sprintf("%s/%s", DefaultControllerName, s.namespace) } s.finalizers = nil if s.label == nil { s.label = make(map[string]string) } - if s.opts.NamespaceSelectorLabel != nil { - for k, v := range s.opts.NamespaceSelectorLabel { + if s.runtimeOpts.NamespaceSelectorLabel != nil { + for k, v := range s.runtimeOpts.NamespaceSelectorLabel { if len(v) > 0 { s.label[k] = v[0] } @@ -74,7 +75,7 @@ func (s *API7Deployer) BeforeEach() { s.additionalGateways = make(map[string]*GatewayResources) var nsLabel map[string]string - if !s.opts.DisableNamespaceLabel { + if !s.runtimeOpts.DisableNamespaceLabel { nsLabel = s.label } k8s.CreateNamespaceWithMetadata(s.t, s.kubectlOptions, metav1.ObjectMeta{Name: s.namespace, Labels: nsLabel}) @@ -85,9 +86,9 @@ func (s *API7Deployer) BeforeEach() { s.gatewayGroupID = s.CreateNewGatewayGroupWithIngress() s.Logf("gateway group id: %s", s.gatewayGroupID) - s.opts.APISIXAdminAPIKey = s.GetAdminKey(s.gatewayGroupID) + s.runtimeOpts.APISIXAdminAPIKey = s.GetAdminKey(s.gatewayGroupID) - s.Logf("apisix admin api key: %s", s.opts.APISIXAdminAPIKey) + s.Logf("apisix admin api key: %s", s.runtimeOpts.APISIXAdminAPIKey) e := utils.ParallelExecutor{} @@ -209,7 +210,7 @@ func (s *API7Deployer) newAPISIXTunnels(serviceName string) error { func (s *API7Deployer) DeployIngress() { s.Framework.DeployIngress(framework.IngressDeployOpts{ ProviderType: "api7ee", - ControllerName: s.opts.ControllerName, + ControllerName: s.runtimeOpts.ControllerName, Namespace: s.namespace, Replicas: ptr.To(1), }) @@ -218,7 +219,7 @@ func (s *API7Deployer) DeployIngress() { func (s *API7Deployer) ScaleIngress(replicas int) { s.Framework.DeployIngress(framework.IngressDeployOpts{ ProviderType: "api7ee", - ControllerName: s.opts.ControllerName, + ControllerName: s.runtimeOpts.ControllerName, Namespace: s.namespace, Replicas: ptr.To(replicas), }) @@ -232,14 +233,14 @@ func (s *API7Deployer) CreateAdditionalGateway(namePrefix string) (string, *core // Create namespace with the same labels var nsLabel map[string]string - if !s.opts.DisableNamespaceLabel { + if !s.runtimeOpts.DisableNamespaceLabel { nsLabel = s.label } k8s.CreateNamespaceWithMetadata(s.t, s.kubectlOptions, metav1.ObjectMeta{Name: additionalNS, Labels: nsLabel}) // Create new kubectl options for the new namespace kubectlOpts := &k8s.KubectlOptions{ - ConfigPath: s.opts.Kubeconfig, + ConfigPath: s.runtimeOpts.Kubeconfig, Namespace: additionalNS, } @@ -304,7 +305,7 @@ func (s *API7Deployer) CleanupAdditionalGateway(gatewayGroupID string) error { // Delete the namespace err := k8s.DeleteNamespaceE(s.t, &k8s.KubectlOptions{ - ConfigPath: s.opts.Kubeconfig, + ConfigPath: s.runtimeOpts.Kubeconfig, Namespace: resources.Namespace, }, resources.Namespace) diff --git a/test/e2e/scaffold/apisix_deployer.go b/test/e2e/scaffold/apisix_deployer.go index bfdc78e1f..704cf1fb6 100644 --- a/test/e2e/scaffold/apisix_deployer.go +++ b/test/e2e/scaffold/apisix_deployer.go @@ -59,42 +59,28 @@ func NewAPISIXDeployer(s *Scaffold) Deployer { } func (s *APISIXDeployer) BeforeEach() { - s.namespace = fmt.Sprintf("ingress-apisix-e2e-tests-%s-%d", s.opts.Name, time.Now().Nanosecond()) + s.runtimeOpts = s.opts + s.namespace = fmt.Sprintf("ingress-apisix-e2e-tests-%s-%d", s.runtimeOpts.Name, time.Now().Nanosecond()) s.kubectlOptions = &k8s.KubectlOptions{ - ConfigPath: s.opts.Kubeconfig, + ConfigPath: s.runtimeOpts.Kubeconfig, Namespace: s.namespace, } - if s.opts.ControllerName == "" { - s.opts.ControllerName = fmt.Sprintf("%s/%s", DefaultControllerName, s.namespace) + if s.runtimeOpts.ControllerName == "" { + s.runtimeOpts.ControllerName = fmt.Sprintf("%s/%s", DefaultControllerName, s.namespace) } + s.finalizers = nil - if s.label == nil { - s.label = make(map[string]string) - } - if s.opts.NamespaceSelectorLabel != nil { - for k, v := range s.opts.NamespaceSelectorLabel { - if len(v) > 0 { - s.label[k] = v[0] - } - } - } else { - s.label["apisix.ingress.watch"] = s.namespace - } // Initialize additionalGateways map s.additionalGateways = make(map[string]*GatewayResources) - var nsLabel map[string]string - if !s.opts.DisableNamespaceLabel { - nsLabel = s.label - } - k8s.CreateNamespaceWithMetadata(s.t, s.kubectlOptions, metav1.ObjectMeta{Name: s.namespace, Labels: nsLabel}) + k8s.CreateNamespace(s.t, s.kubectlOptions, s.namespace) - if s.opts.APISIXAdminAPIKey == "" { - s.opts.APISIXAdminAPIKey = getEnvOrDefault("APISIX_ADMIN_KEY", "edd1c9f034335f136f87ad84b625c8f1") + if s.runtimeOpts.APISIXAdminAPIKey == "" { + s.runtimeOpts.APISIXAdminAPIKey = getEnvOrDefault("APISIX_ADMIN_KEY", "edd1c9f034335f136f87ad84b625c8f1") } - s.Logf("apisix admin api key: %s", s.opts.APISIXAdminAPIKey) + s.Logf("apisix admin api key: %s", s.runtimeOpts.APISIXAdminAPIKey) e := utils.ParallelExecutor{} @@ -149,7 +135,7 @@ func (s *APISIXDeployer) AfterEach() { func (s *APISIXDeployer) DeployDataplane(deployOpts DeployDataplaneOptions) { opts := APISIXDeployOptions{ Namespace: s.namespace, - AdminKey: s.opts.APISIXAdminAPIKey, + AdminKey: s.runtimeOpts.APISIXAdminAPIKey, ServiceHTTPPort: 9080, ServiceHTTPSPort: 9443, Replicas: ptr.To(1), @@ -167,6 +153,9 @@ func (s *APISIXDeployer) DeployDataplane(deployOpts DeployDataplaneOptions) { if deployOpts.ServiceHTTPSPort != 0 { opts.ServiceHTTPSPort = deployOpts.ServiceHTTPSPort } + if deployOpts.AdminKey != "" { + opts.AdminKey = deployOpts.AdminKey + } if deployOpts.Replicas != nil { opts.Replicas = deployOpts.Replicas } @@ -182,6 +171,9 @@ func (s *APISIXDeployer) DeployDataplane(deployOpts DeployDataplaneOptions) { svc := s.deployDataplane(&opts) s.dataplaneService = svc + if opts.Replicas != nil && *opts.Replicas == 0 { + deployOpts.SkipCreateTunnels = true + } if !deployOpts.SkipCreateTunnels { err := s.newAPISIXTunnels(opts.ServiceName) Expect(err).ToNot(HaveOccurred(), "creating apisix tunnels") @@ -230,11 +222,12 @@ func (s *APISIXDeployer) deployDataplane(opts *APISIXDeployOptions) *corev1.Serv Expect(err).ToNot(HaveOccurred(), "executing template") k8s.KubectlApplyFromString(s.GinkgoT, kubectlOpts, buf.String()) - - err = framework.WaitPodsAvailable(s.GinkgoT, kubectlOpts, metav1.ListOptions{ - LabelSelector: "app.kubernetes.io/name=apisix", - }) - Expect(err).ToNot(HaveOccurred(), "waiting for gateway pod ready") + if opts.Replicas == nil || *opts.Replicas > 0 { + err = framework.WaitPodsAvailable(s.GinkgoT, kubectlOpts, metav1.ListOptions{ + LabelSelector: "app.kubernetes.io/name=apisix", + }) + Expect(err).ToNot(HaveOccurred(), "waiting for gateway pod ready") + } Eventually(func() bool { svc, err := k8s.GetServiceE(s.GinkgoT, kubectlOpts, opts.ServiceName) @@ -261,11 +254,11 @@ func (s *APISIXDeployer) ScaleDataplane(replicas int) { func (s *APISIXDeployer) DeployIngress() { syncPeriod := 1 * time.Hour - if s.opts.SyncPeriod != 0 { - syncPeriod = s.opts.SyncPeriod + if s.runtimeOpts.SyncPeriod != 0 { + syncPeriod = s.runtimeOpts.SyncPeriod } s.Framework.DeployIngress(framework.IngressDeployOpts{ - ControllerName: s.opts.ControllerName, + ControllerName: s.runtimeOpts.ControllerName, ProviderType: framework.ProviderType, ProviderSyncPeriod: syncPeriod, Namespace: s.namespace, @@ -275,11 +268,11 @@ func (s *APISIXDeployer) DeployIngress() { func (s *APISIXDeployer) ScaleIngress(replicas int) { syncPeriod := 1 * time.Hour - if s.opts.SyncPeriod != 0 { - syncPeriod = s.opts.SyncPeriod + if s.runtimeOpts.SyncPeriod != 0 { + syncPeriod = s.runtimeOpts.SyncPeriod } s.Framework.DeployIngress(framework.IngressDeployOpts{ - ControllerName: s.opts.ControllerName, + ControllerName: s.runtimeOpts.ControllerName, ProviderType: framework.ProviderType, ProviderSyncPeriod: syncPeriod, Namespace: s.namespace, @@ -297,14 +290,12 @@ func getEnvOrDefault(key, defaultValue string) string { func (s *APISIXDeployer) createAdminTunnel(svc *corev1.Service) (*k8s.Tunnel, error) { var ( - adminNodePort int - adminPort int + adminPort int ) for _, port := range svc.Spec.Ports { switch port.Name { case "admin": - adminNodePort = int(port.NodePort) adminPort = int(port.Port) } } @@ -312,7 +303,7 @@ func (s *APISIXDeployer) createAdminTunnel(svc *corev1.Service) (*k8s.Tunnel, er kubectlOpts := k8s.NewKubectlOptions("", "", svc.Namespace) adminTunnel := k8s.NewTunnel(kubectlOpts, k8s.ResourceTypeService, svc.Name, - adminNodePort, adminPort) + 0, adminPort) if err := adminTunnel.ForwardPortE(s.t); err != nil { return nil, err @@ -333,23 +324,18 @@ func (s *APISIXDeployer) CreateAdditionalGateway(namePrefix string) (string, *co // Create a new namespace for this additional gateway additionalNS := fmt.Sprintf("%s-%d", namePrefix, time.Now().Unix()) - // Create namespace with the same labels - var nsLabel map[string]string - if !s.opts.DisableNamespaceLabel { - nsLabel = s.label - } - k8s.CreateNamespaceWithMetadata(s.t, s.kubectlOptions, metav1.ObjectMeta{Name: additionalNS, Labels: nsLabel}) + k8s.CreateNamespace(s.t, s.kubectlOptions, additionalNS) // Create new kubectl options for the new namespace kubectlOpts := &k8s.KubectlOptions{ - ConfigPath: s.opts.Kubeconfig, + ConfigPath: s.runtimeOpts.Kubeconfig, Namespace: additionalNS, } s.Logf("additional gateway in namespace %s", additionalNS) // Use the same admin key as the main gateway - adminKey := s.opts.APISIXAdminAPIKey + adminKey := s.runtimeOpts.APISIXAdminAPIKey s.Logf("additional gateway admin api key: %s", adminKey) // Store gateway resources info @@ -403,7 +389,7 @@ func (s *APISIXDeployer) CleanupAdditionalGateway(identifier string) error { // Delete the namespace err := k8s.DeleteNamespaceE(s.t, &k8s.KubectlOptions{ - ConfigPath: s.opts.Kubeconfig, + ConfigPath: s.runtimeOpts.Kubeconfig, Namespace: resources.Namespace, }, resources.Namespace) diff --git a/test/e2e/scaffold/assertion.go b/test/e2e/scaffold/assertion.go index c8946f2fd..ef2c35ebd 100644 --- a/test/e2e/scaffold/assertion.go +++ b/test/e2e/scaffold/assertion.go @@ -29,8 +29,8 @@ import ( ) const ( - DefaultTimeout = 12 * time.Second - DefaultInterval = 1 * time.Second + DefaultTimeout = 30 * time.Second + DefaultInterval = 2 * time.Second ) type ResponseCheckFunc func(*HTTPResponse) error diff --git a/test/e2e/scaffold/deployer.go b/test/e2e/scaffold/deployer.go index dd78fd83b..06a629311 100644 --- a/test/e2e/scaffold/deployer.go +++ b/test/e2e/scaffold/deployer.go @@ -45,4 +45,5 @@ type DeployDataplaneOptions struct { ServiceHTTPPort int ServiceHTTPSPort int Replicas *int + AdminKey string } diff --git a/test/e2e/scaffold/k8s.go b/test/e2e/scaffold/k8s.go index 009dda032..85ea6dc3c 100644 --- a/test/e2e/scaffold/k8s.go +++ b/test/e2e/scaffold/k8s.go @@ -208,7 +208,7 @@ func (s *Scaffold) ApplyDefaultGatewayResource( time.Sleep(5 * time.Second) By("create GatewayClass") - gatewayClassName := fmt.Sprintf("apisix-%d", time.Now().Unix()) + gatewayClassName := s.Namespace() gatewayString := fmt.Sprintf(defaultGatewayClass, gatewayClassName, s.GetControllerName()) err = s.CreateResourceFromStringWithNamespace(gatewayString, "") Expect(err).NotTo(HaveOccurred(), "creating GatewayClass") @@ -252,7 +252,7 @@ func (s *Scaffold) ApplyHTTPRoute(hrNN types.NamespacedName, spec string, until }, ) for i, f := range until { - err := wait.PollUntilContextTimeout(context.Background(), time.Second, 10*time.Second, true, f) + err := wait.PollUntilContextTimeout(context.Background(), time.Second, 20*time.Second, true, f) require.NoError(s.GinkgoT, err, "wait for ConditionWithContextFunc[%d] OK", i) } } @@ -314,3 +314,57 @@ spec: } return fmt.Sprintf(gatewayProxyYaml, framework.ProviderType, s.AdminKey()) } + +const ingressClassYaml = ` +apiVersion: networking.k8s.io/%s +kind: IngressClass +metadata: + name: %s + annotations: + apisix.apache.org/parameters-namespace: %s +spec: + controller: %s + parameters: + apiGroup: "apisix.apache.org" + kind: "GatewayProxy" + name: "apisix-proxy-config" +` + +func (s *Scaffold) GetIngressClassYaml() string { + return fmt.Sprintf(ingressClassYaml, framework.IngressVersion, s.Namespace(), s.Namespace(), s.GetControllerName()) +} + +const gatewayClassYaml = ` +apiVersion: gateway.networking.k8s.io/v1 +kind: GatewayClass +metadata: + name: %s +spec: + controllerName: %s +` + +func (s *Scaffold) GetGatewayClassYaml() string { + return fmt.Sprintf(gatewayClassYaml, s.Namespace(), s.GetControllerName()) +} + +const gatewayYaml = ` +apiVersion: gateway.networking.k8s.io/v1 +kind: Gateway +metadata: + name: %s +spec: + gatewayClassName: %s + listeners: + - name: http1 + protocol: HTTP + port: 80 + infrastructure: + parametersRef: + group: apisix.apache.org + kind: GatewayProxy + name: apisix-proxy-config +` + +func (s *Scaffold) GetGatewayYaml() string { + return fmt.Sprintf(gatewayYaml, s.Namespace(), s.Namespace()) +} diff --git a/test/e2e/scaffold/scaffold.go b/test/e2e/scaffold/scaffold.go index 0e8e365af..eababc306 100644 --- a/test/e2e/scaffold/scaffold.go +++ b/test/e2e/scaffold/scaffold.go @@ -57,7 +57,10 @@ type Options struct { type Scaffold struct { *framework.Framework - opts *Options + // opts holds the original, user-provided options. + // It is treated as read-only and must not be modified after initialization. + opts Options + kubectlOptions *k8s.KubectlOptions namespace string t testing.TestingT @@ -73,7 +76,8 @@ type Scaffold struct { additionalGateways map[string]*GatewayResources - Deployer Deployer + runtimeOpts Options + Deployer Deployer } // GatewayResources contains resources associated with a specific Gateway group @@ -90,11 +94,11 @@ func (g *GatewayResources) GetAdminEndpoint() string { } func (s *Scaffold) AdminKey() string { - return s.opts.APISIXAdminAPIKey + return s.runtimeOpts.APISIXAdminAPIKey } // NewScaffold creates an e2e test scaffold. -func NewScaffold(o *Options) *Scaffold { +func NewScaffold(o Options) *Scaffold { if o.Name == "" { o.Name = "default" } @@ -112,7 +116,7 @@ func NewScaffold(o *Options) *Scaffold { s.Deployer = NewDeployer(s) - if !s.opts.SkipHooks { + if !o.SkipHooks { BeforeEach(s.Deployer.BeforeEach) AfterEach(s.Deployer.AfterEach) } @@ -123,7 +127,7 @@ func NewScaffold(o *Options) *Scaffold { // NewDefaultScaffold creates a scaffold with some default options. // apisix-version default v2 func NewDefaultScaffold() *Scaffold { - return NewScaffold(&Options{}) + return NewScaffold(Options{}) } // KillPod kill the pod which name is podName. @@ -284,6 +288,7 @@ func (s *Scaffold) NamespaceSelectorLabelStrings() []string { func (s *Scaffold) NamespaceSelectorLabel() map[string][]string { return s.opts.NamespaceSelectorLabel } + func (s *Scaffold) labelSelector(label string) metav1.ListOptions { return metav1.ListOptions{ LabelSelector: label, @@ -291,7 +296,7 @@ func (s *Scaffold) labelSelector(label string) metav1.ListOptions { } func (s *Scaffold) GetControllerName() string { - return s.opts.ControllerName + return s.runtimeOpts.ControllerName } // createDataplaneTunnels creates HTTP and HTTPS tunnels for a dataplane service.