15954: Write controller URL to stdout when cluster is ready.
authorTom Clegg <tom@tomclegg.ca>
Tue, 28 Jan 2020 16:03:08 +0000 (11:03 -0500)
committerTom Clegg <tom@tomclegg.ca>
Tue, 28 Jan 2020 16:03:08 +0000 (11:03 -0500)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@tomclegg.ca>

lib/boot/cmd.go
sdk/go/health/aggregator.go

index 992c7c6e510f669fc5d884c6fd3a1af962dae9a8..cfa6b425811aa2bac5a3864e11eac37e728df0e3 100644 (file)
@@ -29,6 +29,7 @@ import (
        "git.arvados.org/arvados.git/lib/dispatchcloud"
        "git.arvados.org/arvados.git/sdk/go/arvados"
        "git.arvados.org/arvados.git/sdk/go/ctxlog"
+       "git.arvados.org/arvados.git/sdk/go/health"
        "github.com/sirupsen/logrus"
 )
 
@@ -196,11 +197,37 @@ func (boot *bootCommand) RunCommand(prog string, args []string, stdin io.Reader,
                        }
                }()
        }
+       if boot.waitUntilReady(ctx) {
+               fmt.Fprintln(stdout, boot.cluster.Services.Controller.ExternalURL)
+       }
        <-ctx.Done()
        wg.Wait()
        return 0
 }
 
+func (boot *bootCommand) waitUntilReady(ctx context.Context) bool {
+       agg := health.Aggregator{Cluster: boot.cluster}
+       for waiting := true; waiting; {
+               time.Sleep(time.Second)
+               if ctx.Err() != nil {
+                       return false
+               }
+               resp := agg.ClusterHealth()
+               // The overall health check (resp.Health=="OK") might
+               // never pass due to missing components (like
+               // arvados-dispatch-cloud in a test cluster), so
+               // instead we wait for all configured components to
+               // pass.
+               waiting = false
+               for _, check := range resp.Checks {
+                       if check.Health != "OK" {
+                               waiting = true
+                       }
+               }
+       }
+       return true
+}
+
 func (boot *bootCommand) installGoProgram(ctx context.Context, srcpath string) error {
        boot.goMutex.Lock()
        defer boot.goMutex.Unlock()
index 90823b38b015351ce3c8b24926de4c98f894efed..a0284e8f247a60f8d2fd57b752f37a800d54c222 100644 (file)
@@ -106,6 +106,7 @@ type ServiceHealth struct {
 }
 
 func (agg *Aggregator) ClusterHealth() ClusterHealthResponse {
+       agg.setupOnce.Do(agg.setup)
        resp := ClusterHealthResponse{
                Health:   "OK",
                Checks:   make(map[string]CheckResult),