-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(scheduler): remove node from cache when node-selector label is removed #5145
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 1 commit
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,11 @@ func (sc *SchedulerCache) SyncNode(nodeName string) error { | |||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if !sc.nodeCanAddCache(node) { | ||||||||||||||||||||||||||||||||
| if deleteErr := sc.RemoveNode(nodeName); deleteErr != nil { | ||||||||||||||||||||||||||||||||
| klog.Errorf("Failed to remove node <%s> from cache after label change: %s", nodeName, deleteErr.Error()) | ||||||||||||||||||||||||||||||||
| return deleteErr | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
Comment on lines
+624
to
+627
|
||||||||||||||||||||||||||||||||
| klog.V(3).Infof("Node <%s> no longer matches node selector, removed from cache.", nodeName) | ||||||||||||||||||||||||||||||||
|
Comment on lines
+624
to
+628
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The call to
Suggested change
|
||||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| nodeCopy := node.DeepCopy() | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1573,3 +1573,26 @@ func TestSchedulerCache_SyncHyperNode(t *testing.T) { | |||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| func TestSchedulerCache_SyncNode_RemoveOnLabelChange(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||
| // Simulate: node was in cache with matching label, then label is removed | ||||||||||||||||||||||||||||||||||||||
| n1WithLabel := util.BuildNode("n1", nil, map[string]string{"train": "true"}) | ||||||||||||||||||||||||||||||||||||||
| n1WithoutLabel := util.BuildNode("n1", nil, map[string]string{}) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| sc := NewDefaultMockSchedulerCache("volcano") | ||||||||||||||||||||||||||||||||||||||
| sc.nodeSelectorLabels = map[string]sets.Empty{ | ||||||||||||||||||||||||||||||||||||||
| "train:true": {}, | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Step 1: Add node with matching label to cache | ||||||||||||||||||||||||||||||||||||||
| sc.nodeInformer.Informer().GetIndexer().Add(n1WithLabel) | ||||||||||||||||||||||||||||||||||||||
| err := sc.SyncNode("n1") | ||||||||||||||||||||||||||||||||||||||
| assert.NoError(t, err) | ||||||||||||||||||||||||||||||||||||||
| assert.Contains(t, sc.Nodes, "n1", "node should be in cache after sync with matching label") | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Step 2: Update node to remove the label, then sync again | ||||||||||||||||||||||||||||||||||||||
| sc.nodeInformer.Informer().GetIndexer().Update(n1WithoutLabel) | ||||||||||||||||||||||||||||||||||||||
| err = sc.SyncNode("n1") | ||||||||||||||||||||||||||||||||||||||
| assert.NoError(t, err) | ||||||||||||||||||||||||||||||||||||||
| assert.NotContains(t, sc.Nodes, "n1", "node should be removed from cache after label removal") | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
| } | |
| } | |
| func TestSchedulerCache_SyncNode_NeverMatchesSelector(t *testing.T) { | |
| // Simulate: node never has the matching label, so it should never be added to cache | |
| n2 := util.BuildNode("n2", nil, map[string]string{}) | |
| sc := NewDefaultMockSchedulerCache("volcano") | |
| sc.nodeSelectorLabels = map[string]sets.Empty{ | |
| "train:true": {}, | |
| } | |
| // Add node without matching label to informer and sync | |
| sc.nodeInformer.Informer().GetIndexer().Add(n2) | |
| err := sc.SyncNode("n2") | |
| assert.NoError(t, err) | |
| assert.NotContains(t, sc.Nodes, "n2", "node without matching label should not be added to cache") | |
| } |
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.
The RemoveNode() function returns an error if the node doesn't exist in the cache (line 541). This causes SyncNode() to fail when nodeCanAddCache() returns false for a node that was never added to cache. This breaks the existing test case "Node not added to cache" which expects wantErr: false. The RemoveNode() call should only propagate errors that aren't "node does not exist" errors, or RemoveNode() should be modified to not error when the node is not found.