Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit36636bb

Browse files
authored
feat: add tailnet to agent RPC service (#11304)
Adds tailnet.DRPCService to the agent APISupports#10531 but we still need to add version negotiation to the websocket endpoint
1 parent25f2abf commit36636bb

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

‎coderd/agentapi/api.go‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/coder/coder/v2/coderd/tracing"
2727
"github.com/coder/coder/v2/codersdk/agentsdk"
2828
"github.com/coder/coder/v2/tailnet"
29+
tailnetproto"github.com/coder/coder/v2/tailnet/proto"
2930
)
3031

3132
constAgentAPIVersionDRPC="2.0"
@@ -42,6 +43,7 @@ type API struct {
4243
*AppsAPI
4344
*MetadataAPI
4445
*LogsAPI
46+
*tailnet.DRPCService
4547

4648
mu sync.Mutex
4749
cachedWorkspaceID uuid.UUID
@@ -145,6 +147,13 @@ func New(opts Options) *API {
145147
PublishWorkspaceAgentLogsUpdateFn:opts.PublishWorkspaceAgentLogsUpdateFn,
146148
}
147149

150+
api.DRPCService=&tailnet.DRPCService{
151+
CoordPtr:opts.TailnetCoordinator,
152+
Logger:opts.Log,
153+
DerpMapUpdateFrequency:opts.DerpMapUpdateFrequency,
154+
DerpMapFn:opts.DerpMapFn,
155+
}
156+
148157
returnapi
149158
}
150159

@@ -155,6 +164,11 @@ func (a *API) Server(ctx context.Context) (*drpcserver.Server, error) {
155164
returnnil,xerrors.Errorf("register agent API protocol in DRPC mux: %w",err)
156165
}
157166

167+
err=tailnetproto.DRPCRegisterTailnet(mux,a)
168+
iferr!=nil {
169+
returnnil,xerrors.Errorf("register tailnet API protocol in DRPC mux: %w",err)
170+
}
171+
158172
returndrpcserver.NewWithOptions(&tracing.DRPCHandler{Handler:mux},
159173
drpcserver.Options{
160174
Log:func(errerror) {

‎coderd/workspaceagentsrpc.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package coderd
33
import (
44
"context"
55
"database/sql"
6+
"fmt"
67
"net/http"
78
"runtime/pprof"
89
"sync/atomic"
@@ -22,6 +23,7 @@ import (
2223
"github.com/coder/coder/v2/coderd/httpmw"
2324
"github.com/coder/coder/v2/coderd/util/ptr"
2425
"github.com/coder/coder/v2/codersdk"
26+
"github.com/coder/coder/v2/tailnet"
2527
)
2628

2729
// @Summary Workspace agent RPC API
@@ -128,6 +130,13 @@ func (api *API) workspaceAgentRPC(rw http.ResponseWriter, r *http.Request) {
128130
UpdateAgentMetricsFn:api.UpdateAgentMetrics,
129131
})
130132

133+
streamID:= tailnet.StreamID{
134+
Name:fmt.Sprintf("%s-%s-%s",owner.Username,workspace.Name,workspaceAgent.Name),
135+
ID:workspaceAgent.ID,
136+
Auth: tailnet.AgentTunnelAuth{},
137+
}
138+
ctx=tailnet.WithStreamID(ctx,streamID)
139+
131140
closeCtx,closeCtxCancel:=context.WithCancel(ctx)
132141
gofunc() {
133142
defercloseCtxCancel()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp