Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions pkg/cmd/register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,12 @@ func runRegisterSteps(ctx context.Context, t *terminal.Terminal, s RegisterStore
return nil, fmt.Errorf("node registered but failed to save locally: %w", err)
}

runSetup(node, t, deps)
err = runSetup(node, deps)
stopSpinner()
if err != nil {
return nil, fmt.Errorf("setup command failed: %w", err)
}

t.Vprintf("%s Node registered.\n", t.Green(" ✓"))
t.Vprintf("%s Registration complete.\n", t.Green(" ✓"))
return reg, nil
Expand Down Expand Up @@ -421,19 +425,18 @@ func netbirdManagementConnected(statusOutput string) bool {
return false
}

func runSetup(node *nodev1.ExternalNode, t *terminal.Terminal, deps registerDeps) {
func runSetup(node *nodev1.ExternalNode, deps registerDeps) error {
ci := node.GetConnectivityInfo()
if ci == nil || ci.GetRegistrationCommand() == "" {
t.Vprintf(" %s\n", t.Yellow("Warning: Brev tunnel setup failed, please try again."))
} else {
if err := deps.setupRunner.RunSetup(ci.GetRegistrationCommand()); err != nil {
t.Vprintf(" Warning: setup command failed: %v\n", err)
} else {
// netbird up reconfigures network routes; give them a moment
// to settle before making further RPC calls.
time.Sleep(2 * time.Second)
Comment on lines -432 to -434
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is solved by the backoff during ssh

}
return fmt.Errorf("brev tunnel setup failed, please try again")
}

err := deps.setupRunner.RunSetup(ci.GetRegistrationCommand())
if err != nil {
return fmt.Errorf("setup command failed: %w", err)
}

return nil
}

// grantSSHAccessWithPort enables SSH: shows confirm table, uses port or prompts if port is 0, then allocates port and grants access.
Expand Down
10 changes: 8 additions & 2 deletions pkg/cmd/register/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ func Test_runRegister_WithOrgFlag(t *testing.T) {
OrganizationId: req.GetOrganizationId(),
Name: req.GetName(),
DeviceId: req.GetDeviceId(),
ConnectivityInfo: &nodev1.ConnectivityInfo{
RegistrationCommand: "netbird up --key abc",
},
},
}, nil
},
Expand Down Expand Up @@ -572,8 +575,8 @@ func Test_runRegister_NoSetupCommand(t *testing.T) {
term := terminal.New()
opts := registerOpts{interactive: false, name: "my-spark", orgName: "TestOrg", sshPort: 22}
err := runRegister(context.Background(), term, store, opts, deps)
if err != nil {
t.Fatalf("runRegister failed: %v", err)
if err == nil {
t.Fatal("expected error when no setup command")
}

if setupRunner.called {
Expand Down Expand Up @@ -803,6 +806,9 @@ func Test_runRegister_NameValidation(t *testing.T) {
OrganizationId: "org_123",
Name: req.GetName(),
DeviceId: req.GetDeviceId(),
ConnectivityInfo: &nodev1.ConnectivityInfo{
RegistrationCommand: "netbird up --key abc",
},
},
}, nil
},
Expand Down
Loading