Skip to content

Commit 354f8c3

Browse files
committed
fix: r
Signed-off-by: ashing <[email protected]>
1 parent 2b7a9c3 commit 354f8c3

File tree

11 files changed

+165
-78
lines changed

11 files changed

+165
-78
lines changed

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ GATEAY_API_VERSION ?= v1.2.0
1515
DASHBOARD_VERSION ?= dev
1616
TEST_TIMEOUT ?= 45m
1717

18+
APISIX_IMAGE ?= apache/apisix:dev
19+
APISIX_ADMIN_KEY ?= edd1c9f034335f136f87ad84b625c8f1
20+
APISIX_NAMESPACE ?= apisix-standalone
21+
1822
# CRD Reference Documentation
1923
CRD_REF_DOCS_VERSION ?= v0.1.0
2024
CRD_REF_DOCS ?= $(LOCALBIN)/crd-ref-docs
@@ -109,7 +113,12 @@ kind-e2e-test: kind-up build-image kind-load-images e2e-test
109113
.PHONY: e2e-test
110114
e2e-test:
111115
@kind get kubeconfig --name $(KIND_NAME) > $$KUBECONFIG
112-
DASHBOARD_VERSION=$(DASHBOARD_VERSION) go test ./test/e2e/ -run TestE2E -test.timeout=$(TEST_TIMEOUT) -v -ginkgo.v -ginkgo.focus="$(TEST_FOCUS)"
116+
DASHBOARD_VERSION=$(DASHBOARD_VERSION) go test ./test/e2e/ -test.timeout=$(TEST_TIMEOUT) -v -ginkgo.v -ginkgo.focus="$(TEST_FOCUS)"
117+
118+
.PHONY: e2e-test-standalone
119+
e2e-test-standalone:
120+
@kind get kubeconfig --name $(KIND_NAME) > $$KUBECONFIG
121+
APISIX_IMAGE=$(APISIX_IMAGE) APISIX_ADMIN_KEY=$(APISIX_ADMIN_KEY) APISIX_NAMESPACE=$(APISIX_NAMESPACE) go test ./test/e2e/apisix/ -test.timeout=$(TEST_TIMEOUT) -v -ginkgo.v -ginkgo.focus="$(TEST_FOCUS)"
113122

