Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nfd-master: explicit state variable for the node updater pool #1844

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member

@TessaIO TessaIO Aug 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't we use the u.running function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As that's also behind a lock

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect thanks, didn't see the first lock 😄

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