Add GetNode method to scheduler cache for testing

This commit is contained in:
Maciej Skoczeń
2026-03-16 14:20:49 +00:00
parent 6c8e5e2d41
commit 19eeddaa92
2 changed files with 17 additions and 0 deletions

View File

@@ -649,6 +649,19 @@ func (cache *cacheImpl) RemoveNode(logger klog.Logger, node *v1.Node) error {
return nil
}
// GetNode returns the copy of node stored in the cache.
// DO NOT use outside of tests.
func (cache *cacheImpl) GetNode(name string) (*framework.NodeInfo, error) {
cache.mu.RLock()
defer cache.mu.RUnlock()
n, ok := cache.nodes[name]
if !ok {
return nil, fmt.Errorf("node %v does not exist in scheduler cache", name)
}
return n.info.SnapshotConcrete(), nil
}
// addNodeImageStates adds states of the images on given node to the given nodeInfo and update the imageStates in
// scheduler cache. This function assumes the lock to scheduler cache has been acquired.
func (cache *cacheImpl) addNodeImageStates(node *v1.Node, nodeInfo *framework.NodeInfo) {

View File

@@ -61,6 +61,10 @@ type Cache interface {
// DO NOT use outside of tests.
PodCount() (int, error)
// GetNode returns the copy of node stored in the cache.
// DO NOT use outside of tests.
GetNode(name string) (*framework.NodeInfo, error)
// AssumePod assumes a pod scheduled and aggregates the pod's information into its node.
AssumePod(logger klog.Logger, pod *v1.Pod) error