Skip to content

Commit ba75bcc

Browse files
committed
chore: rename Coordinator to CoordinatorV1
1 parent 545cb9a commit ba75bcc

File tree

10 files changed

+41
-30
lines changed

10 files changed

+41
-30
lines changed

agent/agenttest/client.go

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
"sync"
1414
"time"
1515

16+
"github.com/coder/coder/v2/tailnet/proto"
17+
1618
"github.com/google/uuid"
1719
lru "github.com/hashicorp/golang-lru/v2"
1820
"golang.org/x/exp/slices"
@@ -156,6 +158,24 @@ type haCoordinator struct {
156158
legacyAgents map[uuid.UUID]struct{}
157159
}
158160

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

enterprise/tailnet/pgcoord.go

Lines changed: 0 additions & 6 deletions
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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,9 @@ 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+
var coordinator agpl.CoordinatorV2
615+
var err error
616+
coordinator, err = tailnet.NewPGCoord(ctx, logger, ps, store)
615617
require.NoError(t, err)
616618
defer coordinator.Close()
617619
agpltest.BidirectionalTunnels(ctx, t, coordinator)
@@ -626,7 +628,7 @@ func TestPGCoordinator_GracefulDisconnect(t *testing.T) {
626628
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitSuperLong)
627629
defer cancel()
628630
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
629-
coordinator, err := tailnet.NewPGCoordV2(ctx, logger, ps, store)
631+
coordinator, err := tailnet.NewPGCoord(ctx, logger, ps, store)
630632
require.NoError(t, err)
631633
defer coordinator.Close()
632634
agpltest.GracefulDisconnectTest(ctx, t, coordinator)
@@ -641,7 +643,7 @@ func TestPGCoordinator_Lost(t *testing.T) {
641643
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitSuperLong)
642644
defer cancel()
643645
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
644-
coordinator, err := tailnet.NewPGCoordV2(ctx, logger, ps, store)
646+
coordinator, err := tailnet.NewPGCoord(ctx, logger, ps, store)
645647
require.NoError(t, err)
646648
defer coordinator.Close()
647649
agpltest.LostTest(ctx, t, coordinator)
@@ -676,7 +678,7 @@ func newTestConn(ids []uuid.UUID) *testConn {
676678
return a
677679
}
678680

679-
func newTestAgent(t *testing.T, coord agpl.Coordinator, name string, id ...uuid.UUID) *testConn {
681+
func newTestAgent(t *testing.T, coord agpl.CoordinatorV1, name string, id ...uuid.UUID) *testConn {
680682
a := newTestConn(id)
681683
go func() {
682684
err := coord.ServeAgent(a.serverWS, a.id, name)
@@ -731,7 +733,7 @@ func (c *testConn) waitForClose(ctx context.Context, t *testing.T) {
731733
}
732734
}
733735

734-
func newTestClient(t *testing.T, coord agpl.Coordinator, agentID uuid.UUID, id ...uuid.UUID) *testConn {
736+
func newTestClient(t *testing.T, coord agpl.CoordinatorV1, agentID uuid.UUID, id ...uuid.UUID) *testConn {
735737
c := newTestConn(id)
736738
go func() {
737739
err := coord.ServeClient(c.serverWS, c.id, agentID)
-1 Bytes
Binary file not shown.

tailnet/coordinator.go

Lines changed: 6 additions & 11 deletions
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
// ┌──────────────────┐ ┌────────────────────┐ ┌───────────────────┐ ┌──────────────────┐
@@ -340,7 +335,7 @@ func (c *coordinator) ServeClient(conn net.Conn, id, agentID uuid.UUID) error {
340335
return ServeClientV1(ctx, c.core.logger, c, conn, id, agentID)
341336
}
342337

343-
// ServeClientV1 adapts a v1 Client to a v2 Coordinator
338+
// ServeClientV1 adapts a v1 Client to a v2 CoordinatorV1
344339
func ServeClientV1(ctx context.Context, logger slog.Logger, c CoordinatorV2, conn net.Conn, id uuid.UUID, agent uuid.UUID) error {
345340
logger = logger.With(slog.F("client_id", id), slog.F("agent_id", agent))
346341
defer func() {

tailnet/coordinator_test.go

Lines changed: 3 additions & 3 deletions
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)