-
Notifications
You must be signed in to change notification settings - Fork 976
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
Add node image information to the cache of the scheduler. #2593
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 |
---|---|---|
|
@@ -19,13 +19,15 @@ package cache | |
import ( | ||
"context" | ||
"fmt" | ||
"k8s.io/kubernetes/pkg/scheduler/framework" | ||
"reflect" | ||
"strconv" | ||
|
||
v1 "k8s.io/api/core/v1" | ||
schedulingv1 "k8s.io/api/scheduling/v1" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/sets" | ||
"k8s.io/client-go/tools/cache" | ||
"k8s.io/klog" | ||
"k8s.io/kubernetes/pkg/kubelet/cm/cpumanager/topology" | ||
|
@@ -288,20 +290,75 @@ func (sc *SchedulerCache) DeletePod(obj interface{}) { | |
klog.V(3).Infof("Deleted pod <%s/%v> from cache.", pod.Namespace, pod.Name) | ||
} | ||
|
||
// 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 (sc *SchedulerCache) addNodeImageStates(node *v1.Node, nodeInfo *schedulingapi.NodeInfo) { | ||
newSum := make(map[string]*framework.ImageStateSummary) | ||
|
||
for _, image := range node.Status.Images { | ||
for _, name := range image.Names { | ||
// update the entry in imageStates | ||
state, ok := sc.imageStates[name] | ||
if !ok { | ||
state = &imageState{ | ||
size: image.SizeBytes, | ||
nodes: sets.NewString(node.Name), | ||
} | ||
sc.imageStates[name] = state | ||
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. where we use the data from sc.imageStates[name]? Is it enough that we only store image data in nodeinfo? 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.
When a node is added or deleted, the system updates the information in 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.
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.
In addition, |
||
} else { | ||
state.nodes.Insert(node.Name) | ||
} | ||
// create the imageStateSummary for this image | ||
if _, ok := newSum[name]; !ok { | ||
newSum[name] = sc.createImageStateSummary(state) | ||
} | ||
} | ||
} | ||
nodeInfo.ImageStates = newSum | ||
} | ||
|
||
// removeNodeImageStates removes the given node record from image entries having the node | ||
// in imageStates cache. After the removal, if any image becomes free, i.e., the image | ||
// is no longer available on any node, the image entry will be removed from imageStates. | ||
func (sc *SchedulerCache) removeNodeImageStates(node *v1.Node) { | ||
if node == nil { | ||
return | ||
} | ||
|
||
for _, image := range node.Status.Images { | ||
for _, name := range image.Names { | ||
state, ok := sc.imageStates[name] | ||
if ok { | ||
state.nodes.Delete(node.Name) | ||
if len(state.nodes) == 0 { | ||
// Remove the unused image to make sure the length of | ||
// imageStates represents the total number of different | ||
// images on all nodes | ||
delete(sc.imageStates, name) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Assumes that lock is already acquired. | ||
func (sc *SchedulerCache) addNode(node *v1.Node) error { | ||
if sc.Nodes[node.Name] != nil { | ||
sc.Nodes[node.Name].SetNode(node) | ||
sc.removeNodeImageStates(node) | ||
} else { | ||
sc.Nodes[node.Name] = schedulingapi.NewNodeInfo(node) | ||
} | ||
sc.addNodeImageStates(node, sc.Nodes[node.Name]) | ||
return nil | ||
} | ||
|
||
// Assumes that lock is already acquired. | ||
func (sc *SchedulerCache) updateNode(oldNode, newNode *v1.Node) error { | ||
if sc.Nodes[newNode.Name] != nil { | ||
sc.Nodes[newNode.Name].SetNode(newNode) | ||
sc.removeNodeImageStates(newNode) | ||
sc.addNodeImageStates(newNode, sc.Nodes[newNode.Name]) | ||
return nil | ||
} | ||
|
||
|
@@ -322,7 +379,7 @@ func (sc *SchedulerCache) deleteNode(node *v1.Node) error { | |
klog.Errorf("delete numatopo <%s/%s> failed.", numaInfo.Namespace, numaInfo.Name) | ||
} | ||
} | ||
|
||
sc.removeNodeImageStates(node) | ||
delete(sc.Nodes, node.Name) | ||
|
||
return nil | ||
|
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.
why we need to import this package in this file?
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.
This package is referenced when imageState is used to initialize ImageStateSummary. This package is introduced by the createImageStateSummary function added to the cache file.