Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deflake services e2e #18532

Merged
merged 2 commits into from
Dec 11, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 20 additions & 13 deletions test/e2e/service.go
Expand Up @@ -504,29 +504,36 @@ 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason we can't just simplify this to

nodePort2 := ServiceNodePortRange.Base + (nodePort1 + i) % ServiceNodePortRange.Size

? The multiple offsets with subtraction and addition is a little confusing to follow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't give me the loop I want. I could just linear search from base
to base+limit if you think that would be easier to understand, but I
thought this was not too bad - get the offset of nodePort1, increment it
with wraparound, add it to base.

On Thu, Dec 10, 2015 at 4:20 PM, Jeff Grafton notifications@github.com
wrote:

In test/e2e/service.go
#18532 (comment)
:

@@ -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
    

is there a reason we can't just simplify this to

nodePort2 := ServiceNodePortRange.Base + (nodePort1 + i) % ServiceNodePortRange.Size

? The multiple offsets with subtraction and addition is a little confusing
to follow.


Reply to this email directly or view it on GitHub
https://github.com/kubernetes/kubernetes/pull/18532/files#r47307011.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's good enough (I also spent some time thinking why it is correct, but it seems to be).
Anyway - I'm going to manually merge this PR to see if that helps.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we decide that it's too complicated, we can fix that in a follow-up PR, I guess.

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 {
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")
Expand All @@ -541,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
}

Expand Down