Skip to content

Commit bdad4bb

Browse files
committed
feat: apisix standalone
Signed-off-by: ashing <[email protected]>
1 parent eeb847f commit bdad4bb

File tree

7 files changed

+146
-141
lines changed

7 files changed

+146
-141
lines changed

test/e2e/crds/consumer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,13 +476,13 @@ spec:
476476

477477
By("create additional gateway group to get new admin key")
478478
var err error
479-
additionalGatewayGroupID, _, err = s.CreateAdditionalGatewayGroup("gateway-proxy-update")
479+
additionalGatewayGroupID, _, err = s.Deployer.CreateAdditionalGateway("gateway-proxy-update")
480480
Expect(err).NotTo(HaveOccurred(), "creating additional gateway group")
481481

482-
resources, exists := s.GetAdditionalGatewayGroup(additionalGatewayGroupID)
482+
resources, exists := s.GetAdditionalGateway(additionalGatewayGroupID)
483483
Expect(exists).To(BeTrue(), "additional gateway group should exist")
484484

485-
client, err := s.NewAPISIXClientForGatewayGroup(additionalGatewayGroupID)
485+
client, err := s.NewAPISIXClientForGateway(additionalGatewayGroupID)
486486
Expect(err).NotTo(HaveOccurred(), "creating APISIX client for additional gateway group")
487487

488488
By("Consumer not found for additional gateway group")

test/e2e/gatewayapi/httproute.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,12 @@ spec:
303303

304304
By("Create additional gateway group")
305305
var err error
306-
additionalGatewayGroupID, additionalNamespace, err = s.CreateAdditionalGatewayGroup("multi-gw")
306+
additionalGatewayGroupID, additionalNamespace, err = s.Deployer.CreateAdditionalGateway("multi-gw")
307307
Expect(err).NotTo(HaveOccurred(), "creating additional gateway group")
308308

309309
By("Create additional GatewayProxy")
310310
// Get admin key for the additional gateway group
311-
resources, exists := s.GetAdditionalGatewayGroup(additionalGatewayGroupID)
311+
resources, exists := s.GetAdditionalGateway(additionalGatewayGroupID)
312312
Expect(exists).To(BeTrue(), "additional gateway group should exist")
313313

314314
By("Create additional GatewayClass")
@@ -348,7 +348,7 @@ spec:
348348
Status(http.StatusOK)
349349

350350
By("Access through additional gateway")
351-
client, err := s.NewAPISIXClientForGatewayGroup(additionalGatewayGroupID)
351+
client, err := s.NewAPISIXClientForGateway(additionalGatewayGroupID)
352352
Expect(err).NotTo(HaveOccurred(), "creating client for additional gateway")
353353

354354
client.
@@ -370,7 +370,7 @@ spec:
370370
Status(http.StatusOK)
371371

372372
By("HTTPRoute should not be accessible through additional gateway")
373-
client, err = s.NewAPISIXClientForGatewayGroup(additionalGatewayGroupID)
373+
client, err = s.NewAPISIXClientForGateway(additionalGatewayGroupID)
374374
Expect(err).NotTo(HaveOccurred(), "creating client for additional gateway")
375375

376376
client.
@@ -1671,13 +1671,13 @@ spec:
16711671

16721672
By("create additional gateway group to get new admin key")
16731673
var err error
1674-
additionalGatewayGroupID, _, err = s.CreateAdditionalGatewayGroup("gateway-proxy-update")
1674+
additionalGatewayGroupID, _, err = s.Deployer.CreateAdditionalGateway("gateway-proxy-update")
16751675
Expect(err).NotTo(HaveOccurred(), "creating additional gateway group")
16761676

1677-
resources, exists := s.GetAdditionalGatewayGroup(additionalGatewayGroupID)
1677+
resources, exists := s.GetAdditionalGateway(additionalGatewayGroupID)
16781678
Expect(exists).To(BeTrue(), "additional gateway group should exist")
16791679

1680-
client, err := s.NewAPISIXClientForGatewayGroup(additionalGatewayGroupID)
1680+
client, err := s.NewAPISIXClientForGateway(additionalGatewayGroupID)
16811681
Expect(err).NotTo(HaveOccurred(), "creating APISIX client for additional gateway group")
16821682

16831683
By("HTTPRoute not found for additional gateway group")

test/e2e/ingress/ingress.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -831,10 +831,10 @@ spec:
831831
Status(200)
832832

833833
By("create additional gateway group to get new admin key")
834-
additionalGatewayGroupID, _, err = s.CreateAdditionalGatewayGroup("gateway-proxy-update")
834+
additionalGatewayGroupID, _, err = s.Deployer.CreateAdditionalGateway("gateway-proxy-update")
835835
Expect(err).NotTo(HaveOccurred(), "creating additional gateway group")
836836

