From 17030f19b6c274f8e9c756bcb6a928bd9c00cc20 Mon Sep 17 00:00:00 2001 From: Antonio Ojea Date: Mon, 13 Jan 2025 08:02:42 +0000 Subject: [PATCH] e2e services: avoid panic on service creation retry The test was reusing the same variable for the service on each iteration, the problem is that when the service creation fails, it clears out the variable and in the next iteration it panics because is trying to use a field on that same variable. --- test/e2e/network/service.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/e2e/network/service.go b/test/e2e/network/service.go index 5a5491f08c7..fe45f949fc0 100644 --- a/test/e2e/network/service.go +++ b/test/e2e/network/service.go @@ -1680,16 +1680,17 @@ var _ = common.SIGDescribe("Services", func() { } }() - service := t.BuildServiceSpec() - service.Spec.Type = v1.ServiceTypeNodePort + var service *v1.Service + baseService := t.BuildServiceSpec() + baseService.Spec.Type = v1.ServiceTypeNodePort numberOfRetries := 5 ginkgo.By("creating service " + serviceName + " with type NodePort in namespace " + ns) var err error for i := 0; i < numberOfRetries; i++ { port, err := e2eservice.GetUnusedStaticNodePort() framework.ExpectNoError(err, "Static node port allocator was not able to find a free nodeport.") - service.Spec.Ports[0].NodePort = port - service, err = t.CreateService(service) + baseService.Spec.Ports[0].NodePort = port + service, err = t.CreateService(baseService) // We will later delete this service and then recreate it with same nodeport. We need to ensure that // another e2e test doesn't start listening on our old nodeport and conflicts re-creation of service // hence we use ReserveStaticNodePort.