Skip to content

Commit

Permalink
Merge pull request #1798 from navin772/reset-karmorlog-evenChan
Browse files Browse the repository at this point in the history
fix(logs): reset eventChan everytime `KarmorLogStart()` is called
  • Loading branch information
Prateeknandle authored Jul 11, 2024
2 parents ffb252f + 74e9772 commit 998bfda
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/util/karmorlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,25 @@ func KarmorGetTargetAlert(timeout time.Duration, target *pb.Alert) (EventResult,
return res, nil
}

// drainEventChan drains all events from the eventChan.
func drainEventChan() {
if eventChan == nil {
return
}
for {
select {
case <-eventChan:
default:
return
}
}
}

// KarmorLogStart start observing for kubearmor telemetry events
func KarmorLogStart(logFilter string, ns string, op string, pod string) error {
// reset eventChan
drainEventChan()

if eventChan == nil {
eventChan = make(chan klog.EventInfo, maxEvents)
}
Expand Down

0 comments on commit 998bfda

Please sign in to comment.