837-
client, err := s.NewAPISIXClientForGatewayGroup(additionalGatewayGroupID)
837+
client, err := s.NewAPISIXClientForGateway(additionalGatewayGroupID)
838838
Expect(err).NotTo(HaveOccurred(), "creating APISIX client for additional gateway group")
839839

840840
By("Ingress not found for additional gateway group")
@@ -844,7 +844,7 @@ spec:
844844
Expect().
845845
Status(404)
846846

847-
resources, exists := s.GetAdditionalGatewayGroup(additionalGatewayGroupID)
847+
resources, exists := s.GetAdditionalGateway(additionalGatewayGroupID)
848848
Expect(exists).To(BeTrue(), "additional gateway group should exist")
849849

850850
By("update GatewayProxy with new admin key")
@@ -965,10 +965,10 @@ spec:
965965
Expect().Header("X-Proxy-Test").IsEqual("enabled")
966966

967967
By("create additional gateway group to get new admin key")
968-
additionalGatewayGroupID, _, err = s.CreateAdditionalGatewayGroup("gateway-proxy-update")
968+
additionalGatewayGroupID, _, err = s.Deployer.CreateAdditionalGateway("gateway-proxy-update")
969969
Expect(err).NotTo(HaveOccurred(), "creating additional gateway group")
970970

971-
client, err := s.NewAPISIXClientForGatewayGroup(additionalGatewayGroupID)
971+
client, err := s.NewAPISIXClientForGateway(additionalGatewayGroupID)
972972
Expect(err).NotTo(HaveOccurred(), "creating APISIX client for additional gateway group")
973973

974974
By("Ingress not found for additional gateway group")
@@ -978,7 +978,7 @@ spec:
978978
Expect().
979979
Status(http.StatusNotFound)
980980

981-
resources, exists := s.GetAdditionalGatewayGroup(additionalGatewayGroupID)
981+
resources, exists := s.GetAdditionalGateway(additionalGatewayGroupID)
982982
Expect(exists).To(BeTrue(), "additional gateway group should exist")
983983

984984
By("update secret")

test/e2e/scaffold/api7_deployer.go

Lines changed: 96 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (s *API7Deployer) BeforeEach() {
6666
}
6767

6868
// Initialize additionalGatewayGroups map
69-
s.additionalGatewayGroups = make(map[string]*GatewayGroupResources)
69+
s.additionalGateways = make(map[string]*GatewayResources)
7070

