From 349be2f96f885330317280814cc0aaec05fc4e1e Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Thu, 10 Mar 2022 20:49:53 -0500 Subject: [PATCH] fix: stop events when watcher closes Signed-off-by: Artur Troian --- types.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/types.go b/types.go index 27ceb61..8ca72d9 100644 --- a/types.go +++ b/types.go @@ -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 @@ -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 }) }