Skip to content

[BugFix]Update ImageLocality plugin to account ImageVolume images #130231

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion pkg/scheduler/framework/plugins/imagelocality/image_locality.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ func calculatePriority(sumScores int64, numContainers int) int64 {
return framework.MaxNodeScore * (sumScores - minThreshold) / (maxThreshold - minThreshold)
}

// sumImageScores returns the sum of image scores of all the containers that are already on the node.
// sumImageScores returns the total image score for all container images in the Pod spec,
// including regular containers, init containers, and image volumes, that already exist on the node.
// Each image receives a raw score of its size, scaled by scaledImageScore. The raw scores are later used to calculate
// the final score.
func sumImageScores(nodeInfo fwk.NodeInfo, pod *v1.Pod, totalNumNodes int) int64 {
Expand All @@ -102,6 +103,14 @@ func sumImageScores(nodeInfo fwk.NodeInfo, pod *v1.Pod, totalNumNodes int) int64
sum += scaledImageScore(state, totalNumNodes)
}
}
for _, volume := range pod.Spec.Volumes {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if should check the "ImageVolume" feature gate at here, and only account volume when it enabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, it's done. Is there anything else missing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None from me. Let's wait for other reviewers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, actually I'm not sure about this.
We may have a scheduler without this fg, but both api-server and kubelet has it enabled.
In this case, kubelet will pull the images anyway.
I prefer to calculate them anyway. /cc @macsko What's your opinion?

if volume.Image == nil {
continue
}
if state, ok := nodeInfo.GetImageStates()[normalizedImageName(volume.Image.Reference)]; ok {
sum += scaledImageScore(state, totalNumNodes)
}
}
return sum
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,24 @@ func TestImageLocalityPriority(t *testing.T) {
},
}

testImageVolume := v1.PodSpec{
Containers: []v1.Container{
{
Image: "gcr.io/30",
},
},
Volumes: []v1.Volume{
{
Name: "imageVolume",
VolumeSource: v1.VolumeSource{
Image: &v1.ImageVolumeSource{
Reference: "gcr.io/300",
},
},
},
},
}

test30Init300 := v1.PodSpec{
Containers: []v1.Container{
{
Expand Down Expand Up @@ -340,6 +358,21 @@ func TestImageLocalityPriority(t *testing.T) {
expectedList: []framework.NodeScore{{Name: "node1", Score: 1}, {Name: "node2", Score: 0}},
name: "pod with multiple small images",
},
{
// Pod: gcr.io/300 gcr.io/30

// Node1
// Image: gcr.io/300:latest 300MB
// Score: 100 * (300M * 1/2 - 23M) / (1000M - 23M) = 12

// Node2
// Image: gcr.io/30:latest 30MB
// Score: 100 * (30M - 23M) / (1000M - 23M) = 0
pod: &v1.Pod{Spec: testImageVolume},
nodes: []*v1.Node{makeImageNode("node1", node300600900), makeImageNode("node2", node400030)},
expectedList: []framework.NodeScore{{Name: "node1", Score: 12}, {Name: "node2", Score: 0}},
name: "pod with ImageVolume",
},
{
// Pod: gcr.io/30 InitContainers: gcr.io/300

Expand Down