7171
var nsLabel map[string]string
7272
if !s.opts.DisableNamespaceLabel {
@@ -113,8 +113,8 @@ func (s *API7Deployer) AfterEach() {
113113
}
114114

115115
// Delete all additional namespaces
116-
for _, resources := range s.additionalGatewayGroups {
117-
err := s.CleanupAdditionalGatewayGroup(resources.GatewayGroupID)
116+
for identifier := range s.additionalGateways {
117+
err := s.CleanupAdditionalGateway(identifier)
118118
Expect(err).NotTo(HaveOccurred(), "cleaning up additional gateway group")
119119
}
120120

@@ -185,15 +185,15 @@ func (s *API7Deployer) initDataPlaneClient() {
185185
s.apisixCli, err = dashboard.NewClient()
186186
Expect(err).NotTo(HaveOccurred(), "creating apisix client")
187187

188-
url := fmt.Sprintf("http://%s/apisix/admin", s.GetDashboardEndpoint())
188+
adminURL := fmt.Sprintf("http://%s/apisix/admin", s.GetDashboardEndpoint())
189189

190-
s.Logf("apisix admin: %s", url)
190+
s.Logf("apisix admin: %s", adminURL)
191191

192192
err = s.apisixCli.AddCluster(context.Background(), &dashboard.ClusterOptions{
193193
Name: "default",
194194
ControllerName: s.opts.ControllerName,
195195
Labels: map[string]string{"k8s/controller-name": s.opts.ControllerName},
196-
BaseURL: url,
196+
BaseURL: adminURL,
197197
AdminKey: s.AdminKey(),
198198
})
199199
Expect(err).NotTo(HaveOccurred(), "adding cluster")
@@ -207,3 +207,93 @@ func (s *API7Deployer) initDataPlaneClient() {
207207
})
208208
Expect(err).NotTo(HaveOccurred(), "adding cluster")
209209
}
210+
211+
// CreateAdditionalGateway creates a new gateway group and deploys a dataplane for it.
212+
// It returns the gateway group ID and namespace name where the dataplane is deployed.
213+
func (s *API7Deployer) CreateAdditionalGateway(namePrefix string) (string, string, error) {
214+
// Create a new namespace for this gateway group
215+
additionalNS := fmt.Sprintf("%s-%d", namePrefix, time.Now().Unix())
216+
217+
// Create namespace with the same labels
218+
var nsLabel map[string]string
219+
if !s.opts.DisableNamespaceLabel {
220+
nsLabel = s.label
221+
}
222+
k8s.CreateNamespaceWithMetadata(s.t, s.kubectlOptions, metav1.ObjectMeta{Name: additionalNS, Labels: nsLabel})
223+
224+
// Create new kubectl options for the new namespace
225+
kubectlOpts := &k8s.KubectlOptions{
226+
ConfigPath: s.opts.Kubeconfig,
227+
Namespace: additionalNS,
228+
}
229+
230+
// Create a new gateway group
231+
gatewayGroupID := s.CreateNewGatewayGroupWithIngress()
232+
s.Logf("additional gateway group id: %s in namespace %s", gatewayGroupID, additionalNS)
233+
234+
// Get the admin key for this gateway group
235+
adminKey := s.GetAdminKey(gatewayGroupID)
236+
s.Logf("additional gateway group admin api key: %s", adminKey)
237+
238+
// Store gateway group info
239+
resources := &GatewayResources{
240+
Namespace: additionalNS,
241+
AdminAPIKey: adminKey,
242+
}
243+
244+
serviceName := fmt.Sprintf("api7ee3-apisix-gateway-%s", namePrefix)
245+
246+
// Deploy dataplane for this gateway group
247+
svc := s.DeployGateway(framework.DataPlaneDeployOptions{
248+
GatewayGroupID: gatewayGroupID,
249+
Namespace: additionalNS,
250+
Name: serviceName,
251+
ServiceName: serviceName,
252+
DPManagerEndpoint: framework.DPManagerTLSEndpoint,
253+
SetEnv: true,
254+
SSLKey: framework.TestKey,
255+
SSLCert: framework.TestCert,
256+
TLSEnabled: true,
257+
ForIngressGatewayGroup: true,
258+
ServiceHTTPPort: 9080,
259+
ServiceHTTPSPort: 9443,
260+
})
261+
262+
resources.DataplaneService = svc
263+
264+
// Create tunnels for the dataplane
265+
httpTunnel, httpsTunnel, err := s.createDataplaneTunnels(svc, kubectlOpts, serviceName)
266+
if err != nil {
267+
return "", "", err
268+
}
269+
270+
resources.HttpTunnel = httpTunnel
271+
resources.HttpsTunnel = httpsTunnel
272+
273+
// Store in the map
274+
s.additionalGateways[gatewayGroupID] = resources
275+
276+
return gatewayGroupID, additionalNS, nil
277+
}
278+
279+
// CleanupAdditionalGateway cleans up resources associated with a specific Gateway group
280+
func (s *API7Deployer) CleanupAdditionalGateway(gatewayGroupID string) error {
281+
resources, exists := s.additionalGateways[gatewayGroupID]
282+
if !exists {
283+
return fmt.Errorf("gateway group %s not found", gatewayGroupID)
284+
}
285+
286+
// Delete the gateway group
287+
s.DeleteGatewayGroup(gatewayGroupID)
288+
289+
// Delete the namespace
290+
err := k8s.DeleteNamespaceE(s.t, &k8s.KubectlOptions{
291+
ConfigPath: s.opts.Kubeconfig,
292+
Namespace: resources.Namespace,
293+
}, resources.Namespace)
294+
295+
// Remove from the map
296+
delete(s.additionalGateways, gatewayGroupID)
297+
298+
return err
299+
}

test/e2e/scaffold/apisix_deployer.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,11 @@ func (s *APISIXDeployer) createAdminTunnel(
240240

241241
return adminTunnel, nil
242242
}
243+
244+
func (s *APISIXDeployer) CreateAdditionalGateway(namePrefix string) (string, string, error) {
245+
return "", "", nil
246+
}
247+
248+
func (s *APISIXDeployer) CleanupAdditionalGateway(identifier string) error {
249+
return nil
250+
}

test/e2e/scaffold/deployer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ type Deployer interface {
2020
ScaleIngress(replicas int)
2121
BeforeEach()
2222
AfterEach()
23+
CreateAdditionalGateway(namePrefix string) (string, string, error)
24+
CleanupAdditionalGateway(identifier string) error
2325
}
2426

2527
var NewDeployer func(*Scaffold) Deployer

0 commit comments

Comments
 (0)