Skip to content

Commit

Permalink
[draft] refactor retry to close watchFactory
Browse files Browse the repository at this point in the history
leverage stop channel on watch factory when periodic retry
stopchannel is called

Signed-off-by: Ben Pickard <bpickard@redhat.com>
  • Loading branch information
bpickard22 committed Oct 18, 2022
1 parent fed2993 commit f809693
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions go-controller/pkg/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ func NewNodeWatchFactory(ovnClientset *util.OVNClientset, nodeName string) (*Wat
return wf, nil
}

func (wf *WatchFactory) WaitForWatchFactoryStopChannel(stopChan chan struct{}) {
<-wf.stopChan
close(stopChan)
}

func (wf *WatchFactory) Shutdown() {
close(wf.stopChan)

Expand Down
6 changes: 5 additions & 1 deletion go-controller/pkg/ovn/obj_retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,10 @@ func (oc *Controller) iterateRetryResources(r *RetryObjs) {
// retryObjInterval seconds or when requested through retryChan.
func (oc *Controller) periodicallyRetryResources(r *RetryObjs) {
timer := time.NewTicker(retryObjInterval)
waitCh := make(chan struct{})
go func() {
oc.watchFactory.WaitForWatchFactoryStopChannel(waitCh)
}()
defer timer.Stop()
for {
select {
Expand All @@ -1119,7 +1123,7 @@ func (oc *Controller) periodicallyRetryResources(r *RetryObjs) {
oc.iterateRetryResources(r)
timer.Reset(retryObjInterval)

case <-oc.stopChan:
case <-waitCh:
klog.V(5).Infof("Stop channel got triggered: will stop retrying failed objects of type %s", r.oType)
return
}
Expand Down

0 comments on commit f809693

Please sign in to comment.