Skip to content

Commit

Permalink
Merge pull request #6625 from priyawadhwa/fail-fast
Browse files Browse the repository at this point in the history
Fail fast if waiting for SSH to be available
  • Loading branch information
medyagh authored Feb 14, 2020
2 parents be33c7e + 59abf60 commit f74c956
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions pkg/minikube/machine/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,9 @@ func createHost(api libmachine.API, cfg config.MachineConfig) (*host.Host, error

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

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

func timedCreateHost(h *host.Host, api libmachine.API, t time.Duration) error {
timeout := make(chan bool, 1)
go func() {
time.Sleep(t)
timeout <- true
}()

createFinished := make(chan bool, 1)
var err error
go func() {
err = api.Create(h)
createFinished <- true
}()

select {
case <-createFinished:
if err != nil {
// Wait for all the logs to reach the client
time.Sleep(2 * time.Second)
return errors.Wrap(err, "create")
}
return nil
case <-timeout:
return fmt.Errorf("create host timed out in %f seconds", t.Seconds())
}
}

// postStart are functions shared between startHost and fixHost
func postStartSetup(h *host.Host, mc config.MachineConfig) error {
glog.Infof("post-start starting for %q (driver=%q)", h.Name, h.DriverName)
Expand Down

0 comments on commit f74c956

Please sign in to comment.