Wait a few seconds for the cluster to become healthly.
parent
3fb62577ce
commit
94aca79782
|
@ -63,11 +63,16 @@ func CanReadFile(path string) bool {
|
|||
}
|
||||
|
||||
func Retry(attempts int, callback func() error) (err error) {
|
||||
return RetryAfter(attempts, callback, 0)
|
||||
}
|
||||
|
||||
func RetryAfter(attempts int, callback func() error, d time.Duration) (err error) {
|
||||
for i := 0; i < attempts; i++ {
|
||||
err = callback()
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
time.Sleep(d)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -21,8 +21,10 @@ package integration
|
|||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
commonutil "k8s.io/minikube/pkg/util"
|
||||
"k8s.io/minikube/test/integration/util"
|
||||
)
|
||||
|
||||
|
@ -33,19 +35,26 @@ func TestClusterStatus(t *testing.T) {
|
|||
|
||||
kubectlRunner := util.NewKubectlRunner(t)
|
||||
cs := api.ComponentStatusList{}
|
||||
kubectlRunner.RunCommand([]string{"get", "cs"}, &cs)
|
||||
|
||||
for _, i := range cs.Items {
|
||||
status := api.ConditionFalse
|
||||
for _, c := range i.Conditions {
|
||||
if c.Type != api.ComponentHealthy {
|
||||
continue
|
||||
healthy := func() error {
|
||||
kubectlRunner.RunCommand([]string{"get", "cs"}, &cs)
|
||||
for _, i := range cs.Items {
|
||||
status := api.ConditionFalse
|
||||
for _, c := range i.Conditions {
|
||||
if c.Type != api.ComponentHealthy {
|
||||
continue
|
||||
}
|
||||
fmt.Printf("Component: %s, Healthy: %s.\n", i.GetName(), c.Status)
|
||||
status = c.Status
|
||||
}
|
||||
if status != api.ConditionTrue {
|
||||
return fmt.Errorf("Component %s is not Healthy! Status: %s", i.GetName(), status)
|
||||
}
|
||||
fmt.Printf("Component: %s, Healthy: %s.\n", i.GetName(), c.Status)
|
||||
status = c.Status
|
||||
}
|
||||
if status != api.ConditionTrue {
|
||||
t.Fatalf("Component %s is not Healthy! Status: %s", i.GetName(), status)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := commonutil.RetryAfter(4, healthy, 1*time.Second); err != nil {
|
||||
t.Fatalf("Cluster is not healthy: %s", err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue