forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 1
/
wait.go
33 lines (29 loc) · 891 Bytes
/
wait.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package compose
import (
"time"
"github.com/pkg/errors"
"github.com/rancher/norman/clientbase"
managementClient "github.com/rancher/types/client/management/v3"
)
var (
// WaitCondition is a set of function that can be customized to wait for a resource
WaitCondition = map[string]func(baseClient *clientbase.APIBaseClient, id, schemaType string) error{}
)
func WaitCluster(baseClient *clientbase.APIBaseClient, id, schemaType string) error {
start := time.Now()
for {
respObj := managementClient.Cluster{}
if err := baseClient.ByID(schemaType, id, &respObj); err != nil {
return err
}
for _, cond := range respObj.Conditions {
if cond.Type == "Ready" && cond.Status == "True" {
return nil
}
}
time.Sleep(time.Second * 10)
if time.Now().After(start.Add(time.Minute * 30)) {
return errors.Errorf("Timeout wait for cluster %s to be ready", id)
}
}
}