8000 chore: switch to new wgtunnel via tunnelsdk by deansheather · Pull Request #6489 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

chore: switch to new wgtunnel via tunnelsdk #6489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: merge main and impl tunnel
  • Loading branch information
deansheather committed Mar 9, 2023
commit 85edde2069f22a2dc9e631a60e0fb7c74267fbf2
20 changes: 14 additions & 6 deletions cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,19 +535,27 @@ flags, and YAML configuration. The precedence is as follows:

// If the access URL is empty, we attempt to run a reverse-proxy
// tunnel to make the initial setup really simple.
var tunnel *tunnelsdk.Tunnel
if cfg.AccessURL.Value == "" {
var (
tunnel *tunnelsdk.Tunnel
tunnelDone <-chan struct{} = make(chan struct{}, 1)
)
if cfg.AccessURL.String() == "" {
cmd.Printf("Opening tunnel so workspaces can connect to your deployment. For production scenarios, specify an external access URL\n")
tunnel, err = devtunnel.New(ctx, logger.Named("devtunnel"))
if err != nil {
return xerrors.Errorf("create tunnel: %w", err)
}
defer tunnel.Close()
cfg.AccessURL.Value = tunnel.URL.String()
tunnelDone = tunnel.Wait()
cfg.AccessURL = clibase.URL(*tunnel.URL)

if cfg.WildcardAccessURL.Value == "" {
if cfg.WildcardAccessURL.String() == "" {
// Suffixed wildcard access URL.
cfg.WildcardAccessURL.Value = fmt.Sprintf("*--%s", tunnel.URL.Hostname())
u, err := url.Parse(fmt.Sprintf("*--%s", tunnel.URL.Hostname()))
if err != nil {
return xerrors.Errorf("parse wildcard url: %w", err)
}
cfg.WildcardAccessURL = clibase.URL(*u)
}
}

Expand Down Expand Up @@ -1051,7 +1059,7 @@ flags, and YAML configuration. The precedence is as follows:
_, _ = fmt.Fprintln(cmd.OutOrStdout(), cliui.Styles.Bold.Render(
"Interrupt caught, gracefully exiting. Use ctrl+\\ to force quit",
))
case <-tunnel.Wait():
case <-tunnelDone:
exitErr = xerrors.New("dev tunnel closed unexpectedly")
case exitErr = <-errCh:
}
Expand Down
12 changes: 10 additions & 2 deletions coderd/devtunnel/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ func NewWithConfig(ctx context.Context, logger slog.Logger, cfg Config) (*tunnel
}

c := tunnelsdk.New(u)
if cfg.HTTPClient != nil {
c.HTTPClient = cfg.HTTPClient
}
return c.LaunchTunnel(ctx, tunnelsdk.TunnelConfig{
Log: logger,
Version: cfg.Version,
Expand Down Expand Up @@ -146,9 +149,14 @@ func GenerateConfig() (Config, error) {
spin.Suffix = " Finding the closest tunnel region..."
spin.Start()

node, err := FindClosestNode()
nodes, err := Nodes()
if err != nil {
return Config{}, xerrors.Errorf("get nodes: %w", err)
}
node, err := FindClosestNode(nodes)
if err != nil {
// If we fail to find the closest node, default to US East.
// If we fail to find the closest node, default to a random node from
// the first region.
Comment on lines +158 to +159
Copy link
Member

Choose a reason for hiding this comment

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

Are nodes sorted, so that we need to use random numbers? Could it be always the first node or the healthiest/biggest one?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't have any mechanism to judge which node is healthiest currently. We only have one node so this actually does nothing right now. When/if we add more nodes in the future we can optimize this or perhaps force it to fail on error.

Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if a map, wouldn't be better than array then, but it's a nit-pick.

region := Regions[0]
n, _ := cryptorand.Intn(len(region.Nodes))
node = region.Nodes[n]
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.
0