From ed1f2d75e9c68c6b0739f2de8359867360701579 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Thu, 10 Dec 2015 13:43:26 -0800 Subject: [PATCH 1/2] Deflake services e2e Picking a nodePort needs to be more robust than "add one to an existing port and hope it works". Now we try all ports in the range if we have to. --- test/e2e/service.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/test/e2e/service.go b/test/e2e/service.go index 2f20ab637f8..c9f2eb0cad3 100644 --- a/test/e2e/service.go +++ b/test/e2e/service.go @@ -504,15 +504,22 @@ var _ = Describe("Services", func() { By("hitting the pod through the service's LoadBalancer") testLoadBalancerReachable(ingress1, 80) - By("changing service " + serviceName + " update NodePort") - nodePort2 := nodePort1 - 1 - if !ServiceNodePortRange.Contains(nodePort2) { - //Check for (unlikely) assignment at bottom of range - nodePort2 = nodePort1 + 1 + By("changing service " + serviceName + ": update NodePort") + nodePort2 := 0 + for i := 1; i < ServiceNodePortRange.Size; i++ { + offs1 := nodePort1 - ServiceNodePortRange.Base + offs2 := (offs1 + i) % ServiceNodePortRange.Size + nodePort2 := ServiceNodePortRange.Base + offs2 + service, err = updateService(f.Client, f.Namespace.Name, serviceName, func(s *api.Service) { + s.Spec.Ports[0].NodePort = nodePort2 + }) + if err != nil && strings.Contains(err.Error(), "provided port is already allocated") { + Logf("nodePort %d is busy, will retry", nodePort2) + continue + } + // Otherwise err was nil or err was a real error + break } - service, err = updateService(f.Client, f.Namespace.Name, serviceName, func(s *api.Service) { - s.Spec.Ports[0].NodePort = nodePort2 - }) Expect(err).NotTo(HaveOccurred()) if service.Spec.Type != api.ServiceTypeLoadBalancer { From ad22d00e4038eb05d29f21aabbaba4cf3c545a40 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Thu, 10 Dec 2015 13:52:54 -0800 Subject: [PATCH 2/2] Extend a too-short timeout in services e2e --- test/e2e/service.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/e2e/service.go b/test/e2e/service.go index c9f2eb0cad3..65ce1ab6b2c 100644 --- a/test/e2e/service.go +++ b/test/e2e/service.go @@ -509,7 +509,7 @@ var _ = Describe("Services", func() { for i := 1; i < ServiceNodePortRange.Size; i++ { offs1 := nodePort1 - ServiceNodePortRange.Base offs2 := (offs1 + i) % ServiceNodePortRange.Size - nodePort2 := ServiceNodePortRange.Base + offs2 + nodePort2 = ServiceNodePortRange.Base + offs2 service, err = updateService(f.Client, f.Namespace.Name, serviceName, func(s *api.Service) { s.Spec.Ports[0].NodePort = nodePort2 }) @@ -523,17 +523,17 @@ var _ = Describe("Services", func() { Expect(err).NotTo(HaveOccurred()) if service.Spec.Type != api.ServiceTypeLoadBalancer { - Failf("got unexpected Spec.Type for updated-NodePort service: %v", service) + Failf("got unexpected Spec.Type for updated-LoadBalancer service: %v", service) } if len(service.Spec.Ports) != 1 { - Failf("got unexpected len(Spec.Ports) for updated-NodePort service: %v", service) + Failf("got unexpected len(Spec.Ports) for updated-LoadBalancer service: %v", service) } port = service.Spec.Ports[0] if port.NodePort != nodePort2 { - Failf("got unexpected Spec.Ports[0].nodePort for NodePort service: %v", service) + Failf("got unexpected Spec.Ports[0].nodePort for LoadBalancer service: %v", service) } if len(service.Status.LoadBalancer.Ingress) != 1 { - Failf("got unexpected len(Status.LoadBalancer.Ingress) for NodePort service: %v", service) + Failf("got unexpected len(Status.LoadBalancer.Ingress) for LoadBalancer service: %v", service) } By("hitting the pod through the service's updated NodePort") @@ -548,7 +548,7 @@ var _ = Describe("Services", func() { Expect(err).NotTo(HaveOccurred()) ingress2 := service.Status.LoadBalancer.Ingress[0] - if testLoadBalancerReachableInTime(ingress2, 80, 5*time.Second) { + if testLoadBalancerReachable(ingress2, 80) { break }