Consider initContainer images in pod scheduling

Co-authored-by:     xiaomudk <xiaomudk@gmail.com>
Co-authored-by:     kerthcet <kerthcet@gmail.com>
Signed-off-by: kerthcet <kerthcet@gmail.com>
This commit is contained in:
kerthcet
2024-02-19 14:17:57 +08:00
parent 70af917493
commit 65faa9c680
2 changed files with 38 additions and 6 deletions

View File

@@ -91,6 +91,17 @@ func TestImageLocalityPriority(t *testing.T) {
},
}
test30Init300 := v1.PodSpec{
Containers: []v1.Container{
{
Image: "gcr.io/30",
},
},
InitContainers: []v1.Container{
{Image: "gcr.io/300"},
},
}
node403002000 := v1.NodeStatus{
Images: []v1.ContainerImage{
{
@@ -317,7 +328,7 @@ func TestImageLocalityPriority(t *testing.T) {
// Pod: gcr.io/30 gcr.io/40
// Node1
// Image: gcr.io/20:latest 20MB, gcr.io/30:latest 30MB gcr.io/40:latest 40MB
// Image: gcr.io/20:latest 20MB, gcr.io/30:latest 30MB, gcr.io/40:latest 40MB
// Score: 100 * (30M + 40M * 1/2 - 23M) / (1000M * 2 - 23M) = 1
// Node2
@@ -328,6 +339,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/30 InitContainers: gcr.io/300
// Node1
// Image: gcr.io/40:latest 40MB, gcr.io/300:latest 300MB, gcr.io/2000:latest 2000MB
// Score: 100 * (300M * 1/2 - 23M) / (1000M * 2 - 23M) = 6
// Node2
// Image: gcr.io/20:latest 20MB, gcr.io/30:latest 30MB, gcr.io/40:latest 40MB
// Score: 100 * (30M * 1/2 - 23M) / (1000M * 2 - 23M) = 0
pod: &v1.Pod{Spec: test30Init300},
nodes: []*v1.Node{makeImageNode("node1", node403002000), makeImageNode("node2", node203040)},
expectedList: []framework.NodeScore{{Name: "node1", Score: 6}, {Name: "node2", Score: 0}},
name: "include InitContainers: two images spread on two nodes, prefer the larger image one",
},
}
for _, test := range tests {