Skip to content

Commit f74c956

Browse files
authored
Merge pull request #6625 from priyawadhwa/fail-fast
Fail fast if waiting for SSH to be available
2 parents be33c7e + 59abf60 commit f74c956

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

pkg/minikube/machine/start.go

+30-4
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,9 @@ func createHost(api libmachine.API, cfg config.MachineConfig) (*host.Host, error
134134

135135
cstart := time.Now()
136136
glog.Infof("libmachine.API.Create for %q (driver=%q)", cfg.Name, cfg.Driver)
137-
if err := api.Create(h); err != nil {
138-
// Wait for all the logs to reach the client
139-
time.Sleep(2 * time.Second)
140-
return nil, errors.Wrap(err, "create")
137+
// Allow two minutes to create host before failing fast
138+
if err := timedCreateHost(h, api, 2*time.Minute); err != nil {
139+
return nil, errors.Wrap(err, "creating host")
141140
}
142141
glog.Infof("libmachine.API.Create for %q took %s", cfg.Name, time.Since(cstart))
143142

@@ -151,6 +150,33 @@ func createHost(api libmachine.API, cfg config.MachineConfig) (*host.Host, error
151150
return h, nil
152151
}
153152

153+
func timedCreateHost(h *host.Host, api libmachine.API, t time.Duration) error {
154+
timeout := make(chan bool, 1)
155+
go func() {
156+
time.Sleep(t)
157+
timeout <- true
158+
}()
159+
160+
createFinished := make(chan bool, 1)
161+
var err error
162+
go func() {
163+
err = api.Create(h)
164+
createFinished <- true
165+
}()
166+
167+
select {
168+
case <-createFinished:
169+
if err != nil {
170+
// Wait for all the logs to reach the client
171+
time.Sleep(2 * time.Second)
172+
return errors.Wrap(err, "create")
173+
}
174+
return nil
175+
case <-timeout:
176+
return fmt.Errorf("create host timed out in %f seconds", t.Seconds())
177+
}
178+
}
179+
154180
// postStart are functions shared between startHost and fixHost
155181
func postStartSetup(h *host.Host, mc config.MachineConfig) error {
156182
glog.Infof("post-start starting for %q (driver=%q)", h.Name, h.DriverName)

0 commit comments

Comments
 (0)