mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add single tailnet support to moons (#8587)
This commit is contained in:
@@ -27,10 +27,12 @@ import (
|
||||
"github.com/coder/coder/codersdk"
|
||||
"github.com/coder/coder/enterprise/wsproxy/wsproxysdk"
|
||||
"github.com/coder/coder/site"
|
||||
agpl "github.com/coder/coder/tailnet"
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
Logger slog.Logger
|
||||
Logger slog.Logger
|
||||
Experiments codersdk.Experiments
|
||||
|
||||
HTTPClient *http.Client
|
||||
// DashboardURL is the URL of the primary coderd instance.
|
||||
@@ -168,6 +170,30 @@ func New(ctx context.Context, opts *Options) (*Server, error) {
|
||||
cancel: cancel,
|
||||
}
|
||||
|
||||
connInfo, err := client.SDKClient.WorkspaceAgentConnectionInfo(ctx)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("get derpmap: %w", err)
|
||||
}
|
||||
|
||||
var agentProvider workspaceapps.AgentProvider
|
||||
if opts.Experiments.Enabled(codersdk.ExperimentSingleTailnet) {
|
||||
stn, err := coderd.NewServerTailnet(ctx,
|
||||
s.Logger.Named("server_tailnet"),
|
||||
nil,
|
||||
connInfo.DERPMap,
|
||||
s.DialCoordinator,
|
||||
wsconncache.New(s.DialWorkspaceAgent, 0),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("create server tailnet: %w", err)
|
||||
}
|
||||
agentProvider = stn
|
||||
} else {
|
||||
agentProvider = &wsconncache.AgentProvider{
|
||||
Cache: wsconncache.New(s.DialWorkspaceAgent, 0),
|
||||
}
|
||||
}
|
||||
|
||||
s.AppServer = &workspaceapps.Server{
|
||||
Logger: opts.Logger.Named("workspaceapps"),
|
||||
DashboardURL: opts.DashboardURL,
|
||||
@@ -185,10 +211,7 @@ func New(ctx context.Context, opts *Options) (*Server, error) {
|
||||
},
|
||||
AppSecurityKey: secKey,
|
||||
|
||||
// TODO: Convert wsproxy to use coderd.ServerTailnet.
|
||||
AgentProvider: &wsconncache.AgentProvider{
|
||||
Cache: wsconncache.New(s.DialWorkspaceAgent, 0),
|
||||
},
|
||||
AgentProvider: agentProvider,
|
||||
DisablePathApps: opts.DisablePathApps,
|
||||
SecureAuthCookie: opts.SecureAuthCookie,
|
||||
}
|
||||
@@ -285,6 +308,10 @@ func (s *Server) DialWorkspaceAgent(id uuid.UUID) (*codersdk.WorkspaceAgentConn,
|
||||
return s.SDKClient.DialWorkspaceAgent(s.ctx, id, nil)
|
||||
}
|
||||
|
||||
func (s *Server) DialCoordinator(ctx context.Context) (agpl.MultiAgentConn, error) {
|
||||
return s.SDKClient.DialCoordinator(ctx)
|
||||
}
|
||||
|
||||
func (s *Server) buildInfo(rw http.ResponseWriter, r *http.Request) {
|
||||
httpapi.Write(r.Context(), rw, http.StatusOK, codersdk.BuildInfoResponse{
|
||||
ExternalURL: buildinfo.ExternalURL(),
|
||||
|
||||
Reference in New Issue
Block a user