Wait for the right number of endpoints (#3497)
This commit is contained in:
parent
24f3e508b4
commit
fdeeac3606
3 changed files with 13 additions and 4 deletions
|
@ -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{})
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
@ -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
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue