-
Notifications
You must be signed in to change notification settings - Fork 4k
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
CA: refactor ClusterSnapshot methods #7466
Changes from 1 commit
269c7a3
517ecb9
3860388
a81aa5c
f67db62
473a1a8
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 |
---|---|---|
|
@@ -153,15 +153,6 @@ func (data *internalBasicSnapshotData) addNode(node *apiv1.Node) error { | |
return nil | ||
} | ||
|
||
func (data *internalBasicSnapshotData) addNodes(nodes []*apiv1.Node) error { | ||
for _, node := range nodes { | ||
if err := data.addNode(node); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (data *internalBasicSnapshotData) removeNode(nodeName string) error { | ||
if _, found := data.nodeInfoMap[nodeName]; !found { | ||
return ErrNodeNotFound | ||
|
@@ -241,16 +232,32 @@ func (snapshot *BasicClusterSnapshot) AddNodeInfo(nodeInfo *framework.NodeInfo) | |
return nil | ||
} | ||
|
||
// SetClusterState sets the cluster state. | ||
func (snapshot *BasicClusterSnapshot) SetClusterState(nodes []*apiv1.Node, scheduledPods []*apiv1.Pod) error { | ||
snapshot.Clear() | ||
|
||
knownNodes := make(map[string]bool) | ||
for _, node := range nodes { | ||
if err := snapshot.AddNode(node); err != nil { | ||
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 only error condition for adding a node is if your 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. IMO this is the perfect place to validate this:
Keep in mind that this should be called once per snapshot per loop, so the 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. O.K. I think my initial skepticism here is keeping the source of truth in two places here:
I don't have any reason to suspect a race condition risk here, but would this be more "correct"?: for _, pod := range scheduledPods {
if err := snapshot.getInternalData().addPod(pod, pod.Spec.NodeName); err != nil {
continue
}
} The only error return condition for the if _, found := data.nodeInfoMap[nodeName]; !found {
return ErrNodeNotFound
} So rather than keeping a local accounting of "found nodes" ( |
||
return err | ||
} | ||
knownNodes[node.Name] = true | ||
} | ||
for _, pod := range scheduledPods { | ||
if knownNodes[pod.Spec.NodeName] { | ||
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. This is a slight modification from the original usage of What would you think about removing the 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. Ok, after additional review I see that it is meant to replace eg. static_autoscaler.go usage of AddNode, which ignores pods with unknown nodes. Do you think it's okay that we do it this way? I am worried that some places might depend on the error returned by AddPod. 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. Yeah your second comment got it right - There are basically 2 usages in production code - It's not ideal that each caller has to process the input pods in the same way, but I'd prefer to tackle this when we get to having unschedulable pods tracked in the snapshot. Then 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. That sounds good to me, especially given that we will be able to tackle it for unschedulable pods. |
||
if err := snapshot.AddPod(pod, pod.Spec.NodeName); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// AddNode adds node to the snapshot. | ||
func (snapshot *BasicClusterSnapshot) AddNode(node *apiv1.Node) error { | ||
return snapshot.getInternalData().addNode(node) | ||
} | ||
|
||
// AddNodes adds nodes in batch to the snapshot. | ||
func (snapshot *BasicClusterSnapshot) AddNodes(nodes []*apiv1.Node) error { | ||
return snapshot.getInternalData().addNodes(nodes) | ||
} | ||
|
||
// RemoveNode removes nodes (and pods scheduled to it) from the snapshot. | ||
func (snapshot *BasicClusterSnapshot) RemoveNode(nodeName string) error { | ||
return snapshot.getInternalData().removeNode(nodeName) | ||
|
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.
Shouldn't we just remove Clear() from interface at this point? It feels completely redundant. Initialize(nil, nil) should do exactly the same thing and, after renaming it, should also be a very obvious and natural way of doing that (not to mention the fact that IIRC we never Clear() a snapshot without immediately re-initializing it, so the Clear() functionality is probably never needed).
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.
Yup, full agreement here - removed Clear().