Skip to content

Commit 42cd5ca

Browse files
committed
Fix errors
1 parent 419a422 commit 42cd5ca

File tree

1 file changed

+50
-50
lines changed

1 file changed

+50
-50
lines changed

agent/cmd/cmd.go

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,19 @@ func WithLogger(l *zap.Logger) Option {
103103

104104
// App represents the agent application with all its components.
105105
type App struct {
106-
config Config
107-
flags *Flags
108-
stats tally.Scope
109-
logger *zap.Logger
110-
106+
config Config
107+
flags *Flags
108+
stats tally.Scope
109+
logger *zap.Logger
110+
111111
// Components
112-
peerContext *core.PeerContext
113-
cads *store.CADownloadStore
114-
scheduler scheduler.ReloadableScheduler
115-
tagClient tagclient.Client
116-
registry *registry.Registry
117-
agentServer *agentserver.Server
118-
112+
peerContext core.PeerContext
113+
cads *store.CADownloadStore
114+
scheduler scheduler.ReloadableScheduler
115+
tagClient tagclient.Client
116+
registry *registry.Registry
117+
agentServer *agentserver.Server
118+
119119
// Cleanup functions
120120
cleanup []func()
121121
}
@@ -126,27 +126,27 @@ func NewApp(flags *Flags, opts ...Option) (*App, error) {
126126
flags: flags,
127127
cleanup: make([]func(), 0),
128128
}
129-
129+
130130
if err := app.parseOptions(opts...); err != nil {
131131
return nil, fmt.Errorf("parse options: %w", err)
132132
}
133-
133+
134134
if err := app.validateFlags(); err != nil {
135135
return nil, fmt.Errorf("validate flags: %w", err)
136136
}
137-
137+
138138
if err := app.loadConfig(); err != nil {
139139
return nil, fmt.Errorf("load config: %w", err)
140140
}
141-
141+
142142
if err := app.setupLogging(); err != nil {
143143
return nil, fmt.Errorf("setup logging: %w", err)
144144
}
145-
145+
146146
if err := app.setupMetrics(); err != nil {
147147
return nil, fmt.Errorf("setup metrics: %w", err)
148148
}
149-
149+
150150
return app, nil
151151
}
152152

@@ -155,7 +155,7 @@ func (a *App) parseOptions(opts ...Option) error {
155155
for _, o := range opts {
156156
o(&overrides)
157157
}
158-
158+
159159
if overrides.config != nil {
160160
a.config = *overrides.config
161161
}
@@ -165,7 +165,7 @@ func (a *App) parseOptions(opts ...Option) error {
165165
if overrides.logger != nil {
166166
a.logger = overrides.logger
167167
}
168-
168+
169169
return nil
170170
}
171171

@@ -183,7 +183,7 @@ func (a *App) validateFlags() error {
183183
}
184184

185185
func (a *App) loadConfig() error {
186-
if a.config == (Config{}) {
186+
if a.config.PeerIDFactory == "" && a.flags.ConfigFile != "" {
187187
if err := configutil.Load(a.flags.ConfigFile, &a.config); err != nil {
188188
return fmt.Errorf("load config file: %w", err)
189189
}
@@ -216,7 +216,7 @@ func (a *App) setupMetrics() error {
216216
a.stats = s
217217
a.cleanup = append(a.cleanup, func() { closer.Close() })
218218
}
219-
219+
220220
go metrics.EmitVersion(a.stats)
221221
return nil
222222
}
@@ -230,13 +230,13 @@ func (a *App) setupPeerContext() error {
230230
}
231231
peerIP = localIP
232232
}
233-
233+
234234
pctx, err := core.NewPeerContext(
235235
a.config.PeerIDFactory, a.flags.Zone, a.flags.KrakenCluster, peerIP, a.flags.PeerPort, false)
236236
if err != nil {
237237
return fmt.Errorf("create peer context: %w", err)
238238
}
239-
239+
240240
a.peerContext = pctx
241241
return nil
242242
}
@@ -255,25 +255,25 @@ func (a *App) setupScheduler() error {
255255
if err != nil {
256256
return fmt.Errorf("create network event producer: %w", err)
257257
}
258-
258+
259259
trackers, err := a.config.Tracker.Build()
260260
if err != nil {
261261
return fmt.Errorf("build tracker upstream: %w", err)
262262
}
263263
go trackers.Monitor(nil)
264-
264+
265265
tls, err := a.config.TLS.BuildClient()
266266
if err != nil {
267267
return fmt.Errorf("build client TLS config: %w", err)
268268
}
269-
269+
270270
announceClient := announceclient.New(a.peerContext, trackers, tls)
271271
sched, err := scheduler.NewAgentScheduler(
272272
a.config.Scheduler, a.stats, a.peerContext, a.cads, netevents, trackers, announceClient, tls)
273273
if err != nil {
274274
return fmt.Errorf("create scheduler: %w", err)
275275
}
276-
276+
277277
a.scheduler = sched
278278
return nil
279279
}
@@ -283,52 +283,52 @@ func (a *App) setupTagClient() error {
283283
if err != nil {
284284
return fmt.Errorf("build build-index upstream: %w", err)
285285
}
286-
286+
287287
tls, err := a.config.TLS.BuildClient()
288288
if err != nil {
289289
return fmt.Errorf("build client TLS config: %w", err)
290290
}
291-
291+
292292
a.tagClient = tagclient.NewClusterClient(buildIndexes, tls)
293293
return nil
294294
}
295295

296296
func (a *App) setupRegistry() error {
297297
transferer := transfer.NewReadOnlyTransferer(a.stats, a.cads, a.tagClient, a.scheduler)
298-
298+
299299
registry, err := a.config.Registry.Build(a.config.Registry.ReadOnlyParameters(transferer, a.cads, a.stats))
300300
if err != nil {
301301
return fmt.Errorf("init registry: %w", err)
302302
}
303-
303+
304304
a.registry = registry
305305
return nil
306306
}
307307

308308
func (a *App) setupAgentServer() error {
309309
registryAddr := fmt.Sprintf("127.0.0.1:%d", a.flags.AgentRegistryPort)
310-
310+
311311
containerRuntimeCfg := a.config.ContainerRuntime
312312
dockerdaemonCfg := dockerdaemon.Config{}
313313
if a.config.DockerDaemon != dockerdaemonCfg {
314314
log.Warn("please move docker config under \"container_runtime\"")
315315
containerRuntimeCfg.Docker = a.config.DockerDaemon
316316
}
317-
317+
318318
containerRuntimeFactory, err := containerruntime.NewFactory(containerRuntimeCfg, registryAddr)
319319
if err != nil {
320320
return fmt.Errorf("create container runtime factory: %w", err)
321321
}
322-
322+
323323
tls, err := a.config.TLS.BuildClient()
324324
if err != nil {
325325
return fmt.Errorf("build client TLS config: %w", err)
326326
}
327-
327+
328328
announceClient := announceclient.New(a.peerContext, nil, tls)
329329
a.agentServer = agentserver.New(
330330
a.config.AgentServer, a.stats, a.cads, a.scheduler, a.tagClient, announceClient, containerRuntimeFactory)
331-
331+
332332
return nil
333333
}
334334

@@ -345,42 +345,42 @@ func (a *App) Initialize() error {
345345
{"registry", a.setupRegistry},
346346
{"agent server", a.setupAgentServer},
347347
}
348-
348+
349349
for _, step := range setupSteps {
350350
if err := step.fn(); err != nil {
351351
return fmt.Errorf("setup %s: %w", step.name, err)
352352
}
353353
}
354-
354+
355355
return nil
356356
}
357357

