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: implement ratelimiter for nfd api updates #990

Merged
Merged
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
28 changes: 23 additions & 5 deletions pkg/nfd-master/nfd-master.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,34 @@ func (m *nfdMaster) runGrpcServer(errChan chan<- error) {

// nfdAPIUpdateHandler handles events from the nfd API controller.
func (m *nfdMaster) nfdAPIUpdateHandler() {
updateAll := false
updateNodes := make(map[string]struct{})
rateLimit := time.After(time.Second)
for {
select {
case <-m.nfdController.updateAllNodesChan:
if err := m.nfdAPIUpdateAllNodes(); err != nil {
klog.Error(err)
}
updateAll = true
case nodeName := <-m.nfdController.updateOneNodeChan:
if err := m.nfdAPIUpdateOneNode(nodeName); err != nil {
klog.Error(err)
updateNodes[nodeName] = struct{}{}
case <-rateLimit:
// Check what we need to do
// TODO: we might want to update multiple nodes in parallel
if updateAll {
if err := m.nfdAPIUpdateAllNodes(); err != nil {
klog.Error(err)
}
} else {
for nodeName := range updateNodes {
if err := m.nfdAPIUpdateOneNode(nodeName); err != nil {
klog.Error(err)
}
}
}

// Reset "work queue" and timer
updateAll = false
updateNodes = make(map[string]struct{})
rateLimit = time.After(time.Second)
}
}
}
Expand Down