Wait for the right number of endpoints (#3497)

This commit is contained in:
Manuel Alejandro de Brito Fontes 2018-11-30 20:17:18 -03:00 committed by GitHub
parent 24f3e508b4
commit fdeeac3606
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 4 deletions

View file

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