Skip to content

Commit ad3fed7

Browse files
authored
chore: rename Coordinator to CoordinatorV1 (#11222)
Renames the tailnet.Coordinator to represent both v1 and v2 APIs, so that we can use this interface for the main atomic pointer. Part of #10532
1 parent 545cb9a commit ad3fed7

File tree

9 files changed

+37
-29
lines changed

9 files changed

+37
-29
lines changed

agent/agenttest/client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func NewClient(t testing.TB,
2424
agentID uuid.UUID,
2525
manifest agentsdk.Manifest,
2626
statsChan chan *agentsdk.Stats,
27-
coordinator tailnet.Coordinator,
27+
coordinator tailnet.CoordinatorV1,
2828
) *Client {
2929
if manifest.AgentID == uuid.Nil {
3030
manifest.AgentID = agentID
@@ -47,7 +47,7 @@ type Client struct {
4747
manifest agentsdk.Manifest
4848
metadata map[string]agentsdk.Metadata
4949
statsChan chan *agentsdk.Stats
50-
coordinator tailnet.Coordinator
50+
coordinator tailnet.CoordinatorV1
5151
LastWorkspaceAgent func()
5252
PatchWorkspaceLogs func() error
5353
GetServiceBannerFunc func() (codersdk.ServiceBannerConfig, error)

cli/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
847847
defer closeBatcher()
848848

849849
// We use a separate coderAPICloser so the Enterprise API
850-
// can have it's own close functions. This is cleaner
850+
// can have its own close functions. This is cleaner
851851
// than abstracting the Coder API itself.
852852
coderAPI, coderAPICloser, err := newAPI(ctx, options)
853853
if err != nil {

coderd/workspaceagents.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1508,7 +1508,7 @@ func convertWorkspaceAgentMetadataDesc(mds []database.WorkspaceAgentMetadatum) [
15081508
return metadata
15091509
}
15101510

1511-
func convertWorkspaceAgent(derpMap *tailcfg.DERPMap, coordinator tailnet.Coordinator,
1511+
func convertWorkspaceAgent(derpMap *tailcfg.DERPMap, coordinator tailnet.CoordinatorV1,
15121512
dbAgent database.WorkspaceAgent, apps []codersdk.WorkspaceApp, scripts []codersdk.WorkspaceAgentScript, logSources []codersdk.WorkspaceAgentLogSource,
15131513
agentInactiveDisconnectTimeout time.Duration, agentFallbackTroubleshootingURL string,
15141514
) (codersdk.WorkspaceAgent, error) {

coderd/wsconncache/wsconncache_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ type client struct {
215215
t *testing.T
216216
agentID uuid.UUID
217217
manifest agentsdk.Manifest
218-
coordinator tailnet.Coordinator
218+
coordinator tailnet.CoordinatorV1
219219
}
220220

221221
func (c *client) Manifest(_ context.Context) (agentsdk.Manifest, error) {

enterprise/tailnet/coordinator.go

+19
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/coder/coder/v2/coderd/util/slice"
2424
"github.com/coder/coder/v2/codersdk"
2525
agpl "github.com/coder/coder/v2/tailnet"
26+
"github.com/coder/coder/v2/tailnet/proto"
2627
)
2728

2829
// NewCoordinator creates a new high availability coordinator
@@ -156,6 +157,24 @@ type haCoordinator struct {
156157
legacyAgents map[uuid.UUID]struct{}
157158
}
158159

160+
func (c *haCoordinator) Coordinate(ctx context.Context, _ uuid.UUID, _ string, _ agpl.TunnelAuth) (chan<- *proto.CoordinateRequest, <-chan *proto.CoordinateResponse) {
161+
// HA Coordinator does NOT support v2 API and this is just here to appease the compiler and prevent
162+
// panics while we build out v2 support elsewhere. We will retire the HA Coordinator in favor of
163+
// PG Coordinator before we turn on the v2 API.
164+
c.log.Warn(ctx, "v2 API invoked but unimplemented")
165+
resp := make(chan *proto.CoordinateResponse)
166+
close(resp)
167+
req := make(chan *proto.CoordinateRequest)
168+
go func() {
169+
for {
170+
if _, ok := <-req; !ok {
171+
return
172+
}
173+
}
174+
}()
175+
return req, resp
176+
}
177+
159178
// Node returns an in-memory node by ID.
160179
func (c *haCoordinator) Node(id uuid.UUID) *agpl.Node {
161180
c.mutex.Lock()

enterprise/tailnet/pgcoord.go

-6
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,6 @@ func newPGCoordInternal(
149149
return c, nil
150150
}
151151

152-
// NewPGCoordV2 creates a high-availability coordinator that stores state in the PostgreSQL database and
153-
// receives notifications of updates via the pubsub.
154-
func NewPGCoordV2(ctx context.Context, logger slog.Logger, ps pubsub.Pubsub, store database.Store) (agpl.CoordinatorV2, error) {
155-
return newPGCoordInternal(ctx, logger, ps, store)
156-
}
157-
158152
func (c *pgCoord) ServeMultiAgent(id uuid.UUID) agpl.MultiAgentConn {
159153
return agpl.ServeMultiAgent(c, c.logger, id)
160154
}

enterprise/tailnet/pgcoord_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ func TestPGCoordinator_BidirectionalTunnels(t *testing.T) {
611611
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitSuperLong)
612612
defer cancel()
613613
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
614-
coordinator, err := tailnet.NewPGCoordV2(ctx, logger, ps, store)
614+
coordinator, err := tailnet.NewPGCoord(ctx, logger, ps, store)
615615
require.NoError(t, err)
616616
defer coordinator.Close()
617617
agpltest.BidirectionalTunnels(ctx, t, coordinator)
@@ -626,7 +626,7 @@ func TestPGCoordinator_GracefulDisconnect(t *testing.T) {
626626
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitSuperLong)
627627
defer cancel()
628628
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
629-
coordinator, err := tailnet.NewPGCoordV2(ctx, logger, ps, store)
629+
coordinator, err := tailnet.NewPGCoord(ctx, logger, ps, store)
630630
require.NoError(t, err)
631631
defer coordinator.Close()
632632
agpltest.GracefulDisconnectTest(ctx, t, coordinator)
@@ -641,7 +641,7 @@ func TestPGCoordinator_Lost(t *testing.T) {
641641
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitSuperLong)
642642
defer cancel()
643643
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
644-
coordinator, err := tailnet.NewPGCoordV2(ctx, logger, ps, store)
644+
coordinator, err := tailnet.NewPGCoord(ctx, logger, ps, store)
645645
require.NoError(t, err)
646646
defer coordinator.Close()
647647
agpltest.LostTest(ctx, t, coordinator)
@@ -676,7 +676,7 @@ func newTestConn(ids []uuid.UUID) *testConn {
676676
return a
677677
}
678678

679-
func newTestAgent(t *testing.T, coord agpl.Coordinator, name string, id ...uuid.UUID) *testConn {
679+
func newTestAgent(t *testing.T, coord agpl.CoordinatorV1, name string, id ...uuid.UUID) *testConn {
680680
a := newTestConn(id)
681681
go func() {
682682
err := coord.ServeAgent(a.serverWS, a.id, name)
@@ -731,7 +731,7 @@ func (c *testConn) waitForClose(ctx context.Context, t *testing.T) {
731731
}
732732
}
733733

734-
func newTestClient(t *testing.T, coord agpl.Coordinator, agentID uuid.UUID, id ...uuid.UUID) *testConn {
734+
func newTestClient(t *testing.T, coord agpl.CoordinatorV1, agentID uuid.UUID, id ...uuid.UUID) *testConn {
735735
c := newTestConn(id)
736736
go func() {
737737
err := coord.ServeClient(c.serverWS, c.id, agentID)

tailnet/coordinator.go

+5-10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ import (
2727
// └──────────────────┘ └────────────────────┘ └───────────────────┘ └──────────────────┘
2828
// Coordinators have different guarantees for HA support.
2929
type Coordinator interface {
30+
CoordinatorV1
31+
CoordinatorV2
32+
}
33+
34+
type CoordinatorV1 interface {
3035
// ServeHTTPDebug serves a debug webpage that shows the internal state of
3136
// the coordinator.
3237
ServeHTTPDebug(w http.ResponseWriter, r *http.Request)
@@ -143,16 +148,6 @@ func NewCoordinator(logger slog.Logger) Coordinator {
143148
}
144149
}
145150

146-
// NewCoordinatorV2 constructs a new in-memory connection coordinator. This
147-
// coordinator is incompatible with multiple Coder replicas as all node data is
148-
// in-memory.
149-
func NewCoordinatorV2(logger slog.Logger) CoordinatorV2 {
150-
return &coordinator{
151-
core: newCore(logger.Named(LoggerName)),
152-
closedChan: make(chan struct{}),
153-
}
154-
}
155-
156151
// coordinator exchanges nodes with agents to establish connections entirely in-memory.
157152
// The Enterprise implementation provides this for high-availability.
158153
// ┌──────────────────┐ ┌────────────────────┐ ┌───────────────────┐ ┌──────────────────┐

tailnet/coordinator_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -357,23 +357,23 @@ func TestCoordinator_AgentUpdateWhileClientConnects(t *testing.T) {
357357
func TestCoordinator_BidirectionalTunnels(t *testing.T) {
358358
t.Parallel()
359359
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
360-
coordinator := tailnet.NewCoordinatorV2(logger)
360+
coordinator := tailnet.NewCoordinator(logger)
361361
ctx := testutil.Context(t, testutil.WaitShort)
362362
test.BidirectionalTunnels(ctx, t, coordinator)
363363
}
364364

365365
func TestCoordinator_GracefulDisconnect(t *testing.T) {
366366
t.Parallel()
367367
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
368-
coordinator := tailnet.NewCoordinatorV2(logger)
368+
coordinator := tailnet.NewCoordinator(logger)
369369
ctx := testutil.Context(t, testutil.WaitShort)
370370
test.GracefulDisconnectTest(ctx, t, coordinator)
371371
}
372372

373373
func TestCoordinator_Lost(t *testing.T) {
374374
t.Parallel()
375375
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
376-
coordinator := tailnet.NewCoordinatorV2(logger)
376+
coordinator := tailnet.NewCoordinator(logger)
377377
ctx := testutil.Context(t, testutil.WaitShort)
378378
test.LostTest(ctx, t, coordinator)
379379
}

0 commit comments

Comments
 (0)