Merge pull request #81647 from jfbai/test-node-has-no-mages

test: add cases to test that no images present in node status.
This commit is contained in:
Kubernetes Prow Robot 2019-09-11 20:04:23 -07:00 committed by GitHub
commit 59c276d512
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 0 deletions

View File

@ -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 {

View File

@ -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 {