Skip to content

Commit 2bb8a72

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.
1 parent 5a5b9e3 commit 2bb8a72

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
@@ -206,7 +206,10 @@ func (c *nfdController) updateOneNode(typ string, obj metav1.Object) {
206206
klog.ErrorS(err, "failed to determine node name for object", "type", typ, "object", klog.KObj(obj))
207207
return
208208
}
209-
c.updateOneNodeChan <- nodeName
209+
select {
210+
case c.updateOneNodeChan <- nodeName:
211+
case <-c.stopChan:
212+
}
210213
}
211214

212215
func (c *nfdController) updateAllNodes() {
@@ -217,7 +220,10 @@ func (c *nfdController) updateAllNodes() {
217220
}
218221

219222
func (c *nfdController) updateNodeFeatureGroup(nodeFeatureGroup string) {
220-
c.updateNodeFeatureGroupChan <- nodeFeatureGroup
223+
select {
224+
case c.updateNodeFeatureGroupChan <- nodeFeatureGroup:
225+
case <-c.stopChan:
226+
}
221227
}
222228

223229
func (c *nfdController) updateAllNodeFeatureGroups() {

pkg/nfd-master/nfd-master.go

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

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

398398
case <-m.stop:

0 commit comments

Comments
 (0)