diff --git a/cmd/run.go b/cmd/run.go index d9f676e4..c2bf64a5 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -44,6 +44,8 @@ func newRunCMD(version string) *cobra.Command { k8sConfig.Burst = c.K8sClient.Burst readinessProbe := config.NewReadinessProbe(c) + defer readinessProbe.Close() + resolver := config.NewResolver(c, k8sConfig) logger, err := resolver.Logger() if err != nil { diff --git a/pkg/config/readinessprobe.go b/pkg/config/readinessprobe.go index 2f613fac..949502f3 100644 --- a/pkg/config/readinessprobe.go +++ b/pkg/config/readinessprobe.go @@ -31,12 +31,15 @@ func (r *ReadinessProbe) Ready() { func (r *ReadinessProbe) Wait() { if r.required() && !r.running { r.running = <-r.ready - close(r.ready) zap.L().Debug("readiness probe finished") return } } +func (r *ReadinessProbe) Close() { + close(r.ready) +} + func (r *ReadinessProbe) Running() bool { return r.running } diff --git a/pkg/listener/sync_results.go b/pkg/listener/sync_results.go index 9ce9a1d2..44d435d7 100644 --- a/pkg/listener/sync_results.go +++ b/pkg/listener/sync_results.go @@ -13,7 +13,14 @@ import ( const SendSyncResults = "send_sync_results_listener" func NewSendSyncResultsListener(targets *target.Collection) report.SyncResultsListener { - targets.Reset(context.Background()) + ready := make(chan bool) + ok := false + go func() { + ok = targets.Reset(context.Background()) + if ok { + close(ready) + } + }() return func(rep v1alpha2.ReportInterface) { clients := targets.SyncClients() @@ -21,6 +28,10 @@ func NewSendSyncResultsListener(targets *target.Collection) report.SyncResultsLi return } + if !ok { + <-ready + } + wg := &sync.WaitGroup{} wg.Add(len(clients)) diff --git a/pkg/target/collection.go b/pkg/target/collection.go index df0f147e..090ba33a 100644 --- a/pkg/target/collection.go +++ b/pkg/target/collection.go @@ -59,7 +59,7 @@ func (c *Collection) Update(t *Target) { c.mx.Unlock() } -func (c *Collection) Reset(ctx context.Context) { +func (c *Collection) Reset(ctx context.Context) bool { clients := c.SyncClients() for _, c := range clients { @@ -67,6 +67,8 @@ func (c *Collection) Reset(ctx context.Context) { zap.L().Error("failed to reset target", zap.String("type", c.Type()), zap.String("name", c.Name())) } } + + return true } func (c *Collection) Targets() []*Target {