Build image size map upon node info updates

This commit is contained in:
Silvery Fu
2018-05-08 15:02:18 -07:00
parent a67ccaeab1
commit 4087ff32bc
4 changed files with 56 additions and 9 deletions

View File

@@ -42,7 +42,7 @@ func ImageLocalityPriorityMap(pod *v1.Pod, meta interface{}, nodeInfo *scheduler
return schedulerapi.HostPriority{}, fmt.Errorf("node not found")
}
sumSize := totalImageSize(node, pod.Spec.Containers)
sumSize := totalImageSize(nodeInfo, pod.Spec.Containers)
return schedulerapi.HostPriority{
Host: node.Name,
@@ -69,15 +69,10 @@ func calculateScoreFromSize(sumSize int64) int {
}
// totalImageSize returns the total image size of all the containers that are already on the node.
func totalImageSize(node *v1.Node, containers []v1.Container) int64 {
imageSizes := make(map[string]int64)
for _, image := range node.Status.Images {
for _, name := range image.Names {
imageSizes[name] = image.SizeBytes
}
}
func totalImageSize(nodeInfo *schedulercache.NodeInfo, containers []v1.Container) int64 {
var total int64
imageSizes := nodeInfo.Images()
for _, container := range containers {
if size, ok := imageSizes[container.Image]; ok {
total += size