From 60a27031b23adb39a2344be80100f00c53161fc9 Mon Sep 17 00:00:00 2001 From: Jianfei Bai Date: Tue, 20 Aug 2019 16:00:49 +0800 Subject: [PATCH] test: add cases to test that no images present on node or kubelet's NodeStatusMaxImages flag is set to 0. --- .../priorities/image_locality_test.go | 21 ++++++++++ pkg/scheduler/nodeinfo/util_test.go | 42 +++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/pkg/scheduler/algorithm/priorities/image_locality_test.go b/pkg/scheduler/algorithm/priorities/image_locality_test.go index 55c0aa546a8..cac518f0b53 100644 --- a/pkg/scheduler/algorithm/priorities/image_locality_test.go +++ b/pkg/scheduler/algorithm/priorities/image_locality_test.go @@ -108,6 +108,8 @@ func TestImageLocalityPriority(t *testing.T) { }, } + nodeWithNoImages := v1.NodeStatus{} + tests := []struct { pod *v1.Pod pods []*v1.Pod @@ -160,6 +162,25 @@ func TestImageLocalityPriority(t *testing.T) { expectedList: []schedulerapi.HostPriority{{Host: "machine1", Score: schedulerapi.MaxPriority}, {Host: "machine2", Score: 0}}, name: "if exceed limit, use limit", }, + { + // Pod: gcr.io/2000 gcr.io/10 + + // Node1 + // Image: gcr.io/2000:latest 2000MB + // Score: 10 * (2000M/3 - 23M)/(1000M - 23M) = 6 + + // Node2 + // Image: gcr.io/10:latest 10MB + // Score: 0 (10M/2 < 23M, min-threshold) + + // Node3 + // Image: + // Score: 0 + pod: &v1.Pod{Spec: testMinMax}, + nodes: []*v1.Node{makeImageNode("machine1", node403002000), makeImageNode("machine2", node25010), makeImageNode("machine3", nodeWithNoImages)}, + expectedList: []schedulerapi.HostPriority{{Host: "machine1", Score: 6}, {Host: "machine2", Score: 0}, {Host: "machine3", Score: 0}}, + name: "if exceed limit, use limit (with node which has no images present)", + }, } for _, test := range tests { diff --git a/pkg/scheduler/nodeinfo/util_test.go b/pkg/scheduler/nodeinfo/util_test.go index 0e108773e2b..becd8d0442b 100644 --- a/pkg/scheduler/nodeinfo/util_test.go +++ b/pkg/scheduler/nodeinfo/util_test.go @@ -68,6 +68,17 @@ func TestGetNodeImageStates(t *testing.T) { }, }, }, + { + node: &v1.Node{ + ObjectMeta: metav1.ObjectMeta{Name: "node-0"}, + Status: v1.NodeStatus{}, + }, + imageExistenceMap: map[string]sets.String{ + "gcr.io/10:v1": sets.NewString("node-1"), + "gcr.io/200:v1": sets.NewString(), + }, + expected: map[string]*ImageStateSummary{}, + }, } for _, test := range tests { @@ -123,6 +134,37 @@ func TestCreateImageExistenceMap(t *testing.T) { "gcr.io/200:v1": sets.NewString("node-1"), }, }, + { + nodes: []*v1.Node{ + { + ObjectMeta: metav1.ObjectMeta{Name: "node-0"}, + Status: v1.NodeStatus{}, + }, + { + ObjectMeta: metav1.ObjectMeta{Name: "node-1"}, + Status: v1.NodeStatus{ + Images: []v1.ContainerImage{ + { + Names: []string{ + "gcr.io/10:v1", + }, + SizeBytes: int64(10 * mb), + }, + { + Names: []string{ + "gcr.io/200:v1", + }, + SizeBytes: int64(200 * mb), + }, + }, + }, + }, + }, + expected: map[string]sets.String{ + "gcr.io/10:v1": sets.NewString("node-1"), + "gcr.io/200:v1": sets.NewString("node-1"), + }, + }, } for _, test := range tests {