358358
// Run starts the agent application.
359359
func (a *App) Run(ctx context.Context) error {
360360
agentAddr := fmt.Sprintf(":%d", a.flags.AgentServerPort)
361361
log.Infof("Starting agent server on %s", agentAddr)
362-
362+
363363
agentSrv := &http.Server{
364364
Addr: agentAddr,
365365
Handler: a.agentServer.Handler(),
366366
}
367-
367+
368368
go func() {
369369
if err := agentSrv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
370370
log.Errorf("Agent server error: %v", err)
371371
}
372372
}()
373-
373+
374374
log.Info("Starting registry...")
375375
go func() {
376376
if err := a.registry.ListenAndServe(); err != nil {
377377
log.Errorf("Registry error: %v", err)
378378
}
379379
}()
380-
380+
381381
// Start heartbeat
382382
go a.heartbeat()
383-
383+
384384
// Start nginx
385385
nginxDone := make(chan error, 1)
386386
go func() {
@@ -394,7 +394,7 @@ func (a *App) Run(ctx context.Context) error {
394394
nginx.WithTLS(a.config.TLS))
395395
nginxDone <- err
396396
}()
397-
397+
398398
// Wait for context cancellation or nginx error
399399
select {
400400
case <-ctx.Done():
@@ -409,16 +409,16 @@ func (a *App) shutdown(agentSrv *http.Server) error {
409409
// Shutdown agent server gracefully
410410
shutdownCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
411411
defer cancel()
412-
412+
413413
if err := agentSrv.Shutdown(shutdownCtx); err != nil {
414414
log.Errorf("Agent server shutdown error: %v", err)
415415
}
416-
416+
417417
// Run cleanup functions
418418
for i := len(a.cleanup) - 1; i >= 0; i-- {
419419
a.cleanup[i]()
420420
}
421-
421+
422422
return nil
423423
}
424424

@@ -435,11 +435,11 @@ func Run(flags *Flags, opts ...Option) {
435435
if err != nil {
436436
log.Fatalf("Failed to create app: %v", err)
437437
}
438-
438+
439439
if err := app.Initialize(); err != nil {
440440
log.Fatalf("Failed to initialize app: %v", err)
441441
}
442-
442+
443443
ctx := context.Background()
444444
if err := app.Run(ctx); err != nil {
445445
log.Fatalf("App run error: %v", err)

0 commit comments

Comments
 (0)