Skip to content

feat: add single tailnet support to pgcoord #9351

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 24 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a20d318
feat: add single tailnet support to pgcoord
coadler Aug 25, 2023
efa2071
fixup! feat: add single tailnet support to pgcoord
coadler Aug 25, 2023
2976c00
fixup! feat: add single tailnet support to pgcoord
coadler Aug 25, 2023
a7b39df
separate table + use channels
coadler Aug 31, 2023
618b0e0
fix migrations
coadler Sep 7, 2023
f50f929
fixup! fix migrations
coadler Sep 7, 2023
3a5bb76
fixup! fix migrations
coadler Sep 8, 2023
3ddc783
fixup! fix migrations
coadler Sep 8, 2023
c84626a
Merge branch 'main' into colin/single-pgcoord
coadler Sep 13, 2023
a0cb904
Merge branch 'main' into colin/single-pgcoord
coadler Sep 14, 2023
dcb007d
add subscriber subsystem
coadler Sep 15, 2023
bdd7ef1
fixup! add subscriber subsystem
coadler Sep 15, 2023
751b22f
fixup! add subscriber subsystem
coadler Sep 15, 2023
3af1af1
fixup! add subscriber subsystem
coadler Sep 15, 2023
7762a73
querier <- subscriber
coadler Sep 19, 2023
08501e6
Merge branch 'main' into colin/single-pgcoord
coadler Sep 19, 2023
eb681ff
fixup! Merge branch 'main' into colin/single-pgcoord
coadler Sep 19, 2023
390e837
fixup! Merge branch 'main' into colin/single-pgcoord
coadler Sep 19, 2023
a1c3acf
fixup! Merge branch 'main' into colin/single-pgcoord
coadler Sep 19, 2023
8256670
fixup! Merge branch 'main' into colin/single-pgcoord
coadler Sep 19, 2023
a75f6f1
add extensive multiagent tests
coadler Sep 20, 2023
d143d2d
use dedicated channels for querier subscribe and closing conns
coadler Sep 20, 2023
036094f
fixup! use dedicated channels for querier subscribe and closing conns
coadler Sep 20, 2023
e8a2b01
fixup! use dedicated channels for querier subscribe and closing conns
coadler Sep 21, 2023
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
fix migrations
  • Loading branch information
coadler committed Sep 7, 2023
commit 618b0e0fdd20e22e5937d0223d484239622e1ab1
10 changes: 8 additions & 2 deletions coderd/database/dbauthz/dbauthz.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,10 @@ func (q *querier) DeleteTailnetClient(ctx context.Context, arg database.DeleteTa
}

func (q *querier) DeleteTailnetClientSubscription(ctx context.Context, arg database.DeleteTailnetClientSubscriptionParams) (database.DeleteTailnetClientSubscriptionRow, error) {
panic("not implemented")
if err := q.authorizeContext(ctx, rbac.ActionDelete, rbac.ResourceTailnetCoordinator); err != nil {
return database.DeleteTailnetClientSubscriptionRow{}, err
}
return q.db.DeleteTailnetClientSubscription(ctx, arg)
}

