Skip to content

Commit 0d3c1ac

Browse files
committed
nfd-master: explicit state variable for the node updater pool
1 parent a851aae commit 0d3c1ac

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

pkg/nfd-master/updater-pool.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
)
3232

3333
type updaterPool struct {
34+
started bool
3435
queue workqueue.RateLimitingInterface
3536
nfgQueue workqueue.RateLimitingInterface
3637
sync.RWMutex
@@ -129,16 +130,11 @@ func (u *updaterPool) start(parallelism int) {
129130
u.Lock()
130131
defer u.Unlock()
131132

132-
if u.queue != nil && !u.queue.ShuttingDown() {
133+
if u.started {
133134
klog.InfoS("the NFD master updater pool is already running.")
134135
return
135136
}
136137

137-
if u.nfgQueue != nil && !u.nfgQueue.ShuttingDown() {
138-
klog.InfoS("the NFD master node feature group updater pool is already running.")
139-
return
140-
}
141-
142138
klog.InfoS("starting the NFD master updater pool", "parallelism", parallelism)
143139

144140
// Create ratelimiter. Mimic workqueue.DefaultControllerRateLimiter() but
@@ -158,18 +154,14 @@ func (u *updaterPool) start(parallelism int) {
158154
go u.runNodeFeatureGroupUpdater(u.nfgQueue)
159155
}
160156
}
157+
u.started = true
161158
}
162159

163160
func (u *updaterPool) stop() {
164161
u.Lock()
165162
defer u.Unlock()
166163

167-
if u.queue == nil || u.queue.ShuttingDown() {
168-
klog.InfoS("the NFD master updater pool is not running.")
169-
return
170-
}
171-
172-
if u.nfgQueue == nil || u.nfgQueue.ShuttingDown() {
164+
if !u.started {
173165
klog.InfoS("the NFD master updater pool is not running.")
174166
return
175167
}
@@ -179,6 +171,13 @@ func (u *updaterPool) stop() {
179171
u.wg.Wait()
180172
u.nfgQueue.ShutDown()
181173
u.nfgWg.Wait()
174+
u.started = false
175+
}
176+
177+
func (u *updaterPool) running() bool {
178+
u.RLock()
179+
defer u.RUnlock()
180+
return u.started
182181
}
183182

184183
func (u *updaterPool) addNode(nodeName string) {

pkg/nfd-master/updater-pool_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,15 @@ func TestUpdaterStart(t *testing.T) {
3737
fakeMaster := newFakeMaster()
3838
updaterPool := newFakeupdaterPool(fakeMaster)
3939

40+
Convey("New node updater pool should report running=false", t, func() {
41+
So(updaterPool.running(), ShouldBeFalse)
42+
})
43+
4044
Convey("When starting the node updater pool", t, func() {
4145
updaterPool.start(10)
46+
Convey("Running node updater pool should report running=true", func() {
47+
So(updaterPool.running(), ShouldBeTrue)
48+
})
4249
q := updaterPool.queue
4350
Convey("Node updater pool queue properties should change", func() {
4451
So(q, ShouldNotBeNil)
@@ -57,9 +64,15 @@ func TestNodeUpdaterStop(t *testing.T) {
5764
updaterPool := newFakeupdaterPool(fakeMaster)
5865

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

6171
Convey("When stoping the node updater pool", t, func() {
6272
updaterPool.stop()
73+
Convey("Stopped node updater pool should report running=false", func() {
74+
So(updaterPool.running(), ShouldBeFalse)
75+
})
6376
Convey("Node updater pool queue should be removed", func() {
6477
// Wait for the wg.Done()
6578
So(func() interface{} {

0 commit comments

Comments
 (0)