@@ -47,3 +47,60 @@ func (s *API) WaitForCluster(req *WaitForClusterRequest) (*Cluster, error) {
47
47
}
48
48
return cluster .(* Cluster ), nil
49
49
}
50
+
51
+ func (s * API ) getNodesWhenReady (req * ListNodesRequest , expectedCount uint32 ) (interface {}, bool , error ) {
52
+ res , err := s .ListNodes (req , scw .WithAllPages ())
53
+ if err != nil {
54
+ return nil , false , err
55
+ }
56
+
57
+ // first check that we have the right nodes count
58
+ if res .TotalCount != expectedCount {
59
+ return nil , false , nil
60
+ }
61
+
62
+ // then check that each node has Ready status
63
+ for _ , node := range res .Nodes {
64
+ if node .Status != NodeStatusReady {
65
+ return nil , false , nil
66
+ }
67
+ }
68
+
69
+ return res , true , nil
70
+ }
71
+
72
+ // WaitForPoolNodesReadyRequest is used by WaitForPoolNodesReady method.
73
+ type WaitForPoolNodesReadyRequest struct {
74
+ PoolID string
75
+ Timeout time.Duration
76
+ }
77
+
78
+ // WaitForPoolNodesReady waits for the nodes of a pool to be ready
79
+ func (s * API ) WaitForPoolNodesReady (req * WaitForPoolNodesReadyRequest ) error {
80
+ pool , err := s .GetPool (& GetPoolRequest {
81
+ PoolID : req .PoolID ,
82
+ })
83
+ if err != nil {
84
+ return err
85
+ }
86
+
87
+ r := & ListNodesRequest {
88
+ ClusterID : pool .ClusterID ,
89
+ PoolID : & req .PoolID ,
90
+ }
91
+
92
+ _ , err = async .WaitSync (& async.WaitSyncConfig {
93
+ Get : func () (interface {}, bool , error ) {
94
+ _ , ok , err := s .getNodesWhenReady (r , pool .Size )
95
+ if err != nil {
96
+ return nil , ok , err
97
+ }
98
+
99
+ return nil , ok , nil
100
+ },
101
+ Timeout : req .Timeout ,
102
+ IntervalStrategy : async .LinearIntervalStrategy (5 * time .Second ),
103
+ })
104
+
105
+ return err
106
+ }
0 commit comments