@@ -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
244253func (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
248314func (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