From: Tom Clegg Date: Tue, 28 Jan 2020 16:03:08 +0000 (-0500) Subject: 15954: Write controller URL to stdout when cluster is ready. X-Git-Tag: 2.1.0~273^2~74 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/071208be8ec20519c8fb05fe7ac0563e55e55b5b?ds=sidebyside 15954: Write controller URL to stdout when cluster is ready. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- diff --git a/lib/boot/cmd.go b/lib/boot/cmd.go index 992c7c6e51..cfa6b42581 100644 --- a/lib/boot/cmd.go +++ b/lib/boot/cmd.go @@ -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() diff --git a/sdk/go/health/aggregator.go b/sdk/go/health/aggregator.go index 90823b38b0..a0284e8f24 100644 --- a/sdk/go/health/aggregator.go +++ b/sdk/go/health/aggregator.go @@ -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),