Skip to content

Commit

Permalink
try passing wait group in
Browse files Browse the repository at this point in the history
  • Loading branch information
tvoran committed Sep 13, 2024
1 parent f7b97ce commit 16efd83
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions controllers/vaultstaticsecret_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,7 @@ func (r *VaultStaticSecretReconciler) ensureEventWatcher(ctx context.Context, o
// being garbage collected before the goroutine is started/evaluated
wg := &sync.WaitGroup{}
wg.Add(1)
go func(ctx context.Context, o *secretsv1beta1.VaultStaticSecret, wsClient *vault.WebsocketClient, stoppedCh chan struct{}) {
defer wg.Done()
go r.getEvents(watchCtx, o, wsClient, stoppedCh)
}(ctx, o, wsClient, stoppedCh)
go r.getEvents(watchCtx, o, wsClient, stoppedCh, wg)
wg.Wait()

return nil
Expand All @@ -321,7 +318,8 @@ func (r *VaultStaticSecretReconciler) unWatchEvents(o *secretsv1beta1.VaultStati

// getEvents calls streamStaticSecretEvents in a loop, collecting and responding
// to any errors returned.
func (r *VaultStaticSecretReconciler) getEvents(ctx context.Context, o *secretsv1beta1.VaultStaticSecret, wsClient *vault.WebsocketClient, stoppedCh chan struct{}) {
func (r *VaultStaticSecretReconciler) getEvents(ctx context.Context, o *secretsv1beta1.VaultStaticSecret, wsClient *vault.WebsocketClient, stoppedCh chan struct{}, wg *sync.WaitGroup) {
wg.Done()
logger := log.FromContext(ctx).WithName("getEvents")
name := client.ObjectKeyFromObject(o)
defer func() {
Expand Down

0 comments on commit 16efd83

Please sign in to comment.