Skip to content

Commit b405113

Browse files
committed
fixup! Merge branch 'main' into dean/proxy-derp-map
1 parent 9d90dc2 commit b405113

19 files changed

+116
-437
lines changed

agent/agent.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -817,14 +817,8 @@ func (a *agent) runCoordinator(ctx context.Context, network *tailnet.Conn) error
817817
}
818818
defer coordinator.Close()
819819
a.logger.Info(ctx, "connected to coordination endpoint")
820-
sendNodes, errChan := tailnet.ServeCoordinator(coordinator, func(update tailnet.CoordinatorNodeUpdate) error {
821-
// Check if we need to update our DERP map.
822-
if !tailnet.CompareDERPMaps(network.DERPMap(), update.DERPMap) {
823-
a.logger.Info(ctx, "updating DERP map on connection request due to changes", slog.F("old", network.DERPMap()), slog.F("new", update.DERPMap))
824-
network.SetDERPMap(update.DERPMap)
825-
}
826-
827-
return network.UpdateNodes(update.Nodes, false)
820+
sendNodes, errChan := tailnet.ServeCoordinator(coordinator, func(nodes []*tailnet.Node) error {
821+
return network.UpdateNodes(nodes, false)
828822
})
829823
network.SetNodeCallback(sendNodes)
830824
select {

agent/agent_test.go

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ func TestAgent_StartupScript(t *testing.T) {
889889
DERPMap: &tailcfg.DERPMap{},
890890
},
891891
statsChan: make(chan *agentsdk.Stats),
892-
coordinator: tailnet.NewCoordinator(logger, emptyDerpMapFn),
892+
coordinator: tailnet.NewCoordinator(logger),
893893
}
894894
closer := agent.New(agent.Options{
895895
Client: client,
@@ -930,7 +930,7 @@ func TestAgent_StartupScript(t *testing.T) {
930930
return codersdk.ReadBodyAsError(res)
931931
},
932932
statsChan: make(chan *agentsdk.Stats),
933-
coordinator: tailnet.NewCoordinator(logger, emptyDerpMapFn),
933+
coordinator: tailnet.NewCoordinator(logger),
934934
}
935935
closer := agent.New(agent.Options{
936936
Client: client,
@@ -1290,7 +1290,7 @@ func TestAgent_Lifecycle(t *testing.T) {
12901290
ShutdownScript: "echo " + expected,
12911291
},
12921292
statsChan: make(chan *agentsdk.Stats),
1293-
coordinator: tailnet.NewCoordinator(logger, emptyDerpMapFn),
1293+
coordinator: tailnet.NewCoordinator(logger),
12941294
}
12951295

12961296
fs := afero.NewMemMapFs()
@@ -1538,9 +1538,7 @@ func TestAgent_UpdatedDERP(t *testing.T) {
15381538
metadata := agentsdk.Manifest{
15391539
DERPMap: &derpMap,
15401540
}
1541-
coordinator := tailnet.NewCoordinator(logger, func() *tailcfg.DERPMap {
1542-
return &derpMap
1543-
})
1541+
coordinator := tailnet.NewCoordinator(logger)
15441542
defer func() {
15451543
_ = coordinator.Close()
15461544
}()
@@ -1585,11 +1583,8 @@ func TestAgent_UpdatedDERP(t *testing.T) {
15851583
err := coordinator.ServeClient(serverConn, uuid.New(), agentID)
15861584
assert.NoError(t, err)
15871585
}()
1588-
sendNode, _ := tailnet.ServeCoordinator(clientConn, func(update tailnet.CoordinatorNodeUpdate) error {
1589-
if tailnet.CompareDERPMaps(conn.DERPMap(), update.DERPMap) {
1590-
conn.SetDERPMap(update.DERPMap)
1591-
}
1592-
return conn.UpdateNodes(update.Nodes, false)
1586+
sendNode, _ := tailnet.ServeCoordinator(clientConn, func(nodes []*tailnet.Node) error {
1587+
return conn.UpdateNodes(nodes, false)
15931588
})
15941589
conn.SetNodeCallback(sendNode)
15951590

@@ -1610,6 +1605,7 @@ func TestAgent_UpdatedDERP(t *testing.T) {
16101605
conn1 := newClientConn()
16111606

16121607
// Change the DERP map.
1608+
// TODO: fix this test
16131609
derpMap = *tailnettest.RunDERPAndSTUN(t)
16141610
// Change the region ID.
16151611
derpMap.Regions[2] = derpMap.Regions[1]
@@ -1651,7 +1647,7 @@ func TestAgent_Reconnect(t *testing.T) {
16511647
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
16521648
// After the agent is disconnected from a coordinator, it's supposed
16531649
// to reconnect!
1654-
coordinator := tailnet.NewCoordinator(logger, emptyDerpMapFn)
1650+
coordinator := tailnet.NewCoordinator(logger)
16551651
defer coordinator.Close()
16561652

16571653
agentID := uuid.New()
@@ -1689,7 +1685,7 @@ func TestAgent_Reconnect(t *testing.T) {
16891685
func TestAgent_WriteVSCodeConfigs(t *testing.T) {
16901686
t.Parallel()
16911687
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
1692-
coordinator := tailnet.NewCoordinator(logger, emptyDerpMapFn)
1688+
coordinator := tailnet.NewCoordinator(logger)
16931689
defer coordinator.Close()
16941690

16951691
client := &client{
@@ -1803,9 +1799,7 @@ func setupAgent(t *testing.T, metadata agentsdk.Manifest, ptyTimeout time.Durati
18031799
if metadata.DERPMap == nil {
18041800
metadata.DERPMap = tailnettest.RunDERPAndSTUN(t)
18051801
}
1806-
coordinator := tailnet.NewCoordinator(logger, func() *tailcfg.DERPMap {
1807-
return metadata.DERPMap
1808-
})
1802+
coordinator := tailnet.NewCoordinator(logger)
18091803
t.Cleanup(func() {
18101804
_ = coordinator.Close()
18111805
})
@@ -1853,10 +1847,8 @@ func setupAgent(t *testing.T, metadata agentsdk.Manifest, ptyTimeout time.Durati
18531847
defer close(serveClientDone)
18541848
coordinator.ServeClient(serverConn, uuid.New(), agentID)
18551849
}()
1856-
sendNode, _ := tailnet.ServeCoordinator(clientConn, func(update tailnet.CoordinatorNodeUpdate) error {
1857-
// Don't need to worry about updating the DERP map since it'll never
1858-
// change in this test (as we aren't dealing with proxies etc.)
1859-
return conn.UpdateNodes(update.Nodes, false)
1850+
sendNode, _ := tailnet.ServeCoordinator(clientConn, func(nodes []*tailnet.Node) error {
1851+
return conn.UpdateNodes(nodes, false)
18601852
})
18611853
conn.SetNodeCallback(sendNode)
18621854
agentConn := &codersdk.WorkspaceAgentConn{
@@ -2165,7 +2157,3 @@ func verifyCollectedMetrics(t *testing.T, expected []agentsdk.AgentMetric, actua
21652157
}
21662158
return true
21672159
}
2168-
2169-
func emptyDerpMapFn() *tailcfg.DERPMap {
2170-
return &tailcfg.DERPMap{}
2171-
}

cli/netcheck.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (r *RootCmd) netcheck() *clibase.Cmd {
2727
ctx, cancel := context.WithTimeout(inv.Context(), 30*time.Second)
2828
defer cancel()
2929

30-
connInfo, err := client.WorkspaceAgentConnectionInfo(ctx)
30+
connInfo, err := client.WorkspaceAgentConnectionInfoGeneric(ctx)
3131
if err != nil {
3232
return err
3333
}

coderd/coderd.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ func New(options *Options) *API {
232232
if options.DERPServer == nil {
233233
options.DERPServer = derp.NewServer(key.NewNode(), tailnet.Logger(options.Logger.Named("derp")))
234234
}
235+
if options.TailnetCoordinator == nil {
236+
options.TailnetCoordinator = tailnet.NewCoordinator(options.Logger)
237+
}
235238
if options.Auditor == nil {
236239
options.Auditor = audit.NewNop()
237240
}
@@ -318,9 +321,6 @@ func New(options *Options) *API {
318321
Experiments: experiments,
319322
healthCheckGroup: &singleflight.Group[string, *healthcheck.Report]{},
320323
}
321-
if options.TailnetCoordinator == nil {
322-
options.TailnetCoordinator = tailnet.NewCoordinator(options.Logger, api.DERPMap)
323-
}
324324
if options.HealthcheckFunc == nil {
325325
options.HealthcheckFunc = func(ctx context.Context, apiKey string) *healthcheck.Report {
326326
return healthcheck.Run(ctx, &healthcheck.ReportOptions{

coderd/prometheusmetrics/prometheusmetrics_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ func TestAgents(t *testing.T) {
304304
derpMapFn := func() *tailcfg.DERPMap {
305305
return derpMap
306306
}
307-
coordinator := tailnet.NewCoordinator(slogtest.Make(t, nil).Leveled(slog.LevelDebug), derpMapFn)
307+
coordinator := tailnet.NewCoordinator(slogtest.Make(t, nil).Leveled(slog.LevelDebug))
308308
coordinatorPtr := atomic.Pointer[tailnet.Coordinator]{}
309309
coordinatorPtr.Store(&coordinator)
310310
agentInactiveDisconnectTimeout := 1 * time.Hour // don't need to focus on this value in tests

coderd/workspaceagents.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -757,17 +757,8 @@ func (api *API) dialWorkspaceAgentTailnet(agentID uuid.UUID) (*codersdk.Workspac
757757
return left
758758
})
759759

760-
sendNodes, _ := tailnet.ServeCoordinator(clientConn, func(update tailnet.CoordinatorNodeUpdate) error {
761-
// Check if we need to update the DERP map used by the connection.
762-
if !tailnet.CompareDERPMaps(conn.DERPMap(), update.DERPMap) {
763-
conn.SetDERPMap(update.DERPMap)
764-
}
765-
766-
err = conn.UpdateNodes(update.Nodes, true)
767-
if err != nil {
768-
return xerrors.Errorf("update nodes: %w", err)
769-
}
770-
return nil
760+
sendNodes, _ := tailnet.ServeCoordinator(clientConn, func(nodes []*tailnet.Node) error {
761+
return conn.UpdateNodes(nodes, true)
771762
})
772763
conn.SetNodeCallback(sendNodes)
773764
agentConn := &codersdk.WorkspaceAgentConn{

coderd/wsconncache/wsconncache_test.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/stretchr/testify/require"
2121
"go.uber.org/atomic"
2222
"go.uber.org/goleak"
23-
"tailscale.com/tailcfg"
2423

2524
"cdr.dev/slog"
2625
"cdr.dev/slog/sloggers/slogtest"
@@ -160,9 +159,7 @@ func setupAgent(t *testing.T, manifest agentsdk.Manifest, ptyTimeout time.Durati
160159
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
161160
manifest.DERPMap = tailnettest.RunDERPAndSTUN(t)
162161

163-
coordinator := tailnet.NewCoordinator(logger, func() *tailcfg.DERPMap {
164-
return manifest.DERPMap
165-
})
162+
coordinator := tailnet.NewCoordinator(logger)
166163
t.Cleanup(func() {
167164
_ = coordinator.Close()
168165
})
@@ -193,10 +190,8 @@ func setupAgent(t *testing.T, manifest agentsdk.Manifest, ptyTimeout time.Durati
193190
_ = conn.Close()
194191
})
195192
go coordinator.ServeClient(serverConn, uuid.New(), agentID)
196-
sendNode, _ := tailnet.ServeCoordinator(clientConn, func(update tailnet.CoordinatorNodeUpdate) error {
197-
// Don't need to worry about updating the DERP map since it'll never
198-
// change in this test (as we aren't dealing with proxies etc.)
199-
return conn.UpdateNodes(update.Nodes, false)
193+
sendNode, _ := tailnet.ServeCoordinator(clientConn, func(nodes []*tailnet.Node) error {
194+
return conn.UpdateNodes(nodes, false)
200195
})
201196
conn.SetNodeCallback(sendNode)
202197
agentConn := &codersdk.WorkspaceAgentConn{

codersdk/workspaceagents.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -171,24 +171,18 @@ type WorkspaceAgentConnectionInfo struct {
171171
DisableDirectConnections bool `json:"disable_direct_connections"`
172172
}
173173

174-
func (c *Client) WorkspaceAgentConnectionInfoGeneric(ctx context.Context) (*WorkspaceAgentConnectionInfo, error) {
174+
func (c *Client) WorkspaceAgentConnectionInfoGeneric(ctx context.Context) (WorkspaceAgentConnectionInfo, error) {
175175
res, err := c.Request(ctx, http.MethodGet, "/api/v2/workspaceagents/connection", nil)
176176
if err != nil {
177-
return nil, err
177+
return WorkspaceAgentConnectionInfo{}, err
178178
}
179179
defer res.Body.Close()
180-
181180
if res.StatusCode != http.StatusOK {
182-
return nil, ReadBodyAsError(res)
183-
}
184-
185-
var info WorkspaceAgentConnectionInfo
186-
err = json.NewDecoder(res.Body).Decode(&info)
187-
if err != nil {
188-
return nil, xerrors.Errorf("decode connection info: %w", err)
181+
return WorkspaceAgentConnectionInfo{}, ReadBodyAsError(res)
189182
}
190183

191-
return &info, nil
184+
var connInfo WorkspaceAgentConnectionInfo
185+
return connInfo, json.NewDecoder(res.Body).Decode(&connInfo)
192186
}
193187

194188
func (c *Client) WorkspaceAgentConnectionInfo(ctx context.Context, agentID uuid.UUID) (WorkspaceAgentConnectionInfo, error) {
@@ -295,13 +289,8 @@ func (c *Client) DialWorkspaceAgent(ctx context.Context, agentID uuid.UUID, opti
295289
options.Logger.Debug(ctx, "failed to dial", slog.Error(err))
296290
continue
297291
}
298-
sendNode, errChan := tailnet.ServeCoordinator(websocket.NetConn(ctx, ws, websocket.MessageBinary), func(update tailnet.CoordinatorNodeUpdate) error {
299-
// Check if we need to update the DERP map used by the connection.
300-
if !tailnet.CompareDERPMaps(conn.DERPMap(), update.DERPMap) {
301-
options.Logger.Debug(ctx, "updating DERP map on connection request due to changes", slog.F("old", conn.DERPMap()), slog.F("new", update.DERPMap))
302-
conn.SetDERPMap(update.DERPMap)
303-
}
304-
return conn.UpdateNodes(update.Nodes, false)
292+
sendNode, errChan := tailnet.ServeCoordinator(websocket.NetConn(ctx, ws, websocket.MessageBinary), func(nodes []*tailnet.Node) error {
293+
return conn.UpdateNodes(nodes, false)
305294
})
306295
conn.SetNodeCallback(sendNode)
307296
options.Logger.Debug(ctx, "serving coordinator")

0 commit comments

Comments
 (0)