Skip to content

Commit f3624a3

Browse files
committed
fix: r
Signed-off-by: ashing <[email protected]>
1 parent 52eed7f commit f3624a3

File tree

5 files changed

+37
-181
lines changed

5 files changed

+37
-181
lines changed

test/e2e/framework/dashboard.go

Lines changed: 34 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,24 @@ package framework
22

33
import (
44
"bytes"
5-
"context"
5+
_ "embed"
66
"encoding/json"
77
"fmt"
8-
"io"
9-
"net/http"
108
"os"
11-
"os/exec"
129
"text/template"
1310
"time"
1411

1512
v1 "github.com/api7/api7-ingress-controller/api/dashboard/v1"
1613
"github.com/api7/gopkg/pkg/log"
1714
"github.com/google/uuid"
18-
"github.com/onsi/gomega"
15+
. "github.com/onsi/gomega"
1916
"golang.org/x/net/html"
2017
"helm.sh/helm/v3/pkg/action"
2118
"helm.sh/helm/v3/pkg/chart/loader"
2219
"helm.sh/helm/v3/pkg/cli"
2320

2421
"helm.sh/helm/v3/pkg/kube"
25-
"k8s.io/apimachinery/pkg/util/wait"
2622
"k8s.io/apimachinery/pkg/util/yaml"
27-
28-
testutils "github.com/api7/api7-ingress-controller/test/utils"
2923
)
3024

3125
var (
@@ -204,6 +198,10 @@ dp_manager_configuration:
204198
database:
205199
dsn: {{ .DSN }}
206200
prometheus:
201+
server:
202+
persistence:
203+
enabled: false
204+
postgresql:
207205
{{- if ne .DB "postgres" }}
208206
builtin: false
209207
{{- end }}
@@ -273,70 +271,44 @@ func (f *Framework) deploy() {
273271
"memory",
274272
debug,
275273
)
276-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "init helm action config")
274+
f.GomegaT.Expect(err).ShouldNot(HaveOccurred(), "init helm action config")
277275

278276
install := action.NewInstall(actionConfig)
279277
install.Namespace = f.kubectlOpts.Namespace
280278
install.ReleaseName = "api7ee3"
281-
install.Wait = true
282-
install.Version = dashboardVersion
283-
install.Timeout = 600 * time.Second
284279

285280
chartPath, err := install.LocateChart("api7/api7ee3", cli.New())
286-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
281+
f.GomegaT.Expect(err).ShouldNot(HaveOccurred(), "locate helm chart")
287282

288-
chartObj, err := loader.Load(chartPath)
289-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
283+
chart, err := loader.Load(chartPath)
284+
f.GomegaT.Expect(err).ShouldNot(HaveOccurred(), "load helm chart")
290285

291-
dsn := fmt.Sprintf(
292-
"host=%s port=%d user=%s password=%s dbname=%s sslmode=disable",
293-
"api7ee3-postgresql", 5432, "postgres", "postgres", "api7",
294-
)
295-
DB := "postgres"
296-
297-
valuesBuf := &bytes.Buffer{}
298-
err = valuesTemplate.Execute(valuesBuf, struct {
299-
Tag string
300-
DSN string
301-
DB string
302-
}{
303-
Tag: dashboardVersion,
304-
DSN: dsn,
305-
DB: DB,
286+
buf := bytes.NewBuffer(nil)
287+
_ = valuesTemplate.Execute(buf, map[string]any{
288+
"DB": _db,
289+
"DSN": getDSN(),
290+
"Tag": dashboardVersion,
306291
})
307-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
308-
309-
vals := make(map[string]any)
310-
gomega.Expect(yaml.Unmarshal(valuesBuf.Bytes(), &vals)).NotTo(gomega.HaveOccurred())
311292

312-
_, err = install.Run(chartObj, vals)
313-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
314-
315-
err = f.ExecuteWithRetry(func() error {
316-
cmd := exec.Command("kubectl", "get", "service", "api7ee3-dashboard", "-n", f.DeployNamespace())
317-
_, err := testutils.Run(cmd)
318-
return err
319-
}, f.DeployNamespace())
320-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
293+
var v map[string]any
294+
err = yaml.Unmarshal(buf.Bytes(), &v)
295+
f.GomegaT.Expect(err).ShouldNot(HaveOccurred(), "unmarshal values")
296+
_, err = install.Run(chart, v)
297+
f.GomegaT.Expect(err).ShouldNot(HaveOccurred(), "install dashboard")
321298

322299
err = f.ensureService("api7ee3-dashboard", _namespace, 1)
323-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "ensuring dashboard service")
300+
f.GomegaT.Expect(err).ShouldNot(HaveOccurred(), "ensuring dashboard service")
324301

325302
err = f.ensureService("api7-postgresql", _namespace, 1)
326-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "ensuring postgres service")
303+
f.GomegaT.Expect(err).ShouldNot(HaveOccurred(), "ensuring postgres service")
327304

