Skip to content

Commit 530a8a9

Browse files
committed
fix: r
Signed-off-by: ashing <[email protected]>
1 parent bdad4bb commit 530a8a9

File tree

2 files changed

+104
-2
lines changed

2 files changed

+104
-2
lines changed

test/e2e/apisix/basic.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,19 @@ var _ = Describe("APISIX Standalone Basic Tests", func() {
3434
Expect().
3535
Status(404).Body().Contains("404 Route Not Found")
3636
})
37+
38+
It("should handle basic HTTP requests with additional gateway", func() {
39+
additionalGatewayID, _, err := s.Deployer.CreateAdditionalGateway("additional-gw")
40+
Expect(err).NotTo(HaveOccurred())
41+
42+
httpClient, err := s.NewAPISIXClientForGateway(additionalGatewayID)
43+
Expect(err).NotTo(HaveOccurred())
44+
Expect(httpClient).NotTo(BeNil())
45+
46+
httpClient.GET("/anything").
47+
Expect().
48+
Status(404).Body().Contains("404 Route Not Found")
49+
})
50+
3751
})
3852
})

test/e2e/scaffold/apisix_deployer.go

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ func (s *APISIXDeployer) BeforeEach() {
7171
s.label["apisix.ingress.watch"] = s.namespace
7272
}
7373

74+
// Initialize additionalGateways map
75+
s.additionalGateways = make(map[string]*GatewayResources)
76+
7477
var nsLabel map[string]string
7578
if !s.opts.DisableNamespaceLabel {
7679
nsLabel = s.label
@@ -107,6 +110,12 @@ func (s *APISIXDeployer) AfterEach() {
107110
}
108111
}
109112

113+
// Delete all additional gateways
114+
for identifier := range s.additionalGateways {
115+
err := s.CleanupAdditionalGateway(identifier)
116+
Expect(err).NotTo(HaveOccurred(), "cleaning up additional gateway")
117+
}
118+
110119
// if the test case is successful, just delete namespace
111120
err := k8s.DeleteNamespaceE(s.t, s.kubectlOptions, s.namespace)
112121
Expect(err).NotTo(HaveOccurred(), "deleting namespace "+s.namespace)
@@ -242,9 +251,88 @@ func (s *APISIXDeployer) createAdminTunnel(
242251
}
243252

244253
func (s *APISIXDeployer) CreateAdditionalGateway(namePrefix string) (string, string, error) {
245-
return "", "", nil
254+
// Create a new namespace for this additional gateway
255+
additionalNS := fmt.Sprintf("%s-%d", namePrefix, time.Now().Unix())
256+
257+
// Create namespace with the same labels
258+
var nsLabel map[string]string
259+
if !s.opts.DisableNamespaceLabel {
260+
nsLabel = s.label
261+
}
262+
k8s.CreateNamespaceWithMetadata(s.t, s.kubectlOptions, metav1.ObjectMeta{Name: additionalNS, Labels: nsLabel})
263+
264+
// Create new kubectl options for the new namespace
265+
kubectlOpts := &k8s.KubectlOptions{
266+
ConfigPath: s.opts.Kubeconfig,
267+
Namespace: additionalNS,
268+
}
269+
270+
s.Logf("additional gateway in namespace %s", additionalNS)
271+
272+
// Use the same admin key as the main gateway
273+
adminKey := s.opts.APISIXAdminAPIKey
274+
s.Logf("additional gateway admin api key: %s", adminKey)
275+
276+
// Store gateway resources info
277+
resources := &GatewayResources{
278+
Namespace: additionalNS,
279+
AdminAPIKey: adminKey,
280+
}
281+
282+
serviceName := fmt.Sprintf("apisix-standalone-%s", namePrefix)
283+
284+
// Deploy dataplane for this additional gateway
285+
opts := APISIXDeployOptions{
286+
Namespace: additionalNS,
287+
AdminKey: adminKey,
288+
ServiceName: serviceName,
289+
ServiceHTTPPort: 9080,
290+
ServiceHTTPSPort: 9443,
291+
}
292+
svc := s.deployDataplane(&opts)
293+
294+
resources.DataplaneService = svc
295+
296+
// Create tunnels for the dataplane
297+
httpTunnel, httpsTunnel, err := s.createDataplaneTunnels(svc, kubectlOpts, serviceName)
298+
if err != nil {
299+
return "", "", err
300+
}
301+
302+
resources.HttpTunnel = httpTunnel
303+
resources.HttpsTunnel = httpsTunnel
304+
305+
// Use namespace as identifier for APISIX deployments
306+
identifier := additionalNS
307+
308+
// Store in the map
309+
s.additionalGateways[identifier] = resources
310+
311+
return identifier, additionalNS, nil
246312
}
247313

248314
func (s *APISIXDeployer) CleanupAdditionalGateway(identifier string) error {
249-
return nil
315+
resources, exists := s.additionalGateways[identifier]
316+
if !exists {
317+
return fmt.Errorf("gateway %s not found", identifier)
318+
}
319+
320+
// Close tunnels if they exist
321+
if resources.HttpTunnel != nil {
322+
resources.HttpTunnel.Close()
323+
}
324+
if resources.HttpsTunnel != nil {
325+
resources.HttpsTunnel.Close()
326+
}
327+
328+
// Delete the namespace
329+
err := k8s.DeleteNamespaceE(s.t, &k8s.KubectlOptions{
330+
ConfigPath: s.opts.Kubeconfig,
331+
Namespace: resources.Namespace,
332+
}, resources.Namespace)
333+
334+
// Remove from the map
335+
delete(s.additionalGateways, identifier)
336+
337+
return err
250338
}

0 commit comments

Comments
 (0)