events: prevent defer in loop

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
pull/3628/head
Hidde Beydals 2 years ago
parent 34220fd514
commit c0916edc44
No known key found for this signature in database
GPG Key ID: 979F380FC2341744

@ -199,7 +199,6 @@ func eventsCmdWatchRun(ctx context.Context, kubeclient client.WithWatch, listOpt
if err != nil { if err != nil {
return err return err
} }
defer eventWatch.Stop()
firstIteration := true firstIteration := true
@ -234,15 +233,19 @@ func eventsCmdWatchRun(ctx context.Context, kubeclient client.WithWatch, listOpt
if err != nil { if err != nil {
return err return err
} }
defer refEventWatch.Stop() go func() {
go receiveEventChan(ctx, refEventWatch, handleEvent) err := receiveEventChan(ctx, refEventWatch, handleEvent)
if err != nil {
logger.Failuref("error watching events: %s", err.Error())
}
}()
} }
return receiveEventChan(ctx, eventWatch, handleEvent) return receiveEventChan(ctx, eventWatch, handleEvent)
} }
func receiveEventChan(ctx context.Context, eventWatch watch.Interface, f func(e watch.Event) error) error { func receiveEventChan(ctx context.Context, eventWatch watch.Interface, f func(e watch.Event) error) error {
defer eventWatch.Stop()
for { for {
select { select {
case e, ok := <-eventWatch.ResultChan(): case e, ok := <-eventWatch.ResultChan():

Loading…
Cancel
Save