Skip to content

Commit

Permalink
Deflake services e2e
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thockin committed Dec 10, 2015
1 parent f1f250c commit ed1f2d7
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions test/e2e/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ed1f2d7

Please sign in to comment.