Skip to content

Commit 4c09d81

Browse files
committed
fix: r
Signed-off-by: ashing <[email protected]>
1 parent 51392c0 commit 4c09d81

File tree

2 files changed

+23
-101
lines changed

2 files changed

+23
-101
lines changed

test/e2e/gatewayapi/httproute.go

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ spec:
3333
value: "%s"
3434
`
3535

36-
var defautlGatewayClass = `
36+
var gatewayClassYaml = `
3737
apiVersion: gateway.networking.k8s.io/v1
3838
kind: GatewayClass
3939
metadata:
@@ -42,7 +42,7 @@ spec:
4242
controllerName: %s
4343
`
4444

45-
var defautlGateway = `
45+
var defaultGateway = `
4646
apiVersion: gateway.networking.k8s.io/v1
4747
kind: Gateway
4848
metadata:
@@ -59,7 +59,7 @@ spec:
5959
kind: GatewayProxy
6060
name: api7-proxy-config
6161
`
62-
var defautlGatewayHTTPS = `
62+
var defaultGatewayHTTPS = `
6363
apiVersion: gateway.networking.k8s.io/v1
6464
kind: Gateway
6565
metadata:
@@ -111,7 +111,7 @@ spec:
111111

112112
By("create GatewayClass")
113113
gatewayClassName := fmt.Sprintf("api7-%d", time.Now().Unix())
114-
err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defautlGatewayClass, gatewayClassName, s.GetControllerName()), "")
114+
err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(gatewayClassYaml, gatewayClassName, s.GetControllerName()), "")
115115
Expect(err).NotTo(HaveOccurred(), "creating GatewayClass")
116116
time.Sleep(5 * time.Second)
117117

@@ -122,7 +122,7 @@ spec:
122122
Expect(gcyaml).To(ContainSubstring("message: the gatewayclass has been accepted by the api7-ingress-controller"), "checking GatewayClass condition message")
123123

124124
By("create Gateway")
125-
err = s.CreateResourceFromString(fmt.Sprintf(defautlGateway, gatewayClassName))
125+
err = s.CreateResourceFromString(fmt.Sprintf(defaultGateway, gatewayClassName))
126126
Expect(err).NotTo(HaveOccurred(), "creating Gateway")
127127
time.Sleep(5 * time.Second)
128128

@@ -144,7 +144,7 @@ spec:
144144
createSecret(s, secretName)
145145
By("create GatewayClass")
146146
gatewayClassName := fmt.Sprintf("api7-%d", time.Now().Unix())
147-
err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defautlGatewayClass, gatewayClassName, s.GetControllerName()), "")
147+
err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(gatewayClassYaml, gatewayClassName, s.GetControllerName()), "")
148148
Expect(err).NotTo(HaveOccurred(), "creating GatewayClass")
149149
time.Sleep(5 * time.Second)
150150

@@ -155,7 +155,7 @@ spec:
155155
Expect(gcyaml).To(ContainSubstring("message: the gatewayclass has been accepted by the api7-ingress-controller"), "checking GatewayClass condition message")
156156

157157
By("create Gateway")
158-
err = s.CreateResourceFromString(fmt.Sprintf(defautlGatewayHTTPS, gatewayClassName))
158+
err = s.CreateResourceFromString(fmt.Sprintf(defaultGatewayHTTPS, gatewayClassName))
159159
Expect(err).NotTo(HaveOccurred(), "creating Gateway")
160160
time.Sleep(5 * time.Second)
161161

@@ -214,6 +214,7 @@ spec:
214214
Context("HTTPRoute with Multiple Gateway", func() {
215215
var additionalGatewayGroupID string
216216
var additionalNamespace string
217+
var additionalGatewayClassName string
217218

218219
var additionalGatewayProxyYaml = `
219220
apiVersion: gateway.apisix.io/v1alpha1
@@ -278,58 +279,37 @@ spec:
278279
port: 80
279280
`
280281

281-
var gatewayClassName string
282-
283282
BeforeEach(func() {
284-
By("Create GatewayProxy")
285-
gatewayProxy := fmt.Sprintf(gatewayProxyYaml, framework.DashboardTLSEndpoint, s.AdminKey())
286-
err := s.CreateResourceFromString(gatewayProxy)
287-
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy")
288-
time.Sleep(5 * time.Second)
289-
290-
By("create GatewayClass")
291-
gatewayClassName = fmt.Sprintf("api7-%d", time.Now().Unix())
292-
err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defautlGatewayClass, gatewayClassName, s.GetControllerName()), "")
293-
Expect(err).NotTo(HaveOccurred(), "creating GatewayClass")
294-
time.Sleep(5 * time.Second)
295-
296-
By("check GatewayClass condition")
297-
gcyaml, err := s.GetResourceYaml("GatewayClass", gatewayClassName)
298-
Expect(err).NotTo(HaveOccurred(), "getting GatewayClass yaml")
299-
Expect(gcyaml).To(ContainSubstring(`status: "True"`), "checking GatewayClass condition status")
300-
Expect(gcyaml).To(ContainSubstring("message: the gatewayclass has been accepted by the api7-ingress-controller"), "checking GatewayClass condition message")
301-
302-
By("create Gateway")
303-
err = s.CreateResourceFromString(fmt.Sprintf(defautlGateway, gatewayClassName))
304-
Expect(err).NotTo(HaveOccurred(), "creating Gateway")
305-
time.Sleep(5 * time.Second)
306-
307-
By("check Gateway condition")
308-
gwyaml, err := s.GetResourceYaml("Gateway", "api7ee")
309-
Expect(err).NotTo(HaveOccurred(), "getting Gateway yaml")
310-
Expect(gwyaml).To(ContainSubstring(`status: "True"`), "checking Gateway condition status")
311-
Expect(gwyaml).To(ContainSubstring("message: the gateway has been accepted by the api7-ingress-controller"), "checking Gateway condition message")
283+
beforeEachHTTP()
312284

313285
By("Create additional gateway group")
286+
var err error
314287
additionalGatewayGroupID, additionalNamespace, err = s.CreateAdditionalGatewayGroup("multi-gw")
315288
Expect(err).NotTo(HaveOccurred(), "creating additional gateway group")
316289

317-
By("Initialize dataplane client for additional gateway group")
318-
err = s.InitializeDataplaneClientForGatewayGroup(additionalGatewayGroupID)
319-
Expect(err).NotTo(HaveOccurred(), "initializing dataplane client")
320-
321290
By("Create additional GatewayProxy")
322291
// Get admin key for the additional gateway group
323292
resources, exists := s.GetAdditionalGatewayGroup(additionalGatewayGroupID)
324293
Expect(exists).To(BeTrue(), "additional gateway group should exist")
325294

295+
By("Create additional GatewayClass")
296+
additionalGatewayClassName = fmt.Sprintf("api7-%d", time.Now().Unix())
297+
err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(gatewayClassYaml, additionalGatewayClassName, s.GetControllerName()), "")
298+
Expect(err).NotTo(HaveOccurred(), "creating additional GatewayClass")
299+
time.Sleep(5 * time.Second)
300+
By("Check additional GatewayClass condition")
301+
gcyaml, err := s.GetResourceYaml("GatewayClass", additionalGatewayClassName)
302+
Expect(err).NotTo(HaveOccurred(), "getting additional GatewayClass yaml")
303+
Expect(gcyaml).To(ContainSubstring(`status: "True"`), "checking additional GatewayClass condition status")
304+
Expect(gcyaml).To(ContainSubstring("message: the gatewayclass has been accepted by the api7-ingress-controller"), "checking additional GatewayClass condition message")
305+
326306
additionalGatewayProxy := fmt.Sprintf(additionalGatewayProxyYaml, framework.DashboardTLSEndpoint, resources.AdminAPIKey)
327307
err = s.CreateResourceFromStringWithNamespace(additionalGatewayProxy, additionalNamespace)
328308
Expect(err).NotTo(HaveOccurred(), "creating additional GatewayProxy")
329309

330310
By("Create additional Gateway")
331311
err = s.CreateResourceFromStringWithNamespace(
332-
fmt.Sprintf(additionalGateway, gatewayClassName),
312+
fmt.Sprintf(additionalGateway, additionalGatewayClassName),
333313
additionalNamespace,
334314
)
335315
Expect(err).NotTo(HaveOccurred(), "creating additional Gateway")
@@ -359,7 +339,7 @@ spec:
359339
Status(http.StatusOK)
360340

361341
By("Delete Additional Gateway")
362-
err = s.DeleteResourceFromStringWithNamespace(fmt.Sprintf(additionalGateway, gatewayClassName), additionalNamespace)
342+
err = s.DeleteResourceFromStringWithNamespace(fmt.Sprintf(additionalGateway, additionalGatewayClassName), additionalNamespace)
363343
Expect(err).NotTo(HaveOccurred(), "deleting additional Gateway")
364344
time.Sleep(5 * time.Second)
365345

test/e2e/scaffold/scaffold.go

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -801,64 +801,6 @@ func (s *Scaffold) CleanupAdditionalGatewayGroup(gatewayGroupID string) error {
801801
return err
802802
}
803803

804-
// InitializeDataplaneClientForGatewayGroup initializes the Dashboard client for a specific Gateway group
805-
func (s *Scaffold) InitializeDataplaneClientForGatewayGroup(gatewayGroupID string) error {
806-
resources, exists := s.additionalGatewayGroups[gatewayGroupID]
807-
if !exists {
808-
return fmt.Errorf("gateway group %s not found", gatewayGroupID)
809-
}
810-
811-
// HTTP client
812-
httpURL := fmt.Sprintf("http://%s/apisix/admin", resources.HttpTunnel.Endpoint())
813-
clusterName := fmt.Sprintf("gateway-%s", gatewayGroupID[:8]) // Use first 8 chars of gateway group ID as identifier
814-
815-
err := s.apisixCli.AddCluster(context.Background(), &dashboard.ClusterOptions{
816-
Name: clusterName,
817-
ControllerName: s.opts.ControllerName,
818-
Labels: map[string]string{"k8s/controller-name": s.opts.ControllerName},
819-
BaseURL: httpURL,
820-
AdminKey: resources.AdminAPIKey,
821-
})
822-
if err != nil {
823-
return err
824-
}
825-
826-
// HTTPS client
827-
httpsURL := fmt.Sprintf("https://%s/apisix/admin", resources.HttpsTunnel.Endpoint())
828-
clusterNameHTTPS := fmt.Sprintf("gateway-%s-https", gatewayGroupID[:8])
829-
830-
err = s.apisixCli.AddCluster(context.Background(), &dashboard.ClusterOptions{
831-
Name: clusterNameHTTPS,
832-
BaseURL: httpsURL,
833-
AdminKey: resources.AdminAPIKey,
834-
SkipTLSVerify: true,
835-
})
836-
837-
return err
838-
}
839-
840-
// GetDataplaneResourceForGatewayGroup returns the dataplane resource for a specific Gateway group
841-
func (s *Scaffold) GetDataplaneResourceForGatewayGroup(gatewayGroupID string) (dashboard.Cluster, error) {
842-
_, exists := s.additionalGatewayGroups[gatewayGroupID]
843-
if !exists {
844-
return nil, fmt.Errorf("gateway group %s not found", gatewayGroupID)
845-
}
846-
847-
clusterName := fmt.Sprintf("gateway-%s", gatewayGroupID[:8])
848-
return s.apisixCli.Cluster(clusterName), nil
849-
}
850-
851-
// GetDataplaneResourceHTTPSForGatewayGroup returns the HTTPS dataplane resource for a specific Gateway group
852-
func (s *Scaffold) GetDataplaneResourceHTTPSForGatewayGroup(gatewayGroupID string) (dashboard.Cluster, error) {
853-
_, exists := s.additionalGatewayGroups[gatewayGroupID]
854-
if !exists {
855-
return nil, fmt.Errorf("gateway group %s not found", gatewayGroupID)
856-
}
857-
858-
clusterName := fmt.Sprintf("gateway-%s-https", gatewayGroupID[:8])
859-
return s.apisixCli.Cluster(clusterName), nil
860-
}
861-
862804
// GetGatewayGroupHTTPEndpoint returns the HTTP endpoint for a specific Gateway group
863805
func (s *Scaffold) GetGatewayGroupHTTPEndpoint(gatewayGroupID string) (string, error) {
864806
resources, exists := s.additionalGatewayGroups[gatewayGroupID]

0 commit comments

Comments
 (0)