From 68d6c78fab4e2403bd6cabc11c47f191e48e9e14 Mon Sep 17 00:00:00 2001 From: Bruno Bressi Date: Sat, 13 Jan 2024 18:39:12 +0100 Subject: [PATCH] fix: target manager is now properly checked for during shutdown Signed-off-by: Bruno Bressi --- pkg/sparrow/run.go | 4 ++-- pkg/sparrow/run_test.go | 11 +---------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/pkg/sparrow/run.go b/pkg/sparrow/run.go index 32528955..aa3c0aed 100644 --- a/pkg/sparrow/run.go +++ b/pkg/sparrow/run.go @@ -105,7 +105,7 @@ func (s *Sparrow) Run(ctx context.Context) error { s.cErr <- s.loader.Run(ctx) }() go func() { - if s.cfg.HasTargetManager() { + if s.tarMan != nil { s.cErr <- s.tarMan.Reconcile(ctx) } }() @@ -316,7 +316,7 @@ func (s *Sparrow) shutdown(ctx context.Context) { s.shutOnce.Do(func() { log.Info("Shutting down sparrow gracefully") var errS error - if s.cfg.HasTargetManager() { + if s.tarMan != nil { errS = s.tarMan.Shutdown(ctx) } errA := s.shutdownAPI(ctx) diff --git a/pkg/sparrow/run_test.go b/pkg/sparrow/run_test.go index f4643d22..8f50ba0a 100644 --- a/pkg/sparrow/run_test.go +++ b/pkg/sparrow/run_test.go @@ -243,20 +243,11 @@ func TestSparrow_Run_ContextCancel(t *testing.T) { File: config.FileLoaderConfig{Path: "../config/testdata/config.yaml"}, Interval: time.Second * 1, }, - TargetManager: config.TargetManagerConfig{ - CheckInterval: time.Second * 1, - RegistrationInterval: time.Second * 1, - UnhealthyThreshold: time.Second * 1, - Gitlab: config.GitlabTargetManagerConfig{ - BaseURL: "https://gitlab.com", - Token: "my-cool-token", - ProjectID: 42, - }, - }, } // start sparrow s := New(c) + s.tarMan = &gitlabmock.MockTargetManager{} ctx, cancel := context.WithCancel(context.Background()) go func() { err := s.Run(ctx)