func (q *querier) GetAPIKeyByID(ctx context.Context, id string) (database.APIKey, error) {
Expand Down Expand Up @@ -2783,7 +2786,10 @@ func (q *querier) UpsertTailnetClient(ctx context.Context, arg database.UpsertTa
}

func (q *querier) UpsertTailnetClientSubscription(ctx context.Context, arg database.UpsertTailnetClientSubscriptionParams) error {
panic("not implemented")
if err := q.authorizeContext(ctx, rbac.ActionUpdate, rbac.ResourceTailnetCoordinator); err != nil {
return err
}
return q.db.UpsertTailnetClientSubscription(ctx, arg)
}

func (q *querier) UpsertTailnetCoordinator(ctx context.Context, id uuid.UUID) (database.TailnetCoordinator, error) {
Expand Down
9 changes: 2 additions & 7 deletions coderd/database/dbfake/dbfake.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,13 +909,8 @@ func (*FakeQuerier) DeleteTailnetClient(context.Context, database.DeleteTailnetC
return database.DeleteTailnetClientRow{}, ErrUnimplemented
}

func (q *FakeQuerier) DeleteTailnetClientSubscription(ctx context.Context, arg database.DeleteTailnetClientSubscriptionParams) (database.DeleteTailnetClientSubscriptionRow, error) {
err := validateDatabaseType(arg)
if err != nil {
return database.DeleteTailnetClientSubscriptionRow{}, err
}

panic("not implemented")
func (*FakeQuerier) DeleteTailnetClientSubscription(context.Context, database.DeleteTailnetClientSubscriptionParams) (database.DeleteTailnetClientSubscriptionRow, error) {
return database.DeleteTailnetClientSubscriptionRow{}, ErrUnimplemented
}

func (q *FakeQuerier) GetAPIKeyByID(_ context.Context, id string) (database.APIKey, error) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
BEGIN;

ALTER TABLE
tailnet_clients
ADD COLUMN
agent_id uuid;

UPDATE
tailnet_clients
SET
-- there's no reason for us to try and preserve data since coordinators will
-- have to restart anyways, which will create all of the client mappings.
agent_id = '00000000-0000-0000-0000-000000000000'::uuid;

ALTER TABLE
tailnet_clients
ALTER COLUMN
agent_id SET NOT NULL;

DROP TABLE tailnet_client_subscriptions;
DROP FUNCTION tailnet_notify_client_subscription_change;

-- update the tailnet_clients trigger to the old version.
CREATE OR REPLACE FUNCTION tailnet_notify_client_change() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
IF (OLD IS NOT NULL) THEN
PERFORM pg_notify('tailnet_client_update', OLD.id || ',' || OLD.agent_id);
RETURN NULL;
END IF;
IF (NEW IS NOT NULL) THEN
PERFORM pg_notify('tailnet_client_update', NEW.id || ',' || NEW.agent_id);
RETURN NULL;
END IF;
END;
$$;

COMMIT;
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
BEGIN;

CREATE TABLE tailnet_client_subscriptions (
client_id uuid NOT NULL,
client_id uuid NOT NULL,
coordinator_id uuid NOT NULL,
-- this isn't a foreign key since it's more of a list of agents the client
-- *wants* to connect to, and they don't necessarily have to currently
-- exist in the db.
agent_id uuid NOT NULL,
updated_at timestamp with time zone NOT NULL,
agent_id uuid NOT NULL,
updated_at timestamp with time zone NOT NULL,
PRIMARY KEY (client_id, coordinator_id, agent_id),
FOREIGN KEY (coordinator_id) REFERENCES tailnet_coordinators (id) ON DELETE CASCADE
-- we don't keep a foreign key to the tailnet_clients table since there's
Expand All @@ -23,8 +23,7 @@ BEGIN
IF (NEW IS NOT NULL) THEN
PERFORM pg_notify('tailnet_client_update', NEW.client_id || ',' || NEW.agent_id);
RETURN NULL;
END IF;
IF (OLD IS NOT NULL) THEN
ELSIF (OLD IS NOT NULL) THEN
PERFORM pg_notify('tailnet_client_update', OLD.client_id || ',' || OLD.agent_id);
RETURN NULL;
END IF;
Expand All @@ -44,10 +43,6 @@ DECLARE
var_agent_ids uuid[];
BEGIN
IF (NEW.id IS NOT NULL) THEN
IF (NEW.node IS NULL) THEN
return NULL;
END IF;

var_client_id = NEW.id;
SELECT
array_agg(agent_id)
Expand All @@ -60,6 +55,7 @@ BEGIN
subs.coordinator_id = NEW.coordinator_id;
ELSIF (OLD.id IS NOT NULL) THEN
-- if new is null and old is not null, that means the row was deleted.
-- simulate a foreign key by deleting all of the subscriptions.
var_client_id = OLD.id;
WITH agent_ids AS (
DELETE FROM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ VALUES
);

INSERT INTO tailnet_agents
(id, coordinator_id, updated_at, node)
(id, coordinator_id, updated_at, node)
VALUES
(
'c0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
INSERT INTO tailnet_client_subscriptions
(client_id, agent_id, coordinator_id, updated_at)
VALUES
(
'b0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',
'c0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',
'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',
'2023-06-15 10:23:54+00'
);
2 changes: 1 addition & 1 deletion enterprise/tailnet/pgcoord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ type testConn struct {
func newTestConn(ids []uuid.UUID) *testConn {
a := &testConn{}
a.ws, a.serverWS = net.Pipe()
a.nodeChan = make(chan []*agpl.Node, 5)
a.nodeChan = make(chan []*agpl.Node)
a.sendNode, a.errChan = agpl.ServeCoordinator(a.ws, func(nodes []*agpl.Node) error {
a.nodeChan <- nodes
return nil
Expand Down