-
Notifications
You must be signed in to change notification settings - Fork 2
test: support apisix standalone mode #153
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
Closed
Closed
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d51f99d
test: add apisix standalone mode
ronething cac93b4
fix: r
ronething 2b7a9c3
fix: r
ronething 354f8c3
fix: r
ronething 49dbb01
fix: standalone yaml
ronething 0b74c0d
fix: r
ronething 2363804
fix: r
ronething 059569e
chore: none
ronething 8b1422c
chroe: n
ronething File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package apisix | ||
|
|
||
| import ( | ||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
|
|
||
| "github.com/apache/apisix-ingress-controller/test/e2e/scaffold" | ||
| ) | ||
|
|
||
| var _ = Describe("APISIX Standalone Basic Tests", func() { | ||
| s := scaffold.NewScaffold(&scaffold.Options{ | ||
| ControllerName: "apisix.apache.org/apisix-ingress-controller", | ||
| }) | ||
|
|
||
| Describe("APISIX HTTP Proxy", func() { | ||
| It("should handle basic HTTP requests", func() { | ||
| httpClient := s.NewAPISIXClient() | ||
| Expect(httpClient).NotTo(BeNil()) | ||
|
|
||
| // Test basic connectivity | ||
| resp := httpClient.GET("/anything"). | ||
| Expect(). | ||
| Status(200) | ||
|
|
||
| resp.JSON().Object().ContainsKey("url") | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package apisix | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| . "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" | ||
| ) | ||
|
|
||
| // TestAPISIXE2E runs e2e tests using the APISIX standalone mode | ||
| func TestAPISIXE2E(t *testing.T) { | ||
| RegisterFailHandler(Fail) | ||
| f := framework.NewAPISIXFramework() | ||
|
|
||
| // init newScaffold function | ||
| scaffold.NewScaffold = func(opts *scaffold.Options) scaffold.TestScaffold { | ||
| return scaffold.NewAPISIXScaffold(opts) | ||
| } | ||
|
|
||
| BeforeSuite(f.BeforeSuite) | ||
| AfterSuite(f.AfterSuite) | ||
|
|
||
| _, _ = fmt.Fprintf(GinkgoWriter, "Starting APISIX standalone e2e suite\n") | ||
| RunSpecs(t, "apisix standalone e2e suite") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package framework | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| _ "embed" | ||
| "fmt" | ||
| "os" | ||
| "text/template" | ||
| "time" | ||
|
|
||
| "github.com/Masterminds/sprig/v3" | ||
| "github.com/gruntwork-io/terratest/modules/k8s" | ||
| "github.com/gruntwork-io/terratest/modules/testing" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/util/wait" | ||
| ) | ||
|
|
||
| //go:embed manifests/apisix-standalone.yaml | ||
| var apisixStandaloneTemplate string | ||
|
|
||
| // APISIXDeployOptions contains options for APISIX standalone deployment | ||
| type APISIXDeployOptions struct { | ||
| Namespace string | ||
| Image string | ||
| AdminKey string | ||
| ServiceType string | ||
| HTTPNodePort int32 | ||
| HTTPSNodePort int32 | ||
| AdminNodePort int32 | ||
| } | ||
|
|
||
| // APISIXDeployer implements DataPlaneDeployer for APISIX standalone | ||
| type APISIXDeployer struct { | ||
| kubectlOpts *k8s.KubectlOptions | ||
| opts *APISIXDeployOptions | ||
| service *corev1.Service | ||
| t testing.TestingT | ||
| } | ||
|
|
||
| // NewAPISIXDeployer creates a new APISIX deployer | ||
| func NewAPISIXDeployer(t testing.TestingT, kubectlOpts *k8s.KubectlOptions, opts *APISIXDeployOptions) *APISIXDeployer { | ||
| if opts.Image == "" { | ||
| opts.Image = getEnvOrDefault("APISIX_IMAGE", "apache/apisix:dev") | ||
| } | ||
| if opts.AdminKey == "" { | ||
| opts.AdminKey = getEnvOrDefault("APISIX_ADMIN_KEY", "edd1c9f034335f136f87ad84b625c8f1") | ||
| } | ||
| if opts.Namespace == "" { | ||
| opts.Namespace = getEnvOrDefault("APISIX_NAMESPACE", "apisix-standalone") | ||
| } | ||
| if opts.ServiceType == "" { | ||
| opts.ServiceType = "ClusterIP" | ||
| } | ||
|
|
||
| return &APISIXDeployer{ | ||
| kubectlOpts: kubectlOpts, | ||
| opts: opts, | ||
| t: t, | ||
| } | ||
| } | ||
|
|
||
| func (d *APISIXDeployer) GetService() *corev1.Service { | ||
| return d.service | ||
| } | ||
|
|
||
| // Deploy deploys APISIX standalone | ||
| func (d *APISIXDeployer) Deploy(ctx context.Context) error { | ||
| // Parse and execute template | ||
| tmpl, err := template.New("apisix-standalone").Funcs(sprig.TxtFuncMap()).Parse(apisixStandaloneTemplate) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to parse template: %w", err) | ||
| } | ||
|
|
||
| var buf bytes.Buffer | ||
| if err := tmpl.Execute(&buf, d.opts); err != nil { | ||
| return fmt.Errorf("failed to execute template: %w", err) | ||
| } | ||
|
|
||
| // Apply the manifest | ||
| if err := k8s.KubectlApplyFromStringE(d.t, d.kubectlOpts, buf.String()); err != nil { | ||
| return fmt.Errorf("failed to apply APISIX manifest: %w", err) | ||
| } | ||
|
|
||
| // Wait for deployment to be ready | ||
| if err := d.waitForDeployment(ctx); err != nil { | ||
| return fmt.Errorf("failed to wait for deployment: %w", err) | ||
| } | ||
|
|
||
| // Get service | ||
| service, err := k8s.GetServiceE(d.t, d.kubectlOpts, "apisix") | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get APISIX service: %w", err) | ||
| } | ||
| d.service = service | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // Cleanup removes APISIX standalone deployment | ||
| func (d *APISIXDeployer) Cleanup(ctx context.Context) error { | ||
| // Delete namespace which will clean up all resources | ||
| return k8s.DeleteNamespaceE(d.t, d.kubectlOpts, d.opts.Namespace) | ||
| } | ||
|
|
||
| // waitForDeployment waits for the APISIX deployment to be ready | ||
| func (d *APISIXDeployer) waitForDeployment(ctx context.Context) error { | ||
| return wait.PollImmediate(5*time.Second, 5*time.Minute, func() (bool, error) { | ||
|
Check failure on line 121 in test/e2e/framework/apisix.go
|
||
| pods, err := k8s.ListPodsE(d.t, d.kubectlOpts, metav1.ListOptions{ | ||
| LabelSelector: "app=apisix", | ||
| }) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
|
|
||
| if len(pods) == 0 { | ||
| return false, nil | ||
| } | ||
|
|
||
| for _, pod := range pods { | ||
| if pod.Status.Phase != corev1.PodRunning { | ||
| return false, nil | ||
| } | ||
|
|
||
| // Check if all containers are ready | ||
| for _, condition := range pod.Status.Conditions { | ||
| if condition.Type == corev1.PodReady && condition.Status != corev1.ConditionTrue { | ||
| return false, nil | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return true, nil | ||
| }) | ||
| } | ||
|
|
||
| // getEnvOrDefault returns environment variable value or default | ||
| func getEnvOrDefault(key, defaultValue string) string { | ||
| if value := os.Getenv(key); value != "" { | ||
| return value | ||
| } | ||
| return defaultValue | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need add ci.