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

feat: add tailnet to agent RPC service#11304

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

Merged
spikecurtis merged 1 commit intomainfromspike/10531-agent-tailnet-websocket
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
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
14 changes: 14 additions & 0 deletionscoderd/agentapi/api.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,6 +26,7 @@ import (
"github.com/coder/coder/v2/coderd/tracing"
"github.com/coder/coder/v2/codersdk/agentsdk"
"github.com/coder/coder/v2/tailnet"
tailnetproto "github.com/coder/coder/v2/tailnet/proto"
)

const AgentAPIVersionDRPC = "2.0"
Expand All@@ -42,6 +43,7 @@ type API struct {
*AppsAPI
*MetadataAPI
*LogsAPI
*tailnet.DRPCService

mu sync.Mutex
cachedWorkspaceID uuid.UUID
Expand DownExpand Up@@ -145,6 +147,13 @@ func New(opts Options) *API {
PublishWorkspaceAgentLogsUpdateFn: opts.PublishWorkspaceAgentLogsUpdateFn,
}

api.DRPCService = &tailnet.DRPCService{
CoordPtr: opts.TailnetCoordinator,
Logger: opts.Log,
DerpMapUpdateFrequency: opts.DerpMapUpdateFrequency,
DerpMapFn: opts.DerpMapFn,
}

return api
}

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

err = tailnetproto.DRPCRegisterTailnet(mux, a)
if err != nil {
return nil, xerrors.Errorf("register tailnet API protocol in DRPC mux: %w", err)
}

return drpcserver.NewWithOptions(&tracing.DRPCHandler{Handler: mux},
drpcserver.Options{
Log: func(err error) {
Expand Down
9 changes: 9 additions & 0 deletionscoderd/workspaceagentsrpc.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@ package coderd
import (
"context"
"database/sql"
"fmt"
"net/http"
"runtime/pprof"
"sync/atomic"
Expand All@@ -22,6 +23,7 @@ import (
"github.com/coder/coder/v2/coderd/httpmw"
"github.com/coder/coder/v2/coderd/util/ptr"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/tailnet"
)

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

streamID := tailnet.StreamID{
Name: fmt.Sprintf("%s-%s-%s", owner.Username, workspace.Name, workspaceAgent.Name),
ID: workspaceAgent.ID,
Auth: tailnet.AgentTunnelAuth{},
}
ctx = tailnet.WithStreamID(ctx, streamID)

closeCtx, closeCtxCancel := context.WithCancel(ctx)
go func() {
defer closeCtxCancel()
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp