Skip to content
This repository has been archived by the owner on Nov 25, 2022. It is now read-only.

Commit

Permalink
fix: stop events when watcher closes
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Mar 11, 2022
1 parent ed64842 commit 349be2f
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ func WatchKubeObjects(ctx context.Context, pubsub *pubsub.PubSub, watcher Watche
for {
select {
case <-ctx.Done():
return ctx.Err()
return nil
case <-tm.C:
check <- struct{}{}
case <-check:
if scWatch, err = watcher.Watch(ctx, opt.listOptions); err != nil {
if !k8serr.IsNotFound(err) {
return err
return nil
}
tm.Reset(time.Second * 10)
continue retry
Expand All @@ -126,13 +126,10 @@ func WatchKubeObjects(ctx context.Context, pubsub *pubsub.PubSub, watcher Watche

defer scWatch.Stop()

for {
select {
case <-ctx.Done():
return ctx.Err()
case evt := <-scWatch.ResultChan():
pubsub.Pub(evt, topic)
}
for evt := range scWatch.ResultChan() {
pubsub.Pub(evt, topic)
}

return nil
})
}

0 comments on commit 349be2f

Please sign in to comment.