Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
(6.1) Wait for operator (#2151)
Browse files Browse the repository at this point in the history
  • Loading branch information
r0mant authored Sep 25, 2020
1 parent 277c269 commit d34e87b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion e
Submodule e updated from 478767 to 521899
5 changes: 0 additions & 5 deletions lib/install/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
18 changes: 18 additions & 0 deletions lib/localenv/remoteenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions lib/ops/opsclient/opsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions tool/gravity/cli/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d34e87b

Please sign in to comment.