Skip to content

Commit 95d9f46

Browse files
committed
fix shadows
1 parent e100ec8 commit 95d9f46

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

cmd/bootstrap_manager.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,17 @@ func (b *BootstrapManager) Start() error {
7474
defer zl.Close()
7575

7676
// Check what mode should be activated
77+
var cfg *rest.Config
7778
if kubeconfig := os.Getenv("KUBECONFIG"); kubeconfig != "" {
7879
fmt.Println("KUBECONFIG detected, using kubeconfig: ", kubeconfig)
79-
cfg, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
80+
cfg, err = clientcmd.BuildConfigFromFlags("", kubeconfig)
8081
if err != nil {
8182
return fmt.Errorf("creating controller-runtime manager: %w", err)
8283
}
8384
return b.startDaemon(cfg, daemonConfig, zl)
8485
}
8586

86-
cfg, err := kcfg.GetConfig()
87+
cfg, err = kcfg.GetConfig()
8788
if err != nil {
8889
sm, err := NewStandaloneDaemon(daemonConfig, zl)
8990
if err != nil {

cmd/standalone_daemon.go

+21-21
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ type StandaloneDaemon struct {
2929
tel telemetry.Telemetry
3030
}
3131

32-
func NewStandaloneDaemon(config *config.Config, zl *log.ZapLogger) (*StandaloneDaemon, error) {
32+
func NewStandaloneDaemon(cfg *config.Config, zl *log.ZapLogger) (*StandaloneDaemon, error) {
3333
fmt.Println("starting Standalone Retina daemon")
3434
sdLogger := zl.Named("standalone-daemon")
3535

3636
var tel telemetry.Telemetry
3737
var err error
38-
if config.EnableTelemetry {
38+
if cfg.EnableTelemetry {
3939
if buildinfo.ApplicationInsightsID == "" {
4040
panic("telemetry enabled, but ApplicationInsightsID is empty")
4141
}
4242
sdLogger.Info("telemetry enabled", zap.String("applicationInsightsID", buildinfo.ApplicationInsightsID))
4343
tel, err = telemetry.NewAppInsightsTelemetryClient("standalone-retina-agent", map[string]string{
4444
"version": buildinfo.Version,
45-
"plugins": strings.Join(config.EnabledPlugin, `,`),
45+
"plugins": strings.Join(cfg.EnabledPlugin, `,`),
4646
})
4747
if err != nil {
4848
sdLogger.Error("failed to create telemetry client", zap.Error(err))
@@ -54,62 +54,62 @@ func NewStandaloneDaemon(config *config.Config, zl *log.ZapLogger) (*StandaloneD
5454
}
5555

5656
pMgr, err := pm.NewPluginManager(
57-
config,
57+
cfg,
5858
tel,
5959
)
6060
if err != nil {
61-
return nil, err
61+
return nil, fmt.Errorf("failed to create plugin manager: %w", err)
6262
}
6363

6464
// create HTTP server for API server
6565
httpServer := sm.NewHTTPServer(
66-
config.APIServer.Host,
67-
config.APIServer.Port,
66+
cfg.APIServer.Host,
67+
cfg.APIServer.Port,
6868
)
6969

7070
return &StandaloneDaemon{
7171
l: sdLogger,
7272
httpServer: httpServer,
7373
pluginManager: pMgr,
74-
config: config,
74+
config: cfg,
7575
tel: tel,
7676
}, nil
7777
}
7878

79-
func (sm *StandaloneDaemon) Start() {
80-
sm.l.Info("Starting standalone daemon")
79+
func (sd *StandaloneDaemon) Start() {
80+
sd.l.Info("Starting standalone daemon")
8181

8282
// Start the HTTP server and initialize the cache
83-
if err := sm.httpServer.Init(); err != nil {
84-
sm.l.Error("failed to start http server")
83+
if err := sd.httpServer.Init(); err != nil {
84+
sd.l.Error("failed to start http server")
8585
}
86-
sm.cache = cache.NewStandaloneCache()
86+
sd.cache = cache.NewStandaloneCache()
8787

8888
ctx, cancel := context.WithCancel(context.Background())
8989
defer cancel()
9090

9191
// start heartbeat goroutine for application insights
92-
go sm.tel.Heartbeat(ctx, sm.config.TelemetryInterval)
92+
go sd.tel.Heartbeat(ctx, sd.config.TelemetryInterval)
9393

9494
var g *errgroup.Group
9595
g, ctx = errgroup.WithContext(ctx)
9696

9797
g.Go(func() error {
98-
return sm.pluginManager.Start(ctx)
98+
return sd.pluginManager.Start(ctx)
9999
})
100100
g.Go(func() error {
101-
return sm.httpServer.Start(ctx)
101+
return sd.httpServer.Start(ctx)
102102
})
103103

104104
if err := g.Wait(); err != nil {
105-
sm.l.Panic("Error running standalone daemon", zap.Error(err))
105+
sd.l.Panic("Error running standalone daemon", zap.Error(err))
106106
}
107107

108-
sm.l.Info("Started standalone daemon")
108+
sd.l.Info("Started standalone daemon")
109109
}
110110

111-
func (sm *StandaloneDaemon) Stop() {
111+
func (sd *StandaloneDaemon) Stop() {
112112
// Clean up plugin resources
113-
sm.pluginManager.Stop()
114-
sm.l.Info("Stopped the standalone daemon")
113+
sd.pluginManager.Stop()
114+
sd.l.Info("Stopped the standalone daemon")
115115
}

0 commit comments

Comments
 (0)