Skip to content

Commit d08aca5

Browse files
committed
refactor: simplify tunnel close handling and remove redundant pod list check
1 parent 129c15f commit d08aca5

File tree

4 files changed

+30
-25
lines changed

4 files changed

+30
-25
lines changed

test/e2e/crds/gatewayproxy.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ spec:
187187
keyword = fmt.Sprintf(`{"config.ServerAddrs": ["http://%s:9180"]}`, s.GetPodIP(s.Namespace(), "app.kubernetes.io/name=apisix"))
188188
}
189189

190-
s.Deployer.DeployIngress()
191190
By(fmt.Sprintf("wait for keyword: %s", keyword))
192191
s.WaitControllerManagerLog(keyword, 60, time.Minute)
193192
})

test/e2e/framework/k8s.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@ func (f *Framework) WaitControllerManagerLog(keyword string, sinceSeconds int64,
368368

369369
func (f *Framework) WaitPodsLog(selector, keyword string, sinceSeconds int64, timeout time.Duration) {
370370
pods := f.ListRunningPods(selector)
371-
Expect(pods).NotTo(BeEmpty())
372371
wg := sync.WaitGroup{}
373372
for _, p := range pods {
374373
wg.Add(1)

test/e2e/scaffold/apisix_deployer.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,12 @@ func (s *APISIXDeployer) DeployDataplane(deployOpts DeployDataplaneOptions) {
168168
opts.Replicas = deployOpts.Replicas
169169
}
170170

171-
if s.adminTunnel != nil {
172-
s.adminTunnel.Close()
173-
s.adminTunnel = nil
174-
}
175-
if s.apisixHttpTunnel != nil {
176-
s.apisixHttpTunnel.Close()
177-
s.apisixHttpTunnel = nil
178-
}
179-
if s.apisixHttpsTunnel != nil {
180-
s.apisixHttpsTunnel.Close()
181-
s.apisixHttpsTunnel = nil
171+
for _, close := range []func(){
172+
s.closeAdminTunnel,
173+
s.closeApisixHttpTunnel,
174+
s.closeApisixHttpsTunnel,
175+
} {
176+
close()
182177
}
183178

184179
svc := s.deployDataplane(&opts)
@@ -305,14 +300,18 @@ func (s *APISIXDeployer) createAdminTunnel(svc *corev1.Service) (*k8s.Tunnel, er
305300
if err := adminTunnel.ForwardPortE(s.t); err != nil {
306301
return nil, err
307302
}
308-
s.addFinalizers(func() {
309-
adminTunnel.Close()
310-
s.adminTunnel = nil
311-
})
303+
s.addFinalizers(s.closeAdminTunnel)
312304

313305
return adminTunnel, nil
314306
}
315307

308+
func (s *APISIXDeployer) closeAdminTunnel() {
309+
if s.adminTunnel != nil {
310+
s.adminTunnel.Close()
311+
s.adminTunnel = nil
312+
}
313+
}
314+
316315
func (s *APISIXDeployer) CreateAdditionalGateway(namePrefix string) (string, *corev1.Service, error) {
317316
// Create a new namespace for this additional gateway
318317
additionalNS := fmt.Sprintf("%s-%d", namePrefix, time.Now().Unix())

test/e2e/scaffold/scaffold.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,23 +313,31 @@ func (s *Scaffold) createDataplaneTunnels(
313313
if err := httpTunnel.ForwardPortE(s.t); err != nil {
314314
return nil, nil, err
315315
}
316-
s.addFinalizers(func() {
317-
httpTunnel.Close()
318-
s.apisixHttpTunnel = nil
319-
})
316+
s.addFinalizers(s.closeApisixHttpTunnel)
320317

321318
if err := httpsTunnel.ForwardPortE(s.t); err != nil {
322319
httpTunnel.Close()
323320
return nil, nil, err
324321
}
325-
s.addFinalizers(func() {
326-
httpsTunnel.Close()
327-
s.apisixHttpsTunnel = nil
328-
})
322+
s.addFinalizers(s.closeApisixHttpsTunnel)
329323

330324
return httpTunnel, httpsTunnel, nil
331325
}
332326

327+
func (s *Scaffold) closeApisixHttpTunnel() {
328+
if s.apisixHttpTunnel != nil {
329+
s.apisixHttpTunnel.Close()
330+
s.apisixHttpTunnel = nil
331+
}
332+
}
333+
334+
func (s *Scaffold) closeApisixHttpsTunnel() {
335+
if s.apisixHttpsTunnel != nil {
336+
s.apisixHttpsTunnel.Close()
337+
s.apisixHttpsTunnel = nil
338+
}
339+
}
340+
333341
// GetAdditionalGateway returns resources associated with a specific gateway
334342
func (s *Scaffold) GetAdditionalGateway(identifier string) (*GatewayResources, bool) {
335343
resources, exists := s.additionalGateways[identifier]

0 commit comments

Comments
 (0)