Skip to content

Commit

Permalink
fix(k8sagent): retry watcher if it stops; fixes #416
Browse files Browse the repository at this point in the history
  • Loading branch information
lizthegrey committed Jun 3, 2024
1 parent a0d5bd6 commit 0af592b
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions k8sagent/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,26 @@ func runInformer(

watchlist := &cache.ListWatch{ListFunc: listFunc, WatchFunc: watchFunc}
resyncPeriod := time.Minute
_, controller := cache.NewInformer(
watchlist,
&v1.Pod{},
resyncPeriod,
handler,
)

logrus.WithFields(logrus.Fields{
"labelSelector": labelSelector,
"namespace": namespace,
"fieldSelector": fieldSelector,
}).Debug("Starting informer")
go controller.Run(wait.NeverStop)
go func() {
for {
_, controller := cache.NewInformer(
watchlist,
&v1.Pod{},
resyncPeriod,
handler,
)

logrus.WithFields(logrus.Fields{
"labelSelector": labelSelector,
"namespace": namespace,
"fieldSelector": fieldSelector,
}).Debug("Starting informer")
controller.Run(wait.NeverStop)
logrus.WithFields(logrus.Fields{
"labelSelector": labelSelector,
"namespace": namespace,
"fieldSelector": fieldSelector,
}).Warning("Informer unexpectedly stopped")
}
}()
}

0 comments on commit 0af592b

Please sign in to comment.