- Notifications
You must be signed in to change notification settings - Fork1k
feat: use tailnet v2 API for coordination#11638
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -3,19 +3,26 @@ package agenttest | ||
import ( | ||
"context" | ||
"io" | ||
"sync" | ||
"sync/atomic" | ||
"testing" | ||
"time" | ||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/require" | ||
"golang.org/x/exp/maps" | ||
"golang.org/x/xerrors" | ||
"storj.io/drpc" | ||
"storj.io/drpc/drpcmux" | ||
"storj.io/drpc/drpcserver" | ||
"tailscale.com/tailcfg" | ||
"cdr.dev/slog" | ||
"github.com/coder/coder/v2/codersdk" | ||
"github.com/coder/coder/v2/codersdk/agentsdk" | ||
drpcsdk "github.com/coder/coder/v2/codersdk/drpc" | ||
"github.com/coder/coder/v2/tailnet" | ||
"github.com/coder/coder/v2/tailnet/proto" | ||
"github.com/coder/coder/v2/testutil" | ||
) | ||
@@ -24,18 +31,39 @@ func NewClient(t testing.TB, | ||
agentID uuid.UUID, | ||
manifest agentsdk.Manifest, | ||
statsChan chan *agentsdk.Stats, | ||
coordinator tailnet.Coordinator, | ||
) *Client { | ||
if manifest.AgentID == uuid.Nil { | ||
manifest.AgentID = agentID | ||
} | ||
coordPtr := atomic.Pointer[tailnet.Coordinator]{} | ||
coordPtr.Store(&coordinator) | ||
mux := drpcmux.New() | ||
drpcService := &tailnet.DRPCService{ | ||
CoordPtr: &coordPtr, | ||
Logger: logger, | ||
// TODO: handle DERPMap too! | ||
DerpMapUpdateFrequency: time.Hour, | ||
Comment on lines +45 to +46 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Is this needed for this PR or is it addressed in one of the PRs after this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Addressed in some upstack PRs. As of this PR we still use the old DERPMap dedicated websocket, but I'm in the process of switching everything over after this one. | ||
DerpMapFn: func() *tailcfg.DERPMap { panic("not implemented") }, | ||
} | ||
err := proto.DRPCRegisterTailnet(mux, drpcService) | ||
require.NoError(t, err) | ||
server := drpcserver.NewWithOptions(mux, drpcserver.Options{ | ||
Log: func(err error) { | ||
if xerrors.Is(err, io.EOF) { | ||
return | ||
} | ||
logger.Debug(context.Background(), "drpc server error", slog.Error(err)) | ||
}, | ||
}) | ||
return &Client{ | ||
t: t, | ||
logger: logger.Named("client"), | ||
agentID: agentID, | ||
manifest: manifest, | ||
statsChan: statsChan, | ||
coordinator: coordinator, | ||
server: server, | ||
derpMapUpdates: make(chan agentsdk.DERPMapUpdate), | ||
} | ||
} | ||
@@ -47,7 +75,8 @@ type Client struct { | ||
manifest agentsdk.Manifest | ||
metadata map[string]agentsdk.Metadata | ||
statsChan chan *agentsdk.Stats | ||
coordinator tailnet.Coordinator | ||
server *drpcserver.Server | ||
LastWorkspaceAgent func() | ||
PatchWorkspaceLogs func() error | ||
GetServiceBannerFunc func() (codersdk.ServiceBannerConfig, error) | ||
@@ -63,20 +92,29 @@ func (c *Client) Manifest(_ context.Context) (agentsdk.Manifest, error) { | ||
return c.manifest, nil | ||
} | ||
func (c *Client) Listen(_ context.Context) (drpc.Conn, error) { | ||
conn, lis :=drpcsdk.MemTransportPipe() | ||
closed := make(chan struct{}) | ||
c.LastWorkspaceAgent = func() { | ||
_ =conn.Close() | ||
_ =lis.Close() | ||
<-closed | ||
} | ||
c.t.Cleanup(c.LastWorkspaceAgent) | ||
serveCtx, cancel := context.WithCancel(context.Background()) | ||
c.t.Cleanup(cancel) | ||
auth := tailnet.AgentTunnelAuth{} | ||
streamID := tailnet.StreamID{ | ||
Name: "agenttest", | ||
ID: c.agentID, | ||
Auth: auth, | ||
} | ||
serveCtx = tailnet.WithStreamID(serveCtx, streamID) | ||
go func() { | ||
_ = c.server.Serve(serveCtx, lis) | ||
close(closed) | ||
}() | ||
returnconn, nil | ||
} | ||
func (c *Client) ReportStats(ctx context.Context, _ slog.Logger, statsChan <-chan *agentsdk.Stats, setInterval func(time.Duration)) (io.Closer, error) { | ||
Uh oh!
There was an error while loading.Please reload this page.