Skip to content

Commit 335b305

Browse files
committed
nfd-master: proper shutdown of nfd api informers
Stop blocking on event channels when the api controller is stopped. Ensures that the nfd API informer factory is properly shut down and all resources released when stop() is called. This eliminates a memory leak on re-configure events when leader election is enabled. (cherry picked from commit 2bb8a72)
1 parent 77fb7be commit 335b305

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pkg/nfd-master/nfd-api-controller.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ func (c *nfdController) updateOneNode(typ string, obj metav1.Object) {
187187
klog.ErrorS(err, "failed to determine node name for object", "type", typ, "object", klog.KObj(obj))
188188
return
189189
}
190-
c.updateOneNodeChan <- nodeName
190+
select {
191+
case c.updateOneNodeChan <- nodeName:
192+
case <-c.stopChan:
193+
}
191194
}
192195

193196
func (c *nfdController) updateAllNodes() {
@@ -198,7 +201,10 @@ func (c *nfdController) updateAllNodes() {
198201
}
199202

200203
func (c *nfdController) updateNodeFeatureGroup(nodeFeatureGroup string) {
201-
c.updateNodeFeatureGroupChan <- nodeFeatureGroup
204+
select {
205+
case c.updateNodeFeatureGroupChan <- nodeFeatureGroup:
206+
case <-c.stopChan:
207+
}
202208
}
203209

204210
func (c *nfdController) updateAllNodeFeatureGroups() {

pkg/nfd-master/nfd-master.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ func (m *nfdMaster) Run() error {
393393

394394
// Update all nodes when the configuration changes
395395
if m.nfdController != nil && nfdfeatures.NFDFeatureGate.Enabled(nfdfeatures.NodeFeatureAPI) && m.args.EnableNodeFeatureApi {
396-
m.nfdController.updateAllNodesChan <- struct{}{}
396+
m.nfdController.updateAllNodes()
397397
}
398398

399399
case <-m.stop:

0 commit comments

Comments
 (0)