@@ -3,7 +3,6 @@ package wait
33import (
44 "context"
55 "fmt"
6- "strings"
76 "time"
87
98 "github.com/stackitcloud/stackit-sdk-go/core/wait"
@@ -34,6 +33,8 @@ const (
3433 CredentialsRotationStateCompleted = "COMPLETED"
3534 // Deprecated: InvalidArgusInstanceErrorCode is deprecated and will be removed after 14th November 2025. Use [ske.RUNTIMEERRORCODE_OBSERVABILITY_INSTANCE_NOT_FOUND] instead.
3635 InvalidArgusInstanceErrorCode = "SKE_ARGUS_INSTANCE_NOT_FOUND"
36+
37+ ClusterNoValidHostFound = "SKE_NODE_NO_VALID_HOST_FOUND"
3738)
3839
3940type APIClientClusterInterface interface {
@@ -43,6 +44,8 @@ type APIClientClusterInterface interface {
4344
4445// CreateOrUpdateClusterWaitHandler will wait for cluster creation or update
4546func CreateOrUpdateClusterWaitHandler (ctx context.Context , a APIClientClusterInterface , projectId , region , name string ) * wait.AsyncActionHandler [ske.Cluster ] {
47+ startTime := time .Now ()
48+
4649 handler := wait .New (func () (waitFinished bool , response * ske.Cluster , err error ) {
4750 s , err := a .GetClusterExecute (ctx , projectId , region , name )
4851 if err != nil {
@@ -57,15 +60,25 @@ func CreateOrUpdateClusterWaitHandler(ctx context.Context, a APIClientClusterInt
5760 return true , s , nil
5861 }
5962
60- if s .Status .Errors != nil && len (* s .Status .Errors ) > 0 {
61- var errMsgs []string
63+ // If cluster is UNSPECIFIED or UNHEALTHY and has structured errors, exit early
64+ if (state == ske .CLUSTERSTATUSSTATE_UNSPECIFIED || state == ske .CLUSTERSTATUSSTATE_UNHEALTHY ) &&
65+ s .Status .Errors != nil && len (* s .Status .Errors ) > 0 {
6266 for _ , clusterError := range * s .Status .Errors {
63- if clusterError .Message != nil && clusterError .Code != nil {
64- errMsgs = append ( errMsgs , fmt . Sprintf ( "%s %s" , * clusterError . Code , * clusterError . Message ))
67+ if clusterError .Code != nil && clusterError .Message != nil {
68+ return true , s , nil
6569 }
6670 }
71+ }
6772
68- return true , s , fmt .Errorf ("%s" , strings .Join (errMsgs , "\n " ))
73+ // Waiter has been running more than 15 minutes and cluster is still in CREATING or RECONCILING with errors
74+ if time .Since (startTime ) > 15 * time .Minute &&
75+ (state == ske .CLUSTERSTATUSSTATE_CREATING || state == ske .CLUSTERSTATUSSTATE_RECONCILING ) &&
76+ s .Status .Errors != nil && len (* s .Status .Errors ) > 0 {
77+ for _ , clusterError := range * s .Status .Errors {
78+ if clusterError .Code != nil && clusterError .Message != nil {
79+ return true , s , nil
80+ }
81+ }
6982 }
7083
7184 if state == ske .CLUSTERSTATUSSTATE_HEALTHY || state == ske .CLUSTERSTATUSSTATE_HIBERNATED {
0 commit comments