@@ -2,7 +2,7 @@ package wait
22
33import (
44 "context"
5- "fmt "
5+ "errors "
66 "time"
77
88 "github.com/stackitcloud/stackit-sdk-go/core/wait"
@@ -31,7 +31,17 @@ const (
3131 RUNTIMEERRORCODE_OBSERVABILITY_INSTANCE_NOT_FOUND = ske .RUNTIMEERRORCODE_SKE_OBSERVABILITY_INSTANCE_NOT_FOUND
3232)
3333
34- // CreateOrUpdateClusterWaitHandler will wait for cluster creation or update
34+ // CreateClusterWaitHandler will wait for cluster creation
35+ func CreateClusterWaitHandler (ctx context.Context , a ske.DefaultAPI , projectId , region , name string ) * wait.AsyncActionHandler [ske.Cluster ] {
36+ return CreateOrUpdateClusterWaitHandler (ctx , a , projectId , region , name )
37+ }
38+
39+ // UpdateClusterWaitHandler will wait for cluster update
40+ func UpdateClusterWaitHandler (ctx context.Context , a ske.DefaultAPI , projectId , region , name string ) * wait.AsyncActionHandler [ske.Cluster ] {
41+ return CreateOrUpdateClusterWaitHandler (ctx , a , projectId , region , name )
42+ }
43+
44+ // Deprecated: Will be removed after 2026-12-08. Use the CreateClusterWaitHandler or UpdateClusterWaitHandler instead.
3545func CreateOrUpdateClusterWaitHandler (ctx context.Context , a ske.DefaultAPI , projectId , region , name string ) * wait.AsyncActionHandler [ske.Cluster ] {
3646 handler := wait .New (func () (waitFinished bool , response * ske.Cluster , err error ) {
3747 s , err := a .GetCluster (ctx , projectId , region , name ).Execute ()
@@ -151,72 +161,73 @@ func TriggerClusterWakeupWaitHandler(ctx context.Context, a ske.DefaultAPI, proj
151161
152162// RotateCredentialsWaitHandler will wait for credentials rotation
153163func RotateCredentialsWaitHandler (ctx context.Context , a ske.DefaultAPI , projectId , region , clusterName string ) * wait.AsyncActionHandler [ske.Cluster ] {
154- handler := wait .New (func () (waitFinished bool , response * ske.Cluster , err error ) {
155- s , err := a .GetCluster (ctx , projectId , region , clusterName ).Execute ()
156- if err != nil {
157- return false , nil , err
158- }
159- state := * s .Status .Aggregated
160-
161- if state == ske .CLUSTERSTATUSSTATE_STATE_HEALTHY || state == ske .CLUSTERSTATUSSTATE_STATE_HIBERNATED {
162- return true , s , nil
163- }
164-
165- if state == ske .CLUSTERSTATUSSTATE_STATE_RECONCILING {
166- return false , nil , nil
167- }
168-
169- return true , s , fmt .Errorf ("unexpected state %s while waiting for cluster reconciliation" , state )
170- })
171-
164+ waitConfig := wait.WaiterHelper [ske.Cluster , ske.ClusterStatusState ]{
165+ FetchInstance : a .GetCluster (ctx , projectId , region , clusterName ).Execute ,
166+ GetState : func (s * ske.Cluster ) (ske.ClusterStatusState , error ) {
167+ if s == nil || s .Status == nil || s .Status .Aggregated == nil {
168+ return "" , errors .New ("empty response or status" )
169+ }
170+ return * s .Status .Aggregated , nil
171+ },
172+ ActiveState : []ske.ClusterStatusState {
173+ ske .CLUSTERSTATUSSTATE_STATE_HEALTHY ,
174+ ske .CLUSTERSTATUSSTATE_STATE_HIBERNATED ,
175+ },
176+ ErrorState : []ske.ClusterStatusState {
177+ ske .CLUSTERSTATUSSTATE_STATE_UNHEALTHY ,
178+ ske .CLUSTERSTATUSSTATE_STATE_DELETING ,
179+ ske .CLUSTERSTATUSSTATE_STATE_HIBERNATING ,
180+ ske .CLUSTERSTATUSSTATE_STATE_WAKINGUP ,
181+ },
182+ }
183+
184+ handler := wait .New (waitConfig .Wait ())
172185 handler .SetTimeout (10 * time .Minute )
173186 return handler
174187}
175188
176189// StartCredentialsRotationWaitHandler will wait for credentials rotation
177190func StartCredentialsRotationWaitHandler (ctx context.Context , a ske.DefaultAPI , projectId , region , clusterName string ) * wait.AsyncActionHandler [ske.Cluster ] {
178- handler := wait .New (func () (waitFinished bool , response * ske.Cluster , err error ) {
179- s , err := a .GetCluster (ctx , projectId , region , clusterName ).Execute ()
180- if err != nil {
181- return false , nil , err
182- }
183- state := * s .Status .CredentialsRotation .Phase
184-
185- if state == ske .CREDENTIALSROTATIONSTATEPHASE_PREPARED {
186- return true , s , nil
187- }
188-
189- if state == ske .CREDENTIALSROTATIONSTATEPHASE_PREPARING {
190- return false , nil , nil
191- }
192-
193- return true , s , fmt .Errorf ("unexpected status %s while waiting for cluster credentials rotation to be prepared" , state )
194- })
195-
191+ waitConfig := wait.WaiterHelper [ske.Cluster , ske.CredentialsRotationStatePhase ]{
192+ FetchInstance : a .GetCluster (ctx , projectId , region , clusterName ).Execute ,
193+ GetState : func (s * ske.Cluster ) (ske.CredentialsRotationStatePhase , error ) {
194+ if s == nil || s .Status == nil || s .Status .CredentialsRotation == nil || s .Status .CredentialsRotation .Phase == nil {
195+ return "" , errors .New ("empty response or credentials rotation phase" )
196+ }
197+ return * s .Status .CredentialsRotation .Phase , nil
198+ },
199+ ActiveState : []ske.CredentialsRotationStatePhase {ske .CREDENTIALSROTATIONSTATEPHASE_PREPARED },
200+ ErrorState : []ske.CredentialsRotationStatePhase {
201+ ske .CREDENTIALSROTATIONSTATEPHASE_NEVER ,
202+ ske .CREDENTIALSROTATIONSTATEPHASE_COMPLETING ,
203+ ske .CREDENTIALSROTATIONSTATEPHASE_COMPLETED ,
204+ },
205+ }
206+
207+ handler := wait .New (waitConfig .Wait ())
196208 handler .SetTimeout (45 * time .Minute )
197209 return handler
198210}
199211
200212// CompleteCredentialsRotationWaitHandler will wait for credentials rotation
201213func CompleteCredentialsRotationWaitHandler (ctx context.Context , a ske.DefaultAPI , projectId , region , clusterName string ) * wait.AsyncActionHandler [ske.Cluster ] {
202- handler := wait .New (func () (waitFinished bool , response * ske.Cluster , err error ) {
203- s , err := a .GetCluster (ctx , projectId , region , clusterName ).Execute ()
204- if err != nil {
205- return false , nil , err
206- }
207- state := * s .Status .CredentialsRotation .Phase
208-
209- if state == ske .CREDENTIALSROTATIONSTATEPHASE_COMPLETED {
210- return true , s , nil
211- }
212-
213- if state == ske .CREDENTIALSROTATIONSTATEPHASE_COMPLETING {
214- return false , nil , nil
215- }
216-
217- return true , s , fmt .Errorf ("unexpected status %s while waiting for cluster credentials rotation to be completed" , state )
218- })
219-
214+ waitConfig := wait.WaiterHelper [ske.Cluster , ske.CredentialsRotationStatePhase ]{
215+ FetchInstance : a .GetCluster (ctx , projectId , region , clusterName ).Execute ,
216+ GetState : func (s * ske.Cluster ) (ske.CredentialsRotationStatePhase , error ) {
217+ if s == nil || s .Status == nil || s .Status .CredentialsRotation == nil || s .Status .CredentialsRotation .Phase == nil {
218+ return "" , errors .New ("empty response or credentials rotation phase" )
219+ }
220+ return * s .Status .CredentialsRotation .Phase , nil
221+ },
222+ ActiveState : []ske.CredentialsRotationStatePhase {ske .CREDENTIALSROTATIONSTATEPHASE_COMPLETED },
223+ ErrorState : []ske.CredentialsRotationStatePhase {
224+ ske .CREDENTIALSROTATIONSTATEPHASE_NEVER ,
225+ ske .CREDENTIALSROTATIONSTATEPHASE_PREPARING ,
226+ ske .CREDENTIALSROTATIONSTATEPHASE_PREPARED ,
227+ },
228+ }
229+
230+ handler := wait .New (waitConfig .Wait ())
220231 handler .SetTimeout (45 * time .Minute )
221232 return handler
222233}
0 commit comments