@@ -155,35 +155,35 @@ func New(options Options) Agent {
155
155
hardCtx , hardCancel := context .WithCancel (context .Background ())
156
156
gracefulCtx , gracefulCancel := context .WithCancel (hardCtx )
157
157
a := & agent {
158
- tailnetListenPort : options .TailnetListenPort ,
159
- reconnectingPTYTimeout : options .ReconnectingPTYTimeout ,
160
- logger : options .Logger ,
161
- gracefulCtx : gracefulCtx ,
162
- gracefulCancel : gracefulCancel ,
163
- hardCtx : hardCtx ,
164
- hardCancel : hardCancel ,
165
- coordDisconnected : make (chan struct {}),
166
- environmentVariables : options .EnvironmentVariables ,
167
- client : options .Client ,
168
- exchangeToken : options .ExchangeToken ,
169
- filesystem : options .Filesystem ,
170
- logDir : options .LogDir ,
171
- tempDir : options .TempDir ,
172
- scriptDataDir : options .ScriptDataDir ,
173
- lifecycleUpdate : make (chan struct {}, 1 ),
174
- lifecycleReported : make (chan codersdk.WorkspaceAgentLifecycle , 1 ),
175
- lifecycleStates : []agentsdk.PostLifecycleRequest {{State : codersdk .WorkspaceAgentLifecycleCreated }},
176
- ignorePorts : options .IgnorePorts ,
177
- portCacheDuration : options .PortCacheDuration ,
178
- reportMetadataInterval : options .ReportMetadataInterval ,
179
- serviceBannerRefreshInterval : options .ServiceBannerRefreshInterval ,
180
- sshMaxTimeout : options .SSHMaxTimeout ,
181
- subsystems : options .Subsystems ,
182
- addresses : options .Addresses ,
183
- syscaller : options .Syscaller ,
184
- modifiedProcs : options .ModifiedProcesses ,
185
- processManagementTick : options .ProcessManagementTick ,
186
- logSender : agentsdk .NewLogSender (options .Logger ),
158
+ tailnetListenPort : options .TailnetListenPort ,
159
+ reconnectingPTYTimeout : options .ReconnectingPTYTimeout ,
160
+ logger : options .Logger ,
161
+ gracefulCtx : gracefulCtx ,
162
+ gracefulCancel : gracefulCancel ,
163
+ hardCtx : hardCtx ,
164
+ hardCancel : hardCancel ,
165
+ coordDisconnected : make (chan struct {}),
166
+ environmentVariables : options .EnvironmentVariables ,
167
+ client : options .Client ,
168
+ exchangeToken : options .ExchangeToken ,
169
+ filesystem : options .Filesystem ,
170
+ logDir : options .LogDir ,
171
+ tempDir : options .TempDir ,
172
+ scriptDataDir : options .ScriptDataDir ,
173
+ lifecycleUpdate : make (chan struct {}, 1 ),
174
+ lifecycleReported : make (chan codersdk.WorkspaceAgentLifecycle , 1 ),
175
+ lifecycleStates : []agentsdk.PostLifecycleRequest {{State : codersdk .WorkspaceAgentLifecycleCreated }},
176
+ ignorePorts : options .IgnorePorts ,
177
+ portCacheDuration : options .PortCacheDuration ,
178
+ reportMetadataInterval : options .ReportMetadataInterval ,
179
+ notificationBannersRefreshInterval : options .ServiceBannerRefreshInterval ,
180
+ sshMaxTimeout : options .SSHMaxTimeout ,
181
+ subsystems : options .Subsystems ,
182
+ addresses : options .Addresses ,
183
+ syscaller : options .Syscaller ,
184
+ modifiedProcs : options .ModifiedProcesses ,
185
+ processManagementTick : options .ProcessManagementTick ,
186
+ logSender : agentsdk .NewLogSender (options .Logger ),
187
187
188
188
prometheusRegistry : prometheusRegistry ,
189
189
metrics : newAgentMetrics (prometheusRegistry ),
@@ -193,7 +193,7 @@ func New(options Options) Agent {
193
193
// that gets closed on disconnection. This is used to wait for graceful disconnection from the
194
194
// coordinator during shut down.
195
195
close (a .coordDisconnected )
196
- a .serviceBanner .Store (new (codersdk.ServiceBannerConfig ))
196
+ a .notificationBanners .Store (new ([] codersdk.BannerConfig ))
197
197
a .sessionToken .Store (new (string ))
198
198
a .init ()
199
199
return a
@@ -231,14 +231,14 @@ type agent struct {
231
231
232
232
environmentVariables map [string ]string
233
233
234
- manifest atomic.Pointer [agentsdk.Manifest ] // manifest is atomic because values can change after reconnection.
235
- reportMetadataInterval time.Duration
236
- scriptRunner * agentscripts.Runner
237
- serviceBanner atomic.Pointer [codersdk.ServiceBannerConfig ] // serviceBanner is atomic because it is periodically updated.
238
- serviceBannerRefreshInterval time.Duration
239
- sessionToken atomic.Pointer [string ]
240
- sshServer * agentssh.Server
241
- sshMaxTimeout time.Duration
234
+ manifest atomic.Pointer [agentsdk.Manifest ] // manifest is atomic because values can change after reconnection.
235
+ reportMetadataInterval time.Duration
236
+ scriptRunner * agentscripts.Runner
237
+ notificationBanners atomic.Pointer [[] codersdk.BannerConfig ] // notificationBanners is atomic because it is periodically updated.
238
+ notificationBannersRefreshInterval time.Duration
239
+ sessionToken atomic.Pointer [string ]
240
+ sshServer * agentssh.Server
241
+ sshMaxTimeout time.Duration
242
242
243
243
lifecycleUpdate chan struct {}
244
244
lifecycleReported chan codersdk.WorkspaceAgentLifecycle
@@ -272,11 +272,11 @@ func (a *agent) TailnetConn() *tailnet.Conn {
272
272
func (a * agent ) init () {
273
273
// pass the "hard" context because we explicitly close the SSH server as part of graceful shutdown.
274
274
sshSrv , err := agentssh .NewServer (a .hardCtx , a .logger .Named ("ssh-server" ), a .prometheusRegistry , a .filesystem , & agentssh.Config {
275
- MaxTimeout : a .sshMaxTimeout ,
276
- MOTDFile : func () string { return a .manifest .Load ().MOTDFile },
277
- ServiceBanner : func () * codersdk.ServiceBannerConfig { return a .serviceBanner .Load () },
278
- UpdateEnv : a .updateCommandEnv ,
279
- WorkingDirectory : func () string { return a .manifest .Load ().Directory },
275
+ MaxTimeout : a .sshMaxTimeout ,
276
+ MOTDFile : func () string { return a .manifest .Load ().MOTDFile },
277
+ NotificationBanners : func () * [] codersdk.BannerConfig { return a .notificationBanners .Load () },
278
+ UpdateEnv : a .updateCommandEnv ,
279
+ WorkingDirectory : func () string { return a .manifest .Load ().Directory },
280
280
})
281
281
if err != nil {
282
282
panic (err )
@@ -709,23 +709,26 @@ func (a *agent) setLifecycle(state codersdk.WorkspaceAgentLifecycle) {
709
709
// (and must be done before the session actually starts).
710
710
func (a * agent ) fetchServiceBannerLoop (ctx context.Context , conn drpc.Conn ) error {
711
711
aAPI := proto .NewDRPCAgentClient (conn )
712
- ticker := time .NewTicker (a .serviceBannerRefreshInterval )
712
+ ticker := time .NewTicker (a .notificationBannersRefreshInterval )
713
713
defer ticker .Stop ()
714
714
for {
715
715
select {
716
716
case <- ctx .Done ():
717
717
return ctx .Err ()
718
718
case <- ticker .C :
719
- sbp , err := aAPI .GetServiceBanner (ctx , & proto.GetServiceBannerRequest {})
719
+ bannersProto , err := aAPI .GetNotificationBanners (ctx , & proto.GetNotificationBannersRequest {})
720
720
if err != nil {
721
721
if ctx .Err () != nil {
722
722
return ctx .Err ()
723
723
}
724
- a .logger .Error (ctx , "failed to update service banner " , slog .Error (err ))
724
+ a .logger .Error (ctx , "failed to update notification banners " , slog .Error (err ))
725
725
return err
726
726
}
727
- serviceBanner := agentsdk .ServiceBannerFromProto (sbp )
728
- a .serviceBanner .Store (& serviceBanner )
727
+ banners := make ([]codersdk.BannerConfig , 0 , len (bannersProto .NotificationBanners ))
728
+ for _ , bannerProto := range bannersProto .NotificationBanners {
729
+ banners = append (banners , agentsdk .BannerConfigFromProto (bannerProto ))
730
+ }
731
+ a .notificationBanners .Store (& banners )
729
732
}
730
733
}
731
734
}
@@ -757,15 +760,18 @@ func (a *agent) run() (retErr error) {
757
760
// redial the coder server and retry.
758
761
connMan := newAPIConnRoutineManager (a .gracefulCtx , a .hardCtx , a .logger , conn )
759
762
760
- connMan .start ("init service banner " , gracefulShutdownBehaviorStop ,
763
+ connMan .start ("init notification banners " , gracefulShutdownBehaviorStop ,
761
764
func (ctx context.Context , conn drpc.Conn ) error {
762
765
aAPI := proto .NewDRPCAgentClient (conn )
763
- sbp , err := aAPI .GetServiceBanner (ctx , & proto.GetServiceBannerRequest {})
766
+ bannersProto , err := aAPI .GetNotificationBanners (ctx , & proto.GetNotificationBannersRequest {})
764
767
if err != nil {
765
768
return xerrors .Errorf ("fetch service banner: %w" , err )
766
769
}
767
- serviceBanner := agentsdk .ServiceBannerFromProto (sbp )
768
- a .serviceBanner .Store (& serviceBanner )
770
+ banners := make ([]codersdk.BannerConfig , 0 , len (bannersProto .NotificationBanners ))
771
+ for _ , bannerProto := range bannersProto .NotificationBanners {
772
+ banners = append (banners , agentsdk .BannerConfigFromProto (bannerProto ))
773
+ }
774
+ a .notificationBanners .Store (& banners )
769
775
return nil
770
776
},
771
777
)
0 commit comments