@@ -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+ }
0 commit comments