From 8fc787bc20695d83329f7276c7393e0149ab63c2 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Thu, 13 Feb 2020 14:03:31 -0800 Subject: [PATCH 1/2] Fail fast if waiting for SSH to be available Integration tests were running long because we'd wait up to 22 minutes for SSH to succeed while creating the host. This commit introduces a two minute timer on creating the host. On my Macbook Pro with the docker driver, creating the host takes 5 seconds, so 2 minutes should be more than enough time. Refer to #6608 --- pkg/minikube/cluster/start.go | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/pkg/minikube/cluster/start.go b/pkg/minikube/cluster/start.go index c7669e99661b..ddd1e3a9524f 100644 --- a/pkg/minikube/cluster/start.go +++ b/pkg/minikube/cluster/start.go @@ -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.VMDriver) - 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)) @@ -151,6 +150,32 @@ 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 { + 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) From 59abf60d7ee3dc92f5686e2f21431242926f2439 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Thu, 13 Feb 2020 16:30:38 -0800 Subject: [PATCH 2/2] reinsert comment --- pkg/minikube/machine/start.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/minikube/machine/start.go b/pkg/minikube/machine/start.go index 3c813f931c5c..020c09cbb9b6 100644 --- a/pkg/minikube/machine/start.go +++ b/pkg/minikube/machine/start.go @@ -167,6 +167,7 @@ func timedCreateHost(h *host.Host, api libmachine.API, t time.Duration) error { 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") }