328305
err = f.ensureService("api7-prometheus-server", _namespace, 1)
329-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "ensuring prometheus-server service")
306+
f.GomegaT.Expect(err).ShouldNot(HaveOccurred(), "ensuring prometheus-server service")
330307
}
331308

332309
func (f *Framework) initDashboard() {
333-
// Wait for dashboard to be ready
334-
err := f.ExecuteWithRetry(func() error {
335-
cmd := exec.Command("kubectl", "get", "service", "api7ee3-dashboard", "-n", f.DeployNamespace())
336-
_, err := testutils.Run(cmd)
337-
return err
338-
}, f.DeployNamespace())
339-
f.GomegaT.Expect(err).ShouldNot(gomega.HaveOccurred(), "waiting for dashboard to be ready")
310+
f.deletePods("app.kubernetes.io/name=api7ee3")
311+
time.Sleep(5 * time.Second)
340312
}
341313

342314
// ParseHTML will parse the doc from login page and generate a map contains id and action.
@@ -387,44 +359,23 @@ func (f *Framework) GetTokenFromDashboard(gatewayGroupID string) (string, error)
387359
}
388360

389361
func (f *Framework) GetDataplaneCertificates(gatewayGroupID string) *v1.DataplaneCertificate {
390-
req, err := http.NewRequest(
391-
http.MethodGet,
392-
fmt.Sprintf("http://127.0.0.1:%d/dashboard/api/gateway-groups/%s/dataplane-certificates",
393-
f.ProxyPort(),
394-
gatewayGroupID,
395-
),
396-
nil,
397-
)
398-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
399-
400-
client := http.Client{Timeout: 30 * time.Second}
401-
resp, err := client.Do(req)
402-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
403-
defer func() {
404-
if err := resp.Body.Close(); err != nil {
405-
f.Logf("failed to close response body: %v", err)
406-
}
407-
}()
408-
409-
body, err := io.ReadAll(resp.Body)
410-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
411-
412-
f.Logger.Logf(f.GinkgoT, "dataplane certificates issuer response: %s", string(body))
413-
414362
respExp := f.DashboardHTTPClient().
415363
POST("/api/gateway_groups/"+gatewayGroupID+"/dp_client_certificates").
416364
WithBasicAuth("admin", "admin").
417365
WithHeader("Content-Type", "application/json").
418-
WithBytes(body).
366+
WithBytes([]byte(`{}`)).
419367
Expect()
420368

369+
f.Logger.Logf(f.GinkgoT, "dataplane certificates issuer response: %s", respExp.Body().Raw())
370+
421371
respExp.Status(200).Body().Contains("certificate").Contains("private_key").Contains("ca_certificate")
372+
body := respExp.Body().Raw()
422373

423374
var dpCertResp struct {
424375
Value v1.DataplaneCertificate `json:"value"`
425376
}
426-
err = json.Unmarshal(body, &dpCertResp)
427-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
377+
err := json.Unmarshal([]byte(body), &dpCertResp)
378+
Expect(err).ToNot(HaveOccurred())
428379

429380
return &dpCertResp.Value
430381
}
@@ -441,7 +392,7 @@ func (s *Framework) GetAdminKey(gatewayGroupID string) string {
441392

442393
var response responseCreateGateway
443394
err := json.Unmarshal([]byte(body), &response)
444-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "unmarshal response")
395+
Expect(err).ToNot(HaveOccurred(), "unmarshal response")
445396
return response.Value.Key
446397
}
447398

@@ -457,12 +408,12 @@ func (f *Framework) DeleteGatewayGroup(gatewayGroupID string) {
457408
// unmarshal into responseCreateGateway
458409
var response responseCreateGateway
459410
err := json.Unmarshal([]byte(body), &response)
460-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
411+
Expect(err).ToNot(HaveOccurred())
461412
}
462413

463414
func (f *Framework) CreateNewGatewayGroupWithIngress() string {
464415
gid, err := f.CreateNewGatewayGroupWithIngressE()
465-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
416+
Expect(err).ToNot(HaveOccurred())
466417
return gid
467418
}
468419

@@ -498,34 +449,3 @@ func (f *Framework) CreateNewGatewayGroupWithIngressE() (string, error) {
498449
}
499450
return response.Value.ID, nil
500451
}
501-
502-
// ExecuteWithRetry executes the given function with retry logic
503-
func (f *Framework) ExecuteWithRetry(fn func() error, namespace string) error {
504-
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
505-
defer cancel()
506-
507-
return wait.PollUntilContextTimeout(
508-
ctx,
509-
1*time.Second,
510-
30*time.Second,
511-
false,
512-
func(ctx context.Context) (bool, error) {
513-
err := fn()
514-
if err != nil {
515-
f.Logf("Error executing function, retrying: %v", err)
516-
return false, nil
517-
}
518-
return true, nil
519-
},
520-
)
521-
}
522-
523-
// DeployNamespace returns the namespace used for deployment
524-
func (f *Framework) DeployNamespace() string {
525-
return "api7-ee-e2e"
526-
}
527-
528-
// ProxyPort returns the proxy port
529-
func (f *Framework) ProxyPort() int {
530-
return 9080
531-
}

