Skip to content

Commit

Permalink
Merge pull request #1844 from marquiz/devel/updater-pool-started
Browse files Browse the repository at this point in the history
nfd-master: explicit state variable for the node updater pool
  • Loading branch information
k8s-ci-robot committed Aug 19, 2024
2 parents a851aae + 0d3c1ac commit df7f65c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
23 changes: 11 additions & 12 deletions pkg/nfd-master/updater-pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
)

type updaterPool struct {
started bool
queue workqueue.RateLimitingInterface
nfgQueue workqueue.RateLimitingInterface
sync.RWMutex
Expand Down Expand Up @@ -129,16 +130,11 @@ func (u *updaterPool) start(parallelism int) {
u.Lock()
defer u.Unlock()

if u.queue != nil && !u.queue.ShuttingDown() {
if u.started {
klog.InfoS("the NFD master updater pool is already running.")
return
}

if u.nfgQueue != nil && !u.nfgQueue.ShuttingDown() {
klog.InfoS("the NFD master node feature group updater pool is already running.")
return
}

klog.InfoS("starting the NFD master updater pool", "parallelism", parallelism)

// Create ratelimiter. Mimic workqueue.DefaultControllerRateLimiter() but
Expand All @@ -158,18 +154,14 @@ func (u *updaterPool) start(parallelism int) {
go u.runNodeFeatureGroupUpdater(u.nfgQueue)
}
}
u.started = true
}

func (u *updaterPool) stop() {
u.Lock()
defer u.Unlock()

if u.queue == nil || u.queue.ShuttingDown() {
klog.InfoS("the NFD master updater pool is not running.")
return
}

if u.nfgQueue == nil || u.nfgQueue.ShuttingDown() {
if !u.started {
klog.InfoS("the NFD master updater pool is not running.")
return
}
Expand All @@ -179,6 +171,13 @@ func (u *updaterPool) stop() {
u.wg.Wait()
u.nfgQueue.ShutDown()
u.nfgWg.Wait()
u.started = false
}

func (u *updaterPool) running() bool {
u.RLock()
defer u.RUnlock()
return u.started
}

func (u *updaterPool) addNode(nodeName string) {
Expand Down
13 changes: 13 additions & 0 deletions pkg/nfd-master/updater-pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,15 @@ func TestUpdaterStart(t *testing.T) {
fakeMaster := newFakeMaster()
updaterPool := newFakeupdaterPool(fakeMaster)

Convey("New node updater pool should report running=false", t, func() {
So(updaterPool.running(), ShouldBeFalse)
})

Convey("When starting the node updater pool", t, func() {
updaterPool.start(10)
Convey("Running node updater pool should report running=true", func() {
So(updaterPool.running(), ShouldBeTrue)
})
q := updaterPool.queue
Convey("Node updater pool queue properties should change", func() {
So(q, ShouldNotBeNil)
Expand All @@ -57,9 +64,15 @@ func TestNodeUpdaterStop(t *testing.T) {
updaterPool := newFakeupdaterPool(fakeMaster)

updaterPool.start(10)
Convey("Running node updater pool should report running=true", t, func() {
So(updaterPool.running(), ShouldBeTrue)
})

Convey("When stoping the node updater pool", t, func() {
updaterPool.stop()
Convey("Stopped node updater pool should report running=false", func() {
So(updaterPool.running(), ShouldBeFalse)
})
Convey("Node updater pool queue should be removed", func() {
// Wait for the wg.Done()
So(func() interface{} {
Expand Down

0 comments on commit df7f65c

Please sign in to comment.