-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(scheduler): remove node from cache when node selector no longer matches #5123
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -621,6 +621,15 @@ func (sc *SchedulerCache) SyncNode(nodeName string) error { | |
| } | ||
|
|
||
| if !sc.nodeCanAddCache(node) { | ||
| // If node exists in cache but no longer matches node selector, remove it | ||
| if _, exists := sc.Nodes[nodeName]; exists { | ||
| if deleteErr := sc.RemoveNode(nodeName); deleteErr != nil { | ||
| klog.Errorf("Failed to remove node <%s> from cache that no longer matches node selector: %s", | ||
| nodeName, deleteErr.Error()) | ||
| return deleteErr | ||
| } | ||
| klog.V(3).Infof("Node <%s> no longer matches node selector, removed from cache.", nodeName) | ||
| } | ||
|
Comment on lines
+624
to
+632
|
||
| return nil | ||
| } | ||
| nodeCopy := node.DeepCopy() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a potential race condition here. The check at line 625 reads
sc.Nodes[nodeName]without holding the lock, butRemoveNodeat line 626 acquires the lock and modifiessc.Nodes. Since there can be multiple concurrent node workers (see cache.go:822), another goroutine could remove the node between the check and the RemoveNode call, causing RemoveNode to return an error (see event_handlers.go:540-541). The exists check should be moved inside a lock or removed entirely since RemoveNode already handles the case where the node doesn't exist (it returns an error that could be ignored if it's already been removed).