Skip to content

Commit

Permalink
Add watchFactory waitgroup
Browse files Browse the repository at this point in the history
Add waitgroup property to watchFactory

Use the waitgroup to ensure that we block shutdown until the retry loop
is done

Signed-off-by: Ben Pickard <bpickard@redhat.com>
  • Loading branch information
bpickard22 committed Oct 25, 2022
1 parent e1a3919 commit 4294466
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions go-controller/pkg/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package factory
import (
"fmt"
"reflect"
"sync"
"sync/atomic"
"time"

Expand Down Expand Up @@ -60,6 +61,7 @@ type WatchFactory struct {
informers map[reflect.Type]*informer

stopChan chan struct{}
wg sync.WaitGroup
}

// WatchFactory implements the ObjectCacheInterface interface.
Expand Down Expand Up @@ -347,8 +349,10 @@ func NewNodeWatchFactory(ovnClientset *util.OVNClientset, nodeName string) (*Wat
}

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

func (wf *WatchFactory) Shutdown() {
Expand All @@ -358,6 +362,8 @@ func (wf *WatchFactory) Shutdown() {
for _, inf := range wf.informers {
inf.shutdown()
}

wf.wg.Wait()
}

func getObjectMeta(objType reflect.Type, obj interface{}) (*metav1.ObjectMeta, error) {
Expand Down

0 comments on commit 4294466

Please sign in to comment.