@@ -2,30 +2,24 @@ package framework
22
33import (
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
3125var (
@@ -204,6 +198,10 @@ dp_manager_configuration:
204198 database:
205199 dsn: {{ .DSN }}
206200prometheus:
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
332309func (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
389361func (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
463414func (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- }
0 commit comments