114123
.PHONY: download-api7ee3-chart
115124
download-api7ee3-chart:

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ require (
152152
github.com/moul/http2curl v1.0.0 // indirect
153153
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
154154
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
155-
github.com/onsi/ginkgo v1.10.1 // indirect
156155
github.com/opencontainers/go-digest v1.0.0 // indirect
157156
github.com/opencontainers/image-spec v1.1.0 // indirect
158157
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect

scripts/run-apisix-e2e.sh

Lines changed: 0 additions & 33 deletions
This file was deleted.

test/e2e/apisix/basic.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import (
2020
)
2121

2222
var _ = Describe("APISIX Standalone Basic Tests", func() {
23-
var (
24-
s *scaffold.APISIXScaffold
25-
)
23+
s := scaffold.NewScaffold(&scaffold.Options{
24+
ControllerName: "apisix.apache.org/apisix-ingress-controller",
25+
})
2626

2727
Describe("APISIX HTTP Proxy", func() {
2828
It("should handle basic HTTP requests", func() {

test/e2e/apisix_e2e_test.go renamed to test/e2e/apisix/e2e_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// See the License for the specific language governing permissions and
1111
// limitations under the License.
1212

13-
package e2e
13+
package apisix
1414

1515
import (
1616
"fmt"
@@ -19,7 +19,6 @@ import (
1919
. "github.com/onsi/ginkgo/v2"
2020
. "github.com/onsi/gomega"
2121

22-
_ "github.com/apache/apisix-ingress-controller/test/e2e/apisix"
2322
"github.com/apache/apisix-ingress-controller/test/e2e/framework"
2423
"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
2524
)

test/e2e/framework/apisix.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"text/template"
2222
"time"
2323

24+
"github.com/Masterminds/sprig/v3"
2425
"github.com/gruntwork-io/terratest/modules/k8s"
2526
"github.com/gruntwork-io/terratest/modules/testing"
2627
corev1 "k8s.io/api/core/v1"
@@ -72,10 +73,14 @@ func NewAPISIXDeployer(t testing.TestingT, kubectlOpts *k8s.KubectlOptions, opts
7273
}
7374
}
7475

76+
func (d *APISIXDeployer) GetService() *corev1.Service {
77+
return d.service
78+
}
79+
7580
// Deploy deploys APISIX standalone
7681
func (d *APISIXDeployer) Deploy(ctx context.Context) error {
7782
// Parse and execute template
78-
tmpl, err := template.New("apisix-standalone").Parse(apisixStandaloneTemplate)
83+
tmpl, err := template.New("apisix-standalone").Funcs(sprig.TxtFuncMap()).Parse(apisixStandaloneTemplate)
7984
if err != nil {
8085
return fmt.Errorf("failed to parse template: %w", err)
8186
}

test/e2e/framework/apisix_framework.go

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,26 @@
1313
package framework
1414

1515
import (
16+
"bufio"
17+
"bytes"
1618
"context"
19+
"fmt"
1720
"os"
21+
"strings"
22+
"sync"
23+
"time"
1824

1925
"github.com/gruntwork-io/terratest/modules/k8s"
2026
"github.com/gruntwork-io/terratest/modules/logger"
2127
. "github.com/onsi/ginkgo/v2"
28+
"github.com/onsi/gomega"
2229
. "github.com/onsi/gomega"
30+
corev1 "k8s.io/api/core/v1"
31+
k8serrors "k8s.io/apimachinery/pkg/api/errors"
32+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2333
"k8s.io/client-go/kubernetes"
2434
"k8s.io/client-go/rest"
35+
"k8s.io/utils/ptr"
2536
"sigs.k8s.io/controller-runtime/pkg/client"
2637
)
2738

@@ -42,6 +53,7 @@ type APISIXFramework struct {
4253
clientset *kubernetes.Clientset
4354
restConfig *rest.Config
4455
K8sClient client.Client
56+
namespace string
4557
}
4658

4759
// NewAPISIXFramework creates a new APISIX framework
@@ -60,6 +72,8 @@ func NewAPISIXFramework() *APISIXFramework {
6072
namespace = _apisixNamespace
6173
}
6274

75+
f.namespace = namespace
76+
6377
f.kubectlOpts = k8s.NewKubectlOptions("", "", namespace)
6478
restCfg, err := buildRestConfig("")
6579
f.GomegaT.Expect(err).ShouldNot(HaveOccurred(), "building API Server rest config")
@@ -81,9 +95,17 @@ func NewAPISIXFramework() *APISIXFramework {
8195
// BeforeSuite initializes the APISIX test environment
8296
func (f *APISIXFramework) BeforeSuite() {
8397
f.Logf("Starting APISIX standalone test suite")
98+
_ = k8s.DeleteNamespaceE(GinkgoT(), f.kubectlOpts, f.namespace)
99+
100+
Eventually(func() error {
101+
_, err := k8s.GetNamespaceE(GinkgoT(), f.kubectlOpts, f.namespace)
102+
if k8serrors.IsNotFound(err) {
103+
return nil
104+
}
105+
return fmt.Errorf("namespace %s still exists", f.namespace)
106+
}, "1m", "2s").Should(Succeed())
84107

85-
// Create namespace for APISIX standalone tests
86-
k8s.CreateNamespace(GinkgoT(), f.kubectlOpts, f.kubectlOpts.Namespace)
108+
k8s.CreateNamespace(GinkgoT(), f.kubectlOpts, f.namespace)
87109

88110
f.Logf("APISIX standalone test environment initialized")
89111
}
@@ -105,3 +127,80 @@ func GetAPISIXFramework() *APISIXFramework {
105127
func (f *APISIXFramework) Logf(format string, v ...any) {
106128
f.Logger.Logf(f.GinkgoT, format, v...)
107129
}
130+
131+
func (f *APISIXFramework) DeployIngress(opts IngressDeployOpts) {
132+
buf := bytes.NewBuffer(nil)
133+
134+
err := IngressSpecTpl.Execute(buf, opts)
135+
f.GomegaT.Expect(err).ToNot(HaveOccurred(), "rendering ingress spec")
136+
137+
kubectlOpts := k8s.NewKubectlOptions("", "", opts.Namespace)
138+
139+
k8s.KubectlApplyFromString(f.GinkgoT, kubectlOpts, buf.String())
140+
141+
err = WaitPodsAvailable(f.GinkgoT, kubectlOpts, metav1.ListOptions{
142+
LabelSelector: "control-plane=controller-manager",
143+
})
144+
f.GomegaT.Expect(err).ToNot(HaveOccurred(), "waiting for controller-manager pod ready")
145+
f.WaitControllerManagerLog("All cache synced successfully", 0, time.Minute)
146+
}
147+
148+
func (f *APISIXFramework) WaitControllerManagerLog(keyword string, sinceSeconds int64, timeout time.Duration) {
149+
f.WaitPodsLog("control-plane=controller-manager", keyword, sinceSeconds, timeout)
150+
}
151+
152+
func (f *APISIXFramework) WaitDPLog(keyword string, sinceSeconds int64, timeout time.Duration) {
153+
f.WaitPodsLog("app.kubernetes.io/name=apisix", keyword, sinceSeconds, timeout)
154+
}
155+
156+
func (f *APISIXFramework) WaitPodsLog(selector, keyword string, sinceSeconds int64, timeout time.Duration) {
157+
pods := f.ListRunningPods(selector)
158+
wg := sync.WaitGroup{}
159+
for _, p := range pods {
160+
wg.Add(1)
161+
go func(p corev1.Pod) {
162+
defer wg.Done()
163+
opts := corev1.PodLogOptions{Follow: true}
164+
if sinceSeconds > 0 {
165+
opts.SinceSeconds = ptr.To(sinceSeconds)
166+
} else {
167+
opts.TailLines = ptr.To(int64(0))
168+
}
169+
logStream, err := f.clientset.CoreV1().Pods(p.Namespace).GetLogs(p.Name, &opts).Stream(context.Background())
170+
f.GomegaT.Expect(err).Should(gomega.BeNil())
171+
scanner := bufio.NewScanner(logStream)
172+
scanner.Split(bufio.ScanLines)
173+
for scanner.Scan() {
174+
line := scanner.Text()
175+
if strings.Contains(line, keyword) {
176+
return
177+
}
178+
}
179+
}(p)
180+
}
181+
c := make(chan struct{})
182+
go func() {
183+
defer close(c)
184+
wg.Wait()
185+
}()
186+
select {
187+
case <-c:
188+
return
189+
case <-time.After(timeout):
190+
f.GinkgoT.Error("wait log timeout")
191+
}
192+
}
193+
194+
func (f *APISIXFramework) ListRunningPods(selector string) []corev1.Pod {
195+
pods, err := f.clientset.CoreV1().Pods(f.namespace).List(context.TODO(), metav1.ListOptions{
196+
LabelSelector: selector,
197+
})
198+
f.GomegaT.Expect(err).ShouldNot(gomega.HaveOccurred(), "list pod: ", selector)
199+
runningPods := make([]corev1.Pod, 0)
200+
for _, p := range pods.Items {
201+
if p.Status.Phase == corev1.PodRunning && p.DeletionTimestamp == nil {
202+
runningPods = append(runningPods, p)
203+
}
204+
}
205+
return runningPods
206+
}

test/e2e/framework/dashboard.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,6 @@ var (
4343
)
4444

4545
func init() {
46-
API7EELicense = os.Getenv("API7_EE_LICENSE")
47-
if API7EELicense == "" {
48-
panic("env {API7_EE_LICENSE} is required")
49-
}
50-
51-
dashboardVersion = os.Getenv("DASHBOARD_VERSION")
52-
if dashboardVersion == "" {
53-
dashboardVersion = "dev"
54-
}
55-
5646
tmpl, err := template.New("values.yaml").Parse(`
5747
dashboard:
5848
image:

test/e2e/framework/framework.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
_ "embed"
1919
"encoding/base64"
2020
"fmt"
21+
"os"
2122
"time"
2223

2324
"github.com/gruntwork-io/terratest/modules/k8s"
@@ -76,6 +77,16 @@ type Framework struct {
7677

7778
// NewFramework create a global framework with special settings.
7879
func NewFramework() *Framework {
80+
API7EELicense = os.Getenv("API7_EE_LICENSE")
81+
if API7EELicense == "" {
82+
panic("env {API7_EE_LICENSE} is required")
83+
}
84+
85+
dashboardVersion = os.Getenv("DASHBOARD_VERSION")
86+
if dashboardVersion == "" {
87+
dashboardVersion = "dev"
88+
}
89+
7990
f := &Framework{
8091
GinkgoT: GinkgoT(),
8192
GomegaT: NewWithT(GinkgoT(4)),

test/e2e/framework/manifests/apisix-standalone.yaml

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
apiVersion: v1
2-
kind: Namespace
3-
metadata:
4-
name: {{ .Namespace }}
5-
---
6-
apiVersion: v1
72
kind: ConfigMap
83
metadata:
94
name: apisix-conf
@@ -20,7 +15,7 @@ data:
2015
enabled: true
2116
nginx_config:
2217
worker_processes: 2
23-
error_log_level: debug
18+
error_log_level: info
2419
deployment:
2520
role: data_plane
2621
role_data_plane:
@@ -54,13 +49,6 @@ spec:
5449
containers:
5550
- name: apisix
5651
image: {{ .Image }}
57-
resources:
58-
requests:
59-
cpu: 1000m
60-
memory: 500Mi
61-
limits:
62-
cpu: 2000m
63-
memory: 1500Mi
6452
ports:
6553
- name: http
6654
containerPort: 9080
@@ -91,16 +79,19 @@ metadata:
9179
labels:
9280
app: apisix
9381
spec:
94-
type: {{ .ServiceType }}
82+
type: {{ .ServiceType | default "NodePort" }}
9583
ports:
96-
- port: 80
84+
- port: 9080
9785
name: http
86+
protocol: TCP
9887
targetPort: 9080
99-
- port: 443
88+
- port: 9443
10089
name: https
90+
protocol: TCP
10191
targetPort: 9443
10292
- port: 9180
10393
name: admin
94+
protocol: TCP
10495
targetPort: 9180
10596
selector:
10697
app: apisix

0 commit comments

Comments
 (0)