@@ -37,6 +37,10 @@ import (
37
37
38
38
const (
39
39
CloudsYamlFile = "/etc/ibmcloud/clouds.yaml"
40
+
41
+ // TODO: make the timeout to be configurable
42
+ WaitReadyRetryInterval = 5 * time .Second
43
+ WaitReadyTimeout = 600 * time .Second
40
44
)
41
45
42
46
type GuestService struct {
@@ -74,28 +78,33 @@ func NewInstanceServiceFromMachine(kubeClient kubernetes.Interface, machine *clu
74
78
return NewGuestService (sess ), nil
75
79
}
76
80
77
- func (gs * GuestService ) waitGuestReady (Id int ) {
81
+ func (gs * GuestService ) waitGuestReady (Id int ) error {
78
82
// Wait for transactions to finish
79
83
klog .Info ("Waiting for transactions to complete before destroying." )
80
84
s := services .GetVirtualGuestService (gs .sess ).Id (Id )
81
85
82
86
// Delay to allow transactions to be registered
83
- time .Sleep (5 * time . Second )
87
+ time .Sleep (WaitReadyRetryInterval )
84
88
85
89
// TODO: make it V(2) after initial development work done if necessary
86
90
//if klog.V(2) {
87
91
// Enable debug to show messages from IBM Cloud during node provision
88
92
s .Session .Debug = true
89
93
//}
94
+ sum := WaitReadyRetryInterval
90
95
for transactions , _ := s .GetActiveTransactions (); len (transactions ) > 0 ; {
91
- // TODO(gyliu513) make it configurable or use the notification mechanism to optimize
92
- // the process instead of hardcoded waiting.
93
- time .Sleep (5 * time .Second )
96
+ time .Sleep (WaitReadyRetryInterval )
97
+ sum += WaitReadyRetryInterval
98
+ if sum > WaitReadyTimeout {
99
+ // Now the guest failed to reach timeout
100
+ return fmt .Errorf ("Waiting for guest %d ready time out" , Id )
101
+ }
94
102
transactions , _ = s .GetActiveTransactions ()
95
103
}
96
104
s .Session .Debug = false
97
105
98
- klog .Info ("Waiting for trasactions done." )
106
+ klog .Info ("Waiting for transactions done." )
107
+ return nil
99
108
}
100
109
101
110
func (gs * GuestService ) CreateGuest (clusterName , hostName string , machineSpec * ibmcloudv1.IbmcloudMachineProviderSpec , userScript string ) {
@@ -146,7 +155,11 @@ func (gs *GuestService) CreateGuest(clusterName, hostName string, machineSpec *i
146
155
klog .Infof ("New Virtual Guest created with ID %d in domain %q" , * vGuest .Id , * vGuest .Domain )
147
156
148
157
// Wait for transactions to finish
149
- gs .waitGuestReady (* vGuest .Id )
158
+ err = gs .waitGuestReady (* vGuest .Id )
159
+ if err != nil {
160
+ klog .Errorf ("Failed to wait guest ready: %v" , err )
161
+ return
162
+ }
150
163
}
151
164
152
165
func (gs * GuestService ) DeleteGuest (Id int ) error {
0 commit comments