test/e2e/framework/k8s.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,6 @@ func (f *Framework) newDashboardTunnel() error {
201201
case "https":
202202
httpsNodePort = int(port.NodePort)
203203
httpsPort = int(port.Port)
204-
default:
205-
return fmt.Errorf("unknown port name: %s", port.Name)
206204
}
207205
}
208206

test/e2e/scaffold/dp.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
package scaffold
1616

1717
import (
18-
. "github.com/onsi/gomega" //nolint:staticcheck
19-
corev1 "k8s.io/api/core/v1"
18+
. "github.com/onsi/gomega"
2019

2120
"github.com/api7/api7-ingress-controller/test/e2e/framework"
2221
)
2322

2423
func (s *Scaffold) deployDataplane() {
25-
svc := s.deployGateway(framework.DataPlaneDeployOptions{
24+
svc := s.DeployGateway(framework.DataPlaneDeployOptions{
2625
GatewayGroupID: s.gatewaygroupid,
2726
Namespace: s.namespace,
2827
Name: "api7ee3-apisix-gateway-mtls",
@@ -53,11 +52,3 @@ func (s *Scaffold) newAPISIXTunnels() error {
5352
s.apisixHttpsTunnel = httpsTunnel
5453
return nil
5554
}
56-
57-
// deployGateway 部署网关
58-
func (s *Scaffold) deployGateway(opts framework.DataPlaneDeployOptions) *corev1.Service {
59-
// 实现部署网关的逻辑
60-
// 这里只是个占位符,需要根据实际情况实现
61-
// 应该返回一个 *corev1.Service 类型的服务
62-
return nil
63-
}

test/e2e/scaffold/ingress.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,12 @@ import (
44
"github.com/api7/api7-ingress-controller/test/e2e/framework"
55
)
66

7-
// deployIngress 部署 ingress 控制器
87
func (s *Scaffold) deployIngress() {
9-
s.internalDeployIngress(framework.IngressDeployOpts{
8+
s.DeployIngress(framework.IngressDeployOpts{
109
ControllerName: s.opts.ControllerName,
1110
AdminKey: s.AdminKey(),
1211
AdminTLSVerify: false,
1312
Namespace: s.namespace,
1413
AdminEnpoint: framework.DashboardTLSEndpoint,
1514
})
1615
}
17-
18-
// internalDeployIngress 实际部署 ingress 控制器
19-
func (s *Scaffold) internalDeployIngress(opts framework.IngressDeployOpts) {
20-
// 这里实现部署 ingress 的逻辑
21-
// 只是一个占位符,需要根据实际情况实现
22-
}

test/e2e/scaffold/scaffold.go

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -813,49 +813,3 @@ func (s *Scaffold) GetGatewayGroupHTTPSEndpoint(gatewayGroupID string) (string,
813813

814814
return resources.HttpsTunnel.Endpoint(), nil
815815
}
816-
817-
// UploadLicense 上传证书
818-
func (s *Scaffold) UploadLicense() {
819-
// 这里实现上传证书的逻辑
820-
// 作为占位符,实际逻辑需要根据具体情况实现
821-
}
822-
823-
// CreateNewGatewayGroupWithIngress 创建新的网关组和Ingress
824-
func (s *Scaffold) CreateNewGatewayGroupWithIngress() string {
825-
// 这里实现创建网关组和Ingress的逻辑
826-
// 作为占位符,实际逻辑需要根据具体情况实现
827-
return "gateway-group-id-placeholder"
828-
}
829-
830-
// Logf 日志输出函数
831-
func (s *Scaffold) Logf(format string, args ...any) {
832-
// 这里实现日志输出逻辑
833-
s.Framework.Logf(format, args...)
834-
}
835-
836-
// GetAdminKey 获取管理员密钥
837-
func (s *Scaffold) GetAdminKey(gatewayGroupID string) string {
838-
// 这里实现获取管理员密钥的逻辑
839-
// 作为占位符,实际逻辑需要根据具体情况实现
840-
return "admin-key-placeholder"
841-
}
842-
843-
// GetDashboardEndpoint 获取仪表盘端点
844-
func (s *Scaffold) GetDashboardEndpoint() string {
845-
// 这里实现获取仪表盘端点的逻辑
846-
// 作为占位符,实际逻辑需要根据具体情况实现
847-
return "dashboard-endpoint-placeholder"
848-
}
849-
850-
// GetDashboardEndpointHTTPS 获取仪表盘HTTPS端点
851-
func (s *Scaffold) GetDashboardEndpointHTTPS() string {
852-
// 这里实现获取仪表盘HTTPS端点的逻辑
853-
// 作为占位符,实际逻辑需要根据具体情况实现
854-
return "dashboard-endpoint-https-placeholder"
855-
}
856-
857-
// DeleteGatewayGroup 删除网关组
858-
func (s *Scaffold) DeleteGatewayGroup(gatewayGroupID string) {
859-
// 这里实现删除网关组的逻辑
860-
// 作为占位符,实际逻辑需要根据具体情况实现
861-
}

0 commit comments

Comments
 (0)