Skip to content

Commit cb3ea4a

Browse files
authored
Merge pull request #69 from kubescape/bugfix/watcher-nil
Fixing watcher error when reading from channel
2 parents 9613462 + 2ab21ca commit cb3ea4a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

pkg/watcher/watcher.go

+11
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ func (w *Watcher) Start(notifyF WatchNotifyFunctions, gvr schema.GroupVersionRes
9999
go func() {
100100
// Watch for events
101101
for {
102+
if w.watcher == nil {
103+
w.watcher, err = w.client.Resource(gvr).Namespace("").Watch(context.TODO(), listOptions)
104+
if err != nil {
105+
if notifyF.OnError != nil {
106+
notifyF.OnError(err)
107+
} else {
108+
log.Printf("watcher error: %v", err)
109+
}
110+
return
111+
}
112+
}
102113
event, ok := <-w.watcher.ResultChan()
103114
if !ok {
104115
if w.running {

0 commit comments

Comments
 (0)