Skip to content

Commit

Permalink
Wait for the right number of endpoints (#3497)
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf authored Nov 30, 2018
1 parent 24f3e50 commit fdeeac3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion test/e2e/annotations/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Auth", func() {

var httpbinIP string

err := framework.WaitForEndpoints(f.KubeClientSet, framework.DefaultTimeout, "httpbin", f.IngressController.Namespace)
err := framework.WaitForEndpoints(f.KubeClientSet, framework.DefaultTimeout, "httpbin", f.IngressController.Namespace, 1)
Expect(err).NotTo(HaveOccurred())

e, err := f.KubeClientSet.CoreV1().Endpoints(f.IngressController.Namespace).Get("httpbin", metav1.GetOptions{})
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/framework/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,6 @@ func (f *Framework) NewDeployment(name, image string, port int32, replicas int32
s := f.EnsureService(service)
Expect(s).NotTo(BeNil(), "expected a service but none returned")

err = WaitForEndpoints(f.KubeClientSet, DefaultTimeout, name, f.IngressController.Namespace)
err = WaitForEndpoints(f.KubeClientSet, DefaultTimeout, name, f.IngressController.Namespace, int(replicas))
Expect(err).NotTo(HaveOccurred(), "failed to wait for endpoints to become ready")
}
13 changes: 11 additions & 2 deletions test/e2e/framework/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func WaitForPodsReady(kubeClientSet kubernetes.Interface, timeout time.Duration,
}

// WaitForEndpoints waits for a given amount of time until an endpoint contains.
func WaitForEndpoints(kubeClientSet kubernetes.Interface, timeout time.Duration, name, ns string) error {
func WaitForEndpoints(kubeClientSet kubernetes.Interface, timeout time.Duration, name, ns string, expectedEndpoints int) error {
return wait.Poll(2*time.Second, timeout, func() (bool, error) {
endpoint, err := kubeClientSet.CoreV1().Endpoints(ns).Get(name, metav1.GetOptions{})
if k8sErrors.IsNotFound(err) {
Expand All @@ -154,7 +154,16 @@ func WaitForEndpoints(kubeClientSet kubernetes.Interface, timeout time.Duration,
return false, err
}

return true, nil
r := 0
for _, es := range endpoint.Subsets {
r += len(es.Addresses)
}

if r == expectedEndpoints {
return true, nil
}

return false, nil
})
}

Expand Down

0 comments on commit fdeeac3

Please sign in to comment.