mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-04 07:15:05 -04:00
cli: add "Connecting" spinner state for "constellation init"
This commit is contained in:
parent
f2ce9518a3
commit
77d19eb896
3 changed files with 22 additions and 16 deletions
|
@ -67,6 +67,7 @@ func NewInitCmd() *cobra.Command {
|
||||||
type initCmd struct {
|
type initCmd struct {
|
||||||
log debugLog
|
log debugLog
|
||||||
merger configMerger
|
merger configMerger
|
||||||
|
spinner spinnerInterf
|
||||||
}
|
}
|
||||||
|
|
||||||
// runInitialize runs the initialize command.
|
// runInitialize runs the initialize command.
|
||||||
|
@ -90,13 +91,13 @@ func runInitialize(cmd *cobra.Command, args []string) error {
|
||||||
ctx, cancel := context.WithTimeout(cmd.Context(), time.Hour)
|
ctx, cancel := context.WithTimeout(cmd.Context(), time.Hour)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
cmd.SetContext(ctx)
|
cmd.SetContext(ctx)
|
||||||
i := &initCmd{log: log, merger: &kubeconfigMerger{log: log}}
|
i := &initCmd{log: log, spinner: spinner, merger: &kubeconfigMerger{log: log}}
|
||||||
return i.initialize(cmd, newDialer, fileHandler, license.NewClient(), spinner)
|
return i.initialize(cmd, newDialer, fileHandler, license.NewClient())
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize initializes a Constellation.
|
// initialize initializes a Constellation.
|
||||||
func (i *initCmd) initialize(cmd *cobra.Command, newDialer func(validator *cloudcmd.Validator) *dialer.Dialer,
|
func (i *initCmd) initialize(cmd *cobra.Command, newDialer func(validator *cloudcmd.Validator) *dialer.Dialer,
|
||||||
fileHandler file.Handler, quotaChecker license.QuotaChecker, spinner spinnerInterf,
|
fileHandler file.Handler, quotaChecker license.QuotaChecker,
|
||||||
) error {
|
) error {
|
||||||
flags, err := i.evalFlagArgs(cmd)
|
flags, err := i.evalFlagArgs(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -160,7 +161,8 @@ func (i *initCmd) initialize(cmd *cobra.Command, newDialer func(validator *cloud
|
||||||
clusterName := conf.Name + "-" + idFile.UID
|
clusterName := conf.Name + "-" + idFile.UID
|
||||||
i.log.Debugf("Setting cluster name to %s", clusterName)
|
i.log.Debugf("Setting cluster name to %s", clusterName)
|
||||||
|
|
||||||
spinner.Start("Initializing cluster ", false)
|
cmd.PrintErrln("Note: If you just created the cluster, it can take a few minutes to connect.")
|
||||||
|
i.spinner.Start("Connecting ", false)
|
||||||
req := &initproto.InitRequest{
|
req := &initproto.InitRequest{
|
||||||
KmsUri: masterSecret.EncodeToURI(),
|
KmsUri: masterSecret.EncodeToURI(),
|
||||||
StorageUri: uri.NoStoreURI,
|
StorageUri: uri.NoStoreURI,
|
||||||
|
@ -176,7 +178,7 @@ func (i *initCmd) initialize(cmd *cobra.Command, newDialer func(validator *cloud
|
||||||
}
|
}
|
||||||
i.log.Debugf("Sending initialization request")
|
i.log.Debugf("Sending initialization request")
|
||||||
resp, err := i.initCall(cmd.Context(), newDialer(validator), idFile.IP, req)
|
resp, err := i.initCall(cmd.Context(), newDialer(validator), idFile.IP, req)
|
||||||
spinner.Stop()
|
i.spinner.Stop()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var nonRetriable *nonRetriableError
|
var nonRetriable *nonRetriableError
|
||||||
if errors.As(err, &nonRetriable) {
|
if errors.As(err, &nonRetriable) {
|
||||||
|
@ -201,6 +203,7 @@ func (i *initCmd) initCall(ctx context.Context, dialer grpcDialer, ip string, re
|
||||||
endpoint: net.JoinHostPort(ip, strconv.Itoa(constants.BootstrapperPort)),
|
endpoint: net.JoinHostPort(ip, strconv.Itoa(constants.BootstrapperPort)),
|
||||||
req: req,
|
req: req,
|
||||||
log: i.log,
|
log: i.log,
|
||||||
|
spinner: i.spinner,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a wrapper function that allows logging any returned error from the retrier before checking if it's the expected retriable one.
|
// Create a wrapper function that allows logging any returned error from the retrier before checking if it's the expected retriable one.
|
||||||
|
@ -224,6 +227,7 @@ type initDoer struct {
|
||||||
req *initproto.InitRequest
|
req *initproto.InitRequest
|
||||||
resp *initproto.InitResponse
|
resp *initproto.InitResponse
|
||||||
log debugLog
|
log debugLog
|
||||||
|
spinner spinnerInterf
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *initDoer) Do(ctx context.Context) error {
|
func (d *initDoer) Do(ctx context.Context) error {
|
||||||
|
@ -239,8 +243,7 @@ func (d *initDoer) Do(ctx context.Context) error {
|
||||||
|
|
||||||
grpcStateLogCtx, grpcStateLogCancel := context.WithCancel(ctx)
|
grpcStateLogCtx, grpcStateLogCancel := context.WithCancel(ctx)
|
||||||
defer grpcStateLogCancel()
|
defer grpcStateLogCancel()
|
||||||
wg.Add(1)
|
d.handleGRPCStateChanges(grpcStateLogCtx, &wg, conn)
|
||||||
d.logGRPCStateChanges(grpcStateLogCtx, &wg, conn)
|
|
||||||
|
|
||||||
protoClient := initproto.NewAPIClient(conn)
|
protoClient := initproto.NewAPIClient(conn)
|
||||||
d.log.Debugf("Created protoClient")
|
d.log.Debugf("Created protoClient")
|
||||||
|
@ -252,7 +255,8 @@ func (d *initDoer) Do(ctx context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *initDoer) logGRPCStateChanges(ctx context.Context, wg *sync.WaitGroup, conn *grpc.ClientConn) {
|
func (d *initDoer) handleGRPCStateChanges(ctx context.Context, wg *sync.WaitGroup, conn *grpc.ClientConn) {
|
||||||
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
state := conn.GetState()
|
state := conn.GetState()
|
||||||
|
@ -262,6 +266,8 @@ func (d *initDoer) logGRPCStateChanges(ctx context.Context, wg *sync.WaitGroup,
|
||||||
}
|
}
|
||||||
if state == connectivity.Ready {
|
if state == connectivity.Ready {
|
||||||
d.log.Debugf("Connection ready")
|
d.log.Debugf("Connection ready")
|
||||||
|
d.spinner.Stop()
|
||||||
|
d.spinner.Start("Initializing cluster ", false)
|
||||||
} else {
|
} else {
|
||||||
d.log.Debugf("Connection state ended with %s", state)
|
d.log.Debugf("Connection state ended with %s", state)
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,8 +173,8 @@ func TestInitialize(t *testing.T) {
|
||||||
ctx, cancel := context.WithTimeout(ctx, 4*time.Second)
|
ctx, cancel := context.WithTimeout(ctx, 4*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
cmd.SetContext(ctx)
|
cmd.SetContext(ctx)
|
||||||
i := &initCmd{log: logger.NewTest(t)}
|
i := &initCmd{log: logger.NewTest(t), spinner: &nopSpinner{}}
|
||||||
err := i.initialize(cmd, newDialer, fileHandler, &stubLicenseClient{}, &nopSpinner{})
|
err := i.initialize(cmd, newDialer, fileHandler, &stubLicenseClient{})
|
||||||
|
|
||||||
if tc.wantErr {
|
if tc.wantErr {
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
|
@ -452,8 +452,8 @@ func TestAttestation(t *testing.T) {
|
||||||
defer cancel()
|
defer cancel()
|
||||||
cmd.SetContext(ctx)
|
cmd.SetContext(ctx)
|
||||||
|
|
||||||
i := &initCmd{log: logger.NewTest(t)}
|
i := &initCmd{log: logger.NewTest(t), spinner: &nopSpinner{}}
|
||||||
err := i.initialize(cmd, newDialer, fileHandler, &stubLicenseClient{}, &nopSpinner{})
|
err := i.initialize(cmd, newDialer, fileHandler, &stubLicenseClient{})
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
// make sure the error is actually a TLS handshake error
|
// make sure the error is actually a TLS handshake error
|
||||||
assert.Contains(err.Error(), "transport: authentication handshake failed")
|
assert.Contains(err.Error(), "transport: authentication handshake failed")
|
||||||
|
|
|
@ -265,8 +265,8 @@ func (m *miniUpCmd) initializeMiniCluster(cmd *cobra.Command, fileHandler file.H
|
||||||
}
|
}
|
||||||
m.log.Debugf("Created new logger")
|
m.log.Debugf("Created new logger")
|
||||||
defer log.Sync()
|
defer log.Sync()
|
||||||
i := &initCmd{log: log, merger: &kubeconfigMerger{log: log}}
|
i := &initCmd{log: log, merger: &kubeconfigMerger{log: log}, spinner: spinner}
|
||||||
if err := i.initialize(cmd, newDialer, fileHandler, license.NewClient(), spinner); err != nil {
|
if err := i.initialize(cmd, newDialer, fileHandler, license.NewClient()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
m.log.Debugf("Initialized mini cluster")
|
m.log.Debugf("Initialized mini cluster")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue