-
Notifications
You must be signed in to change notification settings - Fork 2
feat: support custom gatewayproxy namespace for ingressclass #222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,9 +18,16 @@ | |
| package v2 | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net/http" | ||
| "time" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| "k8s.io/apimachinery/pkg/types" | ||
|
|
||
| apiv2 "github.com/apache/apisix-ingress-controller/api/v2" | ||
| "github.com/apache/apisix-ingress-controller/test/e2e/framework" | ||
| "github.com/apache/apisix-ingress-controller/test/e2e/scaffold" | ||
| ) | ||
|
|
||
|
|
@@ -56,11 +63,14 @@ spec: | |
| ` | ||
|
|
||
| var _ = Describe("APISIX Standalone Basic Tests", Label("apisix.apache.org", "v2", "basic"), func() { | ||
| s := scaffold.NewScaffold(&scaffold.Options{ | ||
| ControllerName: "apisix.apache.org/apisix-ingress-controller", | ||
| }) | ||
| var ( | ||
| s = scaffold.NewScaffold(&scaffold.Options{ | ||
| ControllerName: "apisix.apache.org/apisix-ingress-controller", | ||
| }) | ||
| applier = framework.NewApplier(s.GinkgoT, s.K8sClient, s.CreateResourceFromString) | ||
| ) | ||
|
|
||
| Describe("APISIX HTTP Proxy", func() { | ||
| Context("APISIX HTTP Proxy", func() { | ||
| It("should handle basic HTTP requests", func() { | ||
| httpClient := s.NewAPISIXClient() | ||
| Expect(httpClient).NotTo(BeNil()) | ||
|
|
@@ -83,6 +93,97 @@ var _ = Describe("APISIX Standalone Basic Tests", Label("apisix.apache.org", "v2 | |
| Expect(). | ||
| Status(404).Body().Contains("404 Route Not Found") | ||
| }) | ||
| }) | ||
|
|
||
| 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/gatewayproxy-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) | ||
| Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy") | ||
| time.Sleep(5 * time.Second) | ||
|
|
||
| By("create IngressClass") | ||
| ingressClass := fmt.Sprintf(ingressClassYaml, framework.IngressVersion, s.Namespace()) | ||
| err = s.CreateResourceFromString(ingressClass) | ||
| Expect(err).NotTo(HaveOccurred(), "creating IngressClass") | ||
| time.Sleep(5 * time.Second) | ||
|
|
||
| const apisixRouteSpec = ` | ||
| apiVersion: apisix.apache.org/v2 | ||
| kind: ApisixRoute | ||
| metadata: | ||
| name: default | ||
| spec: | ||
| ingressClassName: apisix | ||
| http: | ||
| - name: rule0 | ||
| match: | ||
| hosts: | ||
| - httpbin | ||
| paths: | ||
| - %s | ||
| backends: | ||
| - serviceName: httpbin-service-e2e-test | ||
| servicePort: 80 | ||
| ` | ||
| request := func(path string) int { | ||
| return s.NewAPISIXClient().GET(path).WithHost("httpbin").Expect().Raw().StatusCode | ||
| } | ||
|
|
||
| By("apply ApisixRoute") | ||
| var apisixRoute apiv2.ApisixRoute | ||
| applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apisixRoute, fmt.Sprintf(apisixRouteSpec, "/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")) | ||
| Eventually(request).WithArguments("/get").WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusNotFound)) | ||
| s.RequestAssert(&scaffold.RequestAssert{ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RequestAssert has built-in retry logic.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, i copy it from another file. we can change it in the next PR. |
||
| Method: "GET", | ||
| Path: "/headers", | ||
| Host: "httpbin", | ||
| Check: scaffold.WithExpectedStatus(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)) | ||
| }) | ||
| }) | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.