@@ -37,6 +37,10 @@ import (
3737
3838const (
3939 CloudsYamlFile = "/etc/ibmcloud/clouds.yaml"
40+
41+ // TODO: make the timeout to be configurable
42+ WaitReadyRetryInterval = 5 * time .Second
43+ WaitReadyTimeout = 600 * time .Second
4044)
4145
4246type GuestService struct {
@@ -74,28 +78,33 @@ func NewInstanceServiceFromMachine(kubeClient kubernetes.Interface, machine *clu
7478 return NewGuestService (sess ), nil
7579}
7680
77- func (gs * GuestService ) waitGuestReady (Id int ) {
81+ func (gs * GuestService ) waitGuestReady (Id int ) error {
7882 // Wait for transactions to finish
7983 klog .Info ("Waiting for transactions to complete before destroying." )
8084 s := services .GetVirtualGuestService (gs .sess ).Id (Id )
8185
8286 // Delay to allow transactions to be registered
83- time .Sleep (5 * time . Second )
87+ time .Sleep (WaitReadyRetryInterval )
8488
8589 // TODO: make it V(2) after initial development work done if necessary
8690 //if klog.V(2) {
8791 // Enable debug to show messages from IBM Cloud during node provision
8892 s .Session .Debug = true
8993 //}
94+ sum := WaitReadyRetryInterval
9095 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+ }
94102 transactions , _ = s .GetActiveTransactions ()
95103 }
96104 s .Session .Debug = false
97105
98- klog .Info ("Waiting for trasactions done." )
106+ klog .Info ("Waiting for transactions done." )
107+ return nil
99108}
100109
101110func (gs * GuestService ) CreateGuest (clusterName , hostName string , machineSpec * ibmcloudv1.IbmcloudMachineProviderSpec , userScript string ) {
@@ -146,7 +155,11 @@ func (gs *GuestService) CreateGuest(clusterName, hostName string, machineSpec *i
146155 klog .Infof ("New Virtual Guest created with ID %d in domain %q" , * vGuest .Id , * vGuest .Domain )
147156
148157 // 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+ }
150163}
151164
152165func (gs * GuestService ) DeleteGuest (Id int ) error {
0 commit comments