Skip to content

Commit 4bba5e8

Browse files
authored
Merge pull request #68 from maleck13/service-provision-timout
add a timeout and handle it gracefully
2 parents 070d8c2 + 6f2edc4 commit 4bba5e8

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

pkg/cmd/services.go

+31-22
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import (
3636

3737
"sort"
3838

39+
"time"
40+
3941
"github.com/aerogear/mobile-cli/pkg/cmd/output"
4042
"k8s.io/apimachinery/pkg/watch"
4143
)
@@ -362,35 +364,42 @@ Run the "mobile get services" command from this tool to see which services are a
362364
if noWait {
363365
return nil
364366
}
365-
w, err := sc.scClient.ServicecatalogV1beta1().ServiceInstances(ns).Watch(metav1.ListOptions{})
367+
timeout := int64(10 * time.Minute) // ten minutes
368+
w, err := sc.scClient.ServicecatalogV1beta1().ServiceInstances(ns).Watch(metav1.ListOptions{TimeoutSeconds: &timeout})
366369
if err != nil {
367370
return errors.WithStack(err)
368371
}
369-
for u := range w.ResultChan() {
370-
o := u.Object.(*v1beta1.ServiceInstance)
371-
if o.Labels["serviceName"] != serviceName {
372-
continue
373-
}
374-
switch u.Type {
375-
case watch.Error:
376-
w.Stop()
377-
return errors.New("unexpected error watching ServiceInstance " + err.Error())
378-
case watch.Modified:
379-
for _, c := range o.Status.Conditions {
380-
fmt.Println("status: " + c.Message)
381-
if c.Type == "Ready" && c.Status == "True" {
382-
w.Stop()
383-
}
384-
385-
if c.Type == "Failed" {
386-
w.Stop()
387-
return errors.New("Failed to provision " + extServiceClass.ServiceName + ". " + c.Message)
372+
for {
373+
select {
374+
case msg, ok := <-w.ResultChan():
375+
if !ok {
376+
fmt.Println("Timedout waiting. It seems to be taking a long time for the service to provision. Your service may still be provisioning.")
377+
return nil
378+
}
379+
o := msg.Object.(*v1beta1.ServiceInstance)
380+
if o.Labels["serviceName"] != serviceName {
381+
continue
382+
}
383+
switch msg.Type {
384+
case watch.Error:
385+
w.Stop()
386+
return errors.New("unexpected error watching ServiceInstance " + err.Error())
387+
case watch.Modified:
388+
for _, c := range o.Status.Conditions {
389+
fmt.Println("status: " + c.Message)
390+
if c.Type == "Ready" && c.Status == "True" {
391+
w.Stop()
392+
return nil
393+
}
394+
395+
if c.Type == "Failed" {
396+
w.Stop()
397+
return errors.New("Failed to provision " + extServiceClass.ServiceName + ". " + c.Message)
398+
}
388399
}
389400
}
390401
}
391402
}
392-
393-
return nil
394403
},
395404
}
396405
cmd.PersistentFlags().Bool("no-wait", false, "--no-wait will cause the command to exit immediately after a successful response instead of waiting until the service is fully provisioned")

0 commit comments

Comments
 (0)