@@ -41,6 +41,7 @@ import (
41
41
"github.com/coder/coder/buildinfo"
42
42
"github.com/coder/coder/coderd/gitauth"
43
43
"github.com/coder/coder/codersdk"
44
+ "github.com/coder/coder/codersdk/agentsdk"
44
45
"github.com/coder/coder/pty"
45
46
"github.com/coder/coder/tailnet"
46
47
"github.com/coder/retry"
@@ -68,12 +69,12 @@ type Options struct {
68
69
}
69
70
70
71
type Client interface {
71
- WorkspaceAgentMetadata (ctx context.Context ) (codersdk. WorkspaceAgentMetadata , error )
72
- ListenWorkspaceAgent (ctx context.Context ) (net.Conn , error )
73
- AgentReportStats (ctx context.Context , log slog.Logger , stats func () * codersdk. AgentStats ) (io.Closer , error )
74
- PostWorkspaceAgentLifecycle (ctx context.Context , state codersdk. PostWorkspaceAgentLifecycleRequest ) error
75
- PostWorkspaceAgentAppHealth (ctx context.Context , req codersdk. PostWorkspaceAppHealthsRequest ) error
76
- PostWorkspaceAgentVersion (ctx context.Context , version string ) error
72
+ Metadata (ctx context.Context ) (agentsdk. Metadata , error )
73
+ Listen (ctx context.Context ) (net.Conn , error )
74
+ ReportStats (ctx context.Context , log slog.Logger , stats func () * agentsdk. Stats ) (io.Closer , error )
75
+ PostLifecycle (ctx context.Context , state agentsdk. PostLifecycleRequest ) error
76
+ PostAppHealth (ctx context.Context , req agentsdk. PostAppHealthsRequest ) error
77
+ PostVersion (ctx context.Context , version string ) error
77
78
}
78
79
79
80
func New (options Options ) io.Closer {
@@ -187,7 +188,7 @@ func (a *agent) reportLifecycleLoop(ctx context.Context) {
187
188
188
189
a .logger .Debug (ctx , "post lifecycle state" , slog .F ("state" , state ))
189
190
190
- err := a .client .PostWorkspaceAgentLifecycle (ctx , codersdk. PostWorkspaceAgentLifecycleRequest {
191
+ err := a .client .PostLifecycle (ctx , agentsdk. PostLifecycleRequest {
191
192
State : state ,
192
193
})
193
194
if err == nil {
@@ -226,12 +227,12 @@ func (a *agent) run(ctx context.Context) error {
226
227
}
227
228
a .sessionToken .Store (& sessionToken )
228
229
229
- err = a .client .PostWorkspaceAgentVersion (ctx , buildinfo .Version ())
230
+ err = a .client .PostVersion (ctx , buildinfo .Version ())
230
231
if err != nil {
231
232
return xerrors .Errorf ("update workspace agent version: %w" , err )
232
233
}
233
234
234
- metadata , err := a .client .WorkspaceAgentMetadata (ctx )
235
+ metadata , err := a .client .Metadata (ctx )
235
236
if err != nil {
236
237
return xerrors .Errorf ("fetch metadata: %w" , err )
237
238
}
@@ -300,7 +301,7 @@ func (a *agent) run(ctx context.Context) error {
300
301
appReporterCtx , appReporterCtxCancel := context .WithCancel (ctx )
301
302
defer appReporterCtxCancel ()
302
303
go NewWorkspaceAppHealthReporter (
303
- a .logger , metadata .Apps , a .client .PostWorkspaceAgentAppHealth )(appReporterCtx )
304
+ a .logger , metadata .Apps , a .client .PostAppHealth )(appReporterCtx )
304
305
305
306
a .logger .Debug (ctx , "running tailnet with derpmap" , slog .F ("derpmap" , metadata .DERPMap ))
306
307
@@ -326,7 +327,7 @@ func (a *agent) run(ctx context.Context) error {
326
327
}
327
328
328
329
// Report statistics from the created network.
329
- cl , err := a .client .AgentReportStats (ctx , a .logger , func () * codersdk. AgentStats {
330
+ cl , err := a .client .ReportStats (ctx , a .logger , func () * agentsdk. Stats {
330
331
stats := network .ExtractTrafficStats ()
331
332
return convertAgentStats (stats )
332
333
})
@@ -373,7 +374,7 @@ func (a *agent) trackConnGoroutine(fn func()) error {
373
374
374
375
func (a * agent ) createTailnet (ctx context.Context , derpMap * tailcfg.DERPMap ) (_ * tailnet.Conn , err error ) {
375
376
network , err := tailnet .NewConn (& tailnet.Options {
376
- Addresses : []netip.Prefix {netip .PrefixFrom (codersdk .TailnetIP , 128 )},
377
+ Addresses : []netip.Prefix {netip .PrefixFrom (codersdk .WorkspaceAgentIP , 128 )},
377
378
DERPMap : derpMap ,
378
379
Logger : a .logger .Named ("tailnet" ),
379
380
EnableTrafficStats : true ,
@@ -387,7 +388,7 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (_
387
388
}
388
389
}()
389
390
390
- sshListener , err := network .Listen ("tcp" , ":" + strconv .Itoa (codersdk .TailnetSSHPort ))
391
+ sshListener , err := network .Listen ("tcp" , ":" + strconv .Itoa (codersdk .WorkspaceAgentSSHPort ))
391
392
if err != nil {
392
393
return nil , xerrors .Errorf ("listen on the ssh port: %w" , err )
393
394
}
@@ -419,7 +420,7 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (_
419
420
return nil , err
420
421
}
421
422
422
- reconnectingPTYListener , err := network .Listen ("tcp" , ":" + strconv .Itoa (codersdk .TailnetReconnectingPTYPort ))
423
+ reconnectingPTYListener , err := network .Listen ("tcp" , ":" + strconv .Itoa (codersdk .WorkspaceAgentReconnectingPTYPort ))
423
424
if err != nil {
424
425
return nil , xerrors .Errorf ("listen for reconnecting pty: %w" , err )
425
426
}
@@ -450,7 +451,7 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (_
450
451
if err != nil {
451
452
continue
452
453
}
453
- var msg codersdk.ReconnectingPTYInit
454
+ var msg codersdk.WorkspaceAgentReconnectingPTYInit
454
455
err = json .Unmarshal (data , & msg )
455
456
if err != nil {
456
457
continue
@@ -463,7 +464,7 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (_
463
464
return nil , err
464
465
}
465
466
466
- speedtestListener , err := network .Listen ("tcp" , ":" + strconv .Itoa (codersdk .TailnetSpeedtestPort ))
467
+ speedtestListener , err := network .Listen ("tcp" , ":" + strconv .Itoa (codersdk .WorkspaceAgentSpeedtestPort ))
467
468
if err != nil {
468
469
return nil , xerrors .Errorf ("listen for speedtest: %w" , err )
469
470
}
@@ -491,7 +492,7 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (_
491
492
return nil , err
492
493
}
493
494
494
- statisticsListener , err := network .Listen ("tcp" , ":" + strconv .Itoa (codersdk .TailnetStatisticsPort ))
495
+ statisticsListener , err := network .Listen ("tcp" , ":" + strconv .Itoa (codersdk .WorkspaceAgentStatisticsPort ))
495
496
if err != nil {
496
497
return nil , xerrors .Errorf ("listen for statistics: %w" , err )
497
498
}
@@ -531,7 +532,7 @@ func (a *agent) runCoordinator(ctx context.Context, network *tailnet.Conn) error
531
532
ctx , cancel := context .WithCancel (ctx )
532
533
defer cancel ()
533
534
534
- coordinator , err := a .client .ListenWorkspaceAgent (ctx )
535
+ coordinator , err := a .client .Listen (ctx )
535
536
if err != nil {
536
537
return err
537
538
}
@@ -700,8 +701,8 @@ func (a *agent) init(ctx context.Context) {
700
701
go a .runLoop (ctx )
701
702
}
702
703
703
- func convertAgentStats (counts map [netlogtype.Connection ]netlogtype.Counts ) * codersdk. AgentStats {
704
- stats := & codersdk. AgentStats {
704
+ func convertAgentStats (counts map [netlogtype.Connection ]netlogtype.Counts ) * agentsdk. Stats {
705
+ stats := & agentsdk. Stats {
705
706
ConnsByProto : map [string ]int64 {},
706
707
NumConns : int64 (len (counts )),
707
708
}
@@ -736,7 +737,7 @@ func (a *agent) createCommand(ctx context.Context, rawCommand string, env []stri
736
737
if rawMetadata == nil {
737
738
return nil , xerrors .Errorf ("no metadata was provided: %w" , err )
738
739
}
739
- metadata , valid := rawMetadata .(codersdk. WorkspaceAgentMetadata )
740
+ metadata , valid := rawMetadata .(agentsdk. Metadata )
740
741
if ! valid {
741
742
return nil , xerrors .Errorf ("metadata is the wrong type: %T" , metadata )
742
743
}
@@ -845,7 +846,7 @@ func (a *agent) handleSSHSession(session ssh.Session) (retErr error) {
845
846
session .DisablePTYEmulation ()
846
847
847
848
if ! isQuietLogin (session .RawCommand ()) {
848
- metadata , ok := a .metadata .Load ().(codersdk. WorkspaceAgentMetadata )
849
+ metadata , ok := a .metadata .Load ().(agentsdk. Metadata )
849
850
if ok {
850
851
err = showMOTD (session , metadata .MOTDFile )
851
852
if err != nil {
@@ -918,7 +919,7 @@ func (a *agent) handleSSHSession(session ssh.Session) (retErr error) {
918
919
return cmd .Wait ()
919
920
}
920
921
921
- func (a * agent ) handleReconnectingPTY (ctx context.Context , logger slog.Logger , msg codersdk.ReconnectingPTYInit , conn net.Conn ) (retErr error ) {
922
+ func (a * agent ) handleReconnectingPTY (ctx context.Context , logger slog.Logger , msg codersdk.WorkspaceAgentReconnectingPTYInit , conn net.Conn ) (retErr error ) {
922
923
defer conn .Close ()
923
924
924
925
connectionID := uuid .NewString ()
0 commit comments