From d34e87b378efb24622bad39e694a43c397d971df Mon Sep 17 00:00:00 2001 From: Roman Tkachenko Date: Fri, 25 Sep 2020 15:48:00 -0700 Subject: [PATCH] (6.1) Wait for operator (#2151) --- e | 2 +- lib/install/process.go | 5 ----- lib/localenv/remoteenv.go | 18 ++++++++++++++++++ lib/ops/opsclient/opsclient.go | 9 +++++++++ tool/gravity/cli/install.go | 4 ++++ 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/e b/e index 47876766d5..5218997dc5 160000 --- a/e +++ b/e @@ -1 +1 @@ -Subproject commit 47876766d554022b92e3eb73e5b9a1c575ed532c +Subproject commit 5218997dc5764702840b086fef29ee4f62a7128c diff --git a/lib/install/process.go b/lib/install/process.go index f4bbb53ba1..971bc9100a 100644 --- a/lib/install/process.go +++ b/lib/install/process.go @@ -50,11 +50,6 @@ func InitProcess(ctx context.Context, gravityConfig processconfig.Config, newPro if err != nil { return nil, trace.Wrap(err) } - err = process.WaitForServiceStarted(ctx, p) - if err != nil { - shutdown(p) - return nil, trace.Wrap(err) - } return p, nil } diff --git a/lib/localenv/remoteenv.go b/lib/localenv/remoteenv.go index 6155e0ff6a..51f4653bcb 100644 --- a/lib/localenv/remoteenv.go +++ b/lib/localenv/remoteenv.go @@ -17,11 +17,13 @@ limitations under the License. package localenv import ( + "context" "fmt" "os" "path/filepath" "strconv" "strings" + "time" "github.com/gravitational/gravity/lib/app" "github.com/gravitational/gravity/lib/app/client" @@ -165,6 +167,22 @@ func (w *RemoteEnvironment) LoginWizard(addr, token string) (entry *storage.Logi }) } +// WaitForOperator blocks until the configured operator becomes available or context expires. +func (w *RemoteEnvironment) WaitForOperator(ctx context.Context) error { + err := utils.RetryFor(ctx, time.Minute, func() error { + if err := w.Operator.Ping(ctx); err != nil { + w.Infof("Operator isn't available yet: %v.", err) + return trace.Wrap(err) + } + return nil + }) + if err != nil { + return trace.Wrap(err) + } + w.Info("Operator is available.") + return nil +} + func (w *RemoteEnvironment) login(entry storage.LoginEntry) (*storage.LoginEntry, error) { err := w.withBackend(func(b storage.Backend) error { _, err := b.UpsertLoginEntry(entry) diff --git a/lib/ops/opsclient/opsclient.go b/lib/ops/opsclient/opsclient.go index 6ef3beae05..a608848f49 100644 --- a/lib/ops/opsclient/opsclient.go +++ b/lib/ops/opsclient/opsclient.go @@ -109,6 +109,15 @@ func WithLocalDialer(dialer httplib.Dialer) ClientParam { // ClientParam defines the API to override configuration on client c type ClientParam func(c *Client) error +// Ping calls the operator service status endpoint. +func (c *Client) Ping(ctx context.Context) error { + _, err := c.Get(c.Endpoint("status"), url.Values{}) + if err != nil { + return trace.Wrap(err) + } + return nil +} + func (c *Client) GetAccount(accountID string) (*ops.Account, error) { out, err := c.Get(c.Endpoint("accounts", accountID), url.Values{}) if err != nil { diff --git a/tool/gravity/cli/install.go b/tool/gravity/cli/install.go index bf6928beff..f6e6fa6131 100644 --- a/tool/gravity/cli/install.go +++ b/tool/gravity/cli/install.go @@ -141,6 +141,10 @@ func newInstallerConfig(ctx context.Context, env *localenv.LocalEnvironment, con if err != nil { return nil, trace.Wrap(err) } + err = wizard.WaitForOperator(ctx) + if err != nil { + return nil, trace.Wrap(err) + } installerConfig, err := config.NewInstallerConfig(env, wizard, process) if err != nil { return nil, trace.Wrap(err)