@@ -1145,11 +1145,11 @@ func mustConvertLabelSelectorAsSelector(t *testing.T, ls *metav1.LabelSelector)
1145
1145
1146
1146
func TestSingleConstraint (t * testing.T ) {
1147
1147
tests := []struct {
1148
- name string
1149
- pod * v1.Pod
1150
- nodes []* v1.Node
1151
- existingPods []* v1.Pod
1152
- fits map [string ]bool
1148
+ name string
1149
+ pod * v1.Pod
1150
+ nodes []* v1.Node
1151
+ existingPods []* v1.Pod
1152
+ wantStatusCode map [string ]framework. Code
1153
1153
}{
1154
1154
{
1155
1155
name : "no existing pods" ,
@@ -1162,11 +1162,11 @@ func TestSingleConstraint(t *testing.T) {
1162
1162
st .MakeNode ().Name ("node-x" ).Label ("zone" , "zone2" ).Label ("node" , "node-x" ).Obj (),
1163
1163
st .MakeNode ().Name ("node-y" ).Label ("zone" , "zone2" ).Label ("node" , "node-y" ).Obj (),
1164
1164
},
1165
- fits : map [string ]bool {
1166
- "node-a" : true ,
1167
- "node-b" : true ,
1168
- "node-x" : true ,
1169
- "node-y" : true ,
1165
+ wantStatusCode : map [string ]framework. Code {
1166
+ "node-a" : framework . Success ,
1167
+ "node-b" : framework . Success ,
1168
+ "node-x" : framework . Success ,
1169
+ "node-y" : framework . Success ,
1170
1170
},
1171
1171
},
1172
1172
{
@@ -1180,11 +1180,11 @@ func TestSingleConstraint(t *testing.T) {
1180
1180
st .MakeNode ().Name ("node-x" ).Label ("zone" , "zone2" ).Label ("node" , "node-x" ).Obj (),
1181
1181
st .MakeNode ().Name ("node-y" ).Label ("zone" , "zone2" ).Label ("node" , "node-y" ).Obj (),
1182
1182
},
1183
- fits : map [string ]bool {
1184
- "node-a" : true ,
1185
- "node-b" : true ,
1186
- "node-x" : true ,
1187
- "node-y" : true ,
1183
+ wantStatusCode : map [string ]framework. Code {
1184
+ "node-a" : framework . Success ,
1185
+ "node-b" : framework . Success ,
1186
+ "node-x" : framework . Success ,
1187
+ "node-y" : framework . Success ,
1188
1188
},
1189
1189
},
1190
1190
{
@@ -1204,11 +1204,11 @@ func TestSingleConstraint(t *testing.T) {
1204
1204
st .MakePod ().Name ("p-x1" ).Node ("node-x" ).Label ("foo" , "" ).Obj (),
1205
1205
st .MakePod ().Name ("p-y1" ).Node ("node-y" ).Label ("foo" , "" ).Obj (),
1206
1206
},
1207
- fits : map [string ]bool {
1208
- "node-a" : true ,
1209
- "node-b" : true ,
1210
- "node-x" : false ,
1211
- "node-y" : false ,
1207
+ wantStatusCode : map [string ]framework. Code {
1208
+ "node-a" : framework . Success ,
1209
+ "node-b" : framework . Success ,
1210
+ "node-x" : framework . Unschedulable ,
1211
+ "node-y" : framework . Unschedulable ,
1212
1212
},
1213
1213
},
1214
1214
{
@@ -1230,11 +1230,11 @@ func TestSingleConstraint(t *testing.T) {
1230
1230
st .MakePod ().Name ("p-y2" ).Node ("node-y" ).Label ("foo" , "" ).Obj (),
1231
1231
st .MakePod ().Name ("p-y3" ).Node ("node-y" ).Label ("foo" , "" ).Obj (),
1232
1232
},
1233
- fits : map [string ]bool {
1234
- "node-a" : true ,
1235
- "node-b" : true ,
1236
- "node-x" : true ,
1237
- "node-y" : true ,
1233
+ wantStatusCode : map [string ]framework. Code {
1234
+ "node-a" : framework . Success ,
1235
+ "node-b" : framework . Success ,
1236
+ "node-x" : framework . Success ,
1237
+ "node-y" : framework . Success ,
1238
1238
},
1239
1239
},
1240
1240
{
@@ -1256,11 +1256,11 @@ func TestSingleConstraint(t *testing.T) {
1256
1256
st .MakePod ().Name ("p-x1" ).Node ("node-x" ).Label ("foo" , "" ).Obj (),
1257
1257
st .MakePod ().Name ("p-y1" ).Node ("node-y" ).Label ("foo" , "" ).Obj (),
1258
1258
},
1259
- fits : map [string ]bool {
1260
- "node-a" : true ,
1261
- "node-b" : false ,
1262
- "node-x" : false ,
1263
- "node-y" : false ,
1259
+ wantStatusCode : map [string ]framework. Code {
1260
+ "node-a" : framework . Success ,
1261
+ "node-b" : framework . UnschedulableAndUnresolvable ,
1262
+ "node-x" : framework . Unschedulable ,
1263
+ "node-y" : framework . Unschedulable ,
1264
1264
},
1265
1265
},
1266
1266
{
@@ -1282,11 +1282,11 @@ func TestSingleConstraint(t *testing.T) {
1282
1282
st .MakePod ().Name ("p-y2" ).Node ("node-y" ).Label ("foo" , "" ).Obj (),
1283
1283
st .MakePod ().Name ("p-y3" ).Node ("node-y" ).Label ("foo" , "" ).Obj (),
1284
1284
},
1285
- fits : map [string ]bool {
1286
- "node-a" : false ,
1287
- "node-b" : false ,
1288
- "node-x" : true ,
1289
- "node-y" : false ,
1285
+ wantStatusCode : map [string ]framework. Code {
1286
+ "node-a" : framework . Unschedulable ,
1287
+ "node-b" : framework . Unschedulable ,
1288
+ "node-x" : framework . Success ,
1289
+ "node-y" : framework . Unschedulable ,
1290
1290
},
1291
1291
},
1292
1292
{
@@ -1308,11 +1308,11 @@ func TestSingleConstraint(t *testing.T) {
1308
1308
st .MakePod ().Name ("p-y2" ).Node ("node-y" ).Label ("foo" , "" ).Obj (),
1309
1309
st .MakePod ().Name ("p-y3" ).Node ("node-y" ).Label ("foo" , "" ).Obj (),
1310
1310
},
1311
- fits : map [string ]bool {
1312
- "node-a" : false ,
1313
- "node-b" : true ,
1314
- "node-x" : true ,
1315
- "node-y" : false ,
1311
+ wantStatusCode : map [string ]framework. Code {
1312
+ "node-a" : framework . Unschedulable ,
1313
+ "node-b" : framework . Success ,
1314
+ "node-x" : framework . Success ,
1315
+ "node-y" : framework . Unschedulable ,
1316
1316
},
1317
1317
},
1318
1318
{
@@ -1338,11 +1338,11 @@ func TestSingleConstraint(t *testing.T) {
1338
1338
st .MakePod ().Name ("p-y2" ).Node ("node-y" ).Label ("foo" , "" ).Obj (),
1339
1339
st .MakePod ().Name ("p-y3" ).Node ("node-y" ).Label ("foo" , "" ).Obj (),
1340
1340
},
1341
- fits : map [string ]bool {
1342
- "node-a" : false ,
1343
- "node-b" : true ,
1344
- "node-x" : true ,
1345
- "node-y" : false ,
1341
+ wantStatusCode : map [string ]framework. Code {
1342
+ "node-a" : framework . Unschedulable ,
1343
+ "node-b" : framework . Success ,
1344
+ "node-x" : framework . Success ,
1345
+ "node-y" : framework . Unschedulable ,
1346
1346
},
1347
1347
},
1348
1348
{
@@ -1370,11 +1370,11 @@ func TestSingleConstraint(t *testing.T) {
1370
1370
st .MakePod ().Name ("p-y2" ).Node ("node-y" ).Label ("foo" , "" ).Obj (),
1371
1371
st .MakePod ().Name ("p-y3" ).Node ("node-y" ).Label ("foo" , "" ).Obj (),
1372
1372
},
1373
- fits : map [string ]bool {
1374
- "node-a" : true ,
1375
- "node-b" : true , // in real case, it's false
1376
- "node-x" : true , // in real case, it's false
1377
- "node-y" : false ,
1373
+ wantStatusCode : map [string ]framework. Code {
1374
+ "node-a" : framework . Success ,
1375
+ "node-b" : framework . Success , // in real case, it's false
1376
+ "node-x" : framework . Success , // in real case, it's false
1377
+ "node-y" : framework . Unschedulable ,
1378
1378
},
1379
1379
},
1380
1380
{
@@ -1390,9 +1390,9 @@ func TestSingleConstraint(t *testing.T) {
1390
1390
st .MakePod ().Name ("p-a" ).Node ("node-a" ).Label ("foo" , "" ).Terminating ().Obj (),
1391
1391
st .MakePod ().Name ("p-b" ).Node ("node-b" ).Label ("foo" , "" ).Obj (),
1392
1392
},
1393
- fits : map [string ]bool {
1394
- "node-a" : true ,
1395
- "node-b" : false ,
1393
+ wantStatusCode : map [string ]framework. Code {
1394
+ "node-a" : framework . Success ,
1395
+ "node-b" : framework . Unschedulable ,
1396
1396
},
1397
1397
},
1398
1398
}
@@ -1409,8 +1409,8 @@ func TestSingleConstraint(t *testing.T) {
1409
1409
for _ , node := range tt .nodes {
1410
1410
nodeInfo , _ := snapshot .NodeInfos ().Get (node .Name )
1411
1411
status := p .Filter (context .Background (), state , tt .pod , nodeInfo )
1412
- if status .IsSuccess () != tt .fits [node .Name ] {
1413
- t .Errorf ("[%s]: expected %v got %v" , node .Name , tt .fits [node .Name ], status .IsSuccess ())
1412
+ if len ( tt . wantStatusCode ) != 0 && status .Code () != tt .wantStatusCode [node .Name ] {
1413
+ t .Errorf ("[%s]: expected status code %v got %v" , node .Name , tt .wantStatusCode [node .Name ], status .Code ())
1414
1414
}
1415
1415
}
1416
1416
})
@@ -1419,11 +1419,11 @@ func TestSingleConstraint(t *testing.T) {
1419
1419
1420
1420
func TestMultipleConstraints (t * testing.T ) {
1421
1421
tests := []struct {
1422
- name string
1423
- pod * v1.Pod
1424
- nodes []* v1.Node
1425
- existingPods []* v1.Pod
1426
- fits map [string ]bool
1422
+ name string
1423
+ pod * v1.Pod
1424
+ nodes []* v1.Node
1425
+ existingPods []* v1.Pod
1426
+ wantStatusCode map [string ]framework. Code
1427
1427
}{
1428
1428
{
1429
1429
// 1. to fulfil "zone" constraint, incoming pod can be placed on any zone (hence any node)
@@ -1448,11 +1448,11 @@ func TestMultipleConstraints(t *testing.T) {
1448
1448
st .MakePod ().Name ("p-y2" ).Node ("node-y" ).Label ("foo" , "" ).Obj (),
1449
1449
st .MakePod ().Name ("p-y3" ).Node ("node-y" ).Label ("foo" , "" ).Obj (),
1450
1450
},
1451
- fits : map [string ]bool {
1452
- "node-a" : false ,
1453
- "node-b" : false ,
1454
- "node-x" : true ,
1455
- "node-y" : false ,
1451
+ wantStatusCode : map [string ]framework. Code {
1452
+ "node-a" : framework . Unschedulable ,
1453
+ "node-b" : framework . Unschedulable ,
1454
+ "node-x" : framework . Success ,
1455
+ "node-y" : framework . Unschedulable ,
1456
1456
},
1457
1457
},
1458
1458
{
@@ -1479,11 +1479,11 @@ func TestMultipleConstraints(t *testing.T) {
1479
1479
st .MakePod ().Name ("p-y3" ).Node ("node-y" ).Label ("foo" , "" ).Obj (),
1480
1480
st .MakePod ().Name ("p-y4" ).Node ("node-y" ).Label ("foo" , "" ).Obj (),
1481
1481
},
1482
- fits : map [string ]bool {
1483
- "node-a" : false ,
1484
- "node-b" : false ,
1485
- "node-x" : false ,
1486
- "node-y" : false ,
1482
+ wantStatusCode : map [string ]framework. Code {
1483
+ "node-a" : framework . Unschedulable ,
1484
+ "node-b" : framework . Unschedulable ,
1485
+ "node-x" : framework . Unschedulable ,
1486
+ "node-y" : framework . Unschedulable ,
1487
1487
},
1488
1488
},
1489
1489
{
@@ -1505,11 +1505,11 @@ func TestMultipleConstraints(t *testing.T) {
1505
1505
st .MakePod ().Name ("p-a1" ).Node ("node-a" ).Label ("foo" , "" ).Obj (),
1506
1506
st .MakePod ().Name ("p-y1" ).Node ("node-y" ).Label ("bar" , "" ).Obj (),
1507
1507
},
1508
- fits : map [string ]bool {
1509
- "node-a" : false ,
1510
- "node-b" : false ,
1511
- "node-x" : true ,
1512
- "node-y" : false ,
1508
+ wantStatusCode : map [string ]framework. Code {
1509
+ "node-a" : framework . Unschedulable ,
1510
+ "node-b" : framework . Unschedulable ,
1511
+ "node-x" : framework . Success ,
1512
+ "node-y" : framework . Unschedulable ,
1513
1513
},
1514
1514
},
1515
1515
{
@@ -1532,11 +1532,11 @@ func TestMultipleConstraints(t *testing.T) {
1532
1532
st .MakePod ().Name ("p-x1" ).Node ("node-x" ).Label ("bar" , "" ).Obj (),
1533
1533
st .MakePod ().Name ("p-y1" ).Node ("node-y" ).Label ("bar" , "" ).Obj (),
1534
1534
},
1535
- fits : map [string ]bool {
1536
- "node-a" : false ,
1537
- "node-b" : false ,
1538
- "node-x" : false ,
1539
- "node-y" : false ,
1535
+ wantStatusCode : map [string ]framework. Code {
1536
+ "node-a" : framework . Unschedulable ,
1537
+ "node-b" : framework . Unschedulable ,
1538
+ "node-x" : framework . Unschedulable ,
1539
+ "node-y" : framework . Unschedulable ,
1540
1540
},
1541
1541
},
1542
1542
{
@@ -1561,11 +1561,11 @@ func TestMultipleConstraints(t *testing.T) {
1561
1561
st .MakePod ().Name ("p-y2" ).Node ("node-y" ).Label ("foo" , "" ).Label ("bar" , "" ).Obj (),
1562
1562
st .MakePod ().Name ("p-y3" ).Node ("node-y" ).Label ("foo" , "" ).Obj (),
1563
1563
},
1564
- fits : map [string ]bool {
1565
- "node-a" : false ,
1566
- "node-b" : true ,
1567
- "node-x" : false ,
1568
- "node-y" : false ,
1564
+ wantStatusCode : map [string ]framework. Code {
1565
+ "node-a" : framework . Unschedulable ,
1566
+ "node-b" : framework . Success ,
1567
+ "node-x" : framework . Unschedulable ,
1568
+ "node-y" : framework . Unschedulable ,
1569
1569
},
1570
1570
},
1571
1571
{
@@ -1588,11 +1588,37 @@ func TestMultipleConstraints(t *testing.T) {
1588
1588
st .MakePod ().Name ("p-x1" ).Node ("node-x" ).Label ("bar" , "" ).Obj (),
1589
1589
st .MakePod ().Name ("p-y1" ).Node ("node-y" ).Label ("bar" , "" ).Obj (),
1590
1590
},
1591
- fits : map [string ]bool {
1592
- "node-a" : true ,
1593
- "node-b" : true ,
1594
- "node-x" : false ,
1595
- "node-y" : false ,
1591
+ wantStatusCode : map [string ]framework.Code {
1592
+ "node-a" : framework .Success ,
1593
+ "node-b" : framework .Success ,
1594
+ "node-x" : framework .Unschedulable ,
1595
+ "node-y" : framework .Unschedulable ,
1596
+ },
1597
+ },
1598
+ {
1599
+ // 1. to fulfil "zone" constraint, incoming pod can be placed on any zone (hence any node)
1600
+ // 2. to fulfil "node" constraint, incoming pod can be placed on node-b (node-x doesn't have the required label)
1601
+ // intersection of (1) and (2) returns node-b
1602
+ name : "two Constraints on zone and node, absence of label 'node' on node-x, spreads = [1/1, 1/0/0/1]" ,
1603
+ pod : st .MakePod ().Name ("p" ).Label ("foo" , "" ).
1604
+ SpreadConstraint (1 , "zone" , v1 .DoNotSchedule , st .MakeLabelSelector ().Exists ("foo" ).Obj ()).
1605
+ SpreadConstraint (1 , "node" , v1 .DoNotSchedule , st .MakeLabelSelector ().Exists ("foo" ).Obj ()).
1606
+ Obj (),
1607
+ nodes : []* v1.Node {
1608
+ st .MakeNode ().Name ("node-a" ).Label ("zone" , "zone1" ).Label ("node" , "node-a" ).Obj (),
1609
+ st .MakeNode ().Name ("node-b" ).Label ("zone" , "zone1" ).Label ("node" , "node-b" ).Obj (),
1610
+ st .MakeNode ().Name ("node-x" ).Label ("zone" , "zone2" ).Obj (),
1611
+ st .MakeNode ().Name ("node-y" ).Label ("zone" , "zone2" ).Label ("node" , "node-y" ).Obj (),
1612
+ },
1613
+ existingPods : []* v1.Pod {
1614
+ st .MakePod ().Name ("p-a1" ).Node ("node-a" ).Label ("foo" , "" ).Obj (),
1615
+ st .MakePod ().Name ("p-y3" ).Node ("node-y" ).Label ("foo" , "" ).Obj (),
1616
+ },
1617
+ wantStatusCode : map [string ]framework.Code {
1618
+ "node-a" : framework .Unschedulable ,
1619
+ "node-b" : framework .Success ,
1620
+ "node-x" : framework .UnschedulableAndUnresolvable ,
1621
+ "node-y" : framework .Unschedulable ,
1596
1622
},
1597
1623
},
1598
1624
}
@@ -1609,8 +1635,8 @@ func TestMultipleConstraints(t *testing.T) {
1609
1635
for _ , node := range tt .nodes {
1610
1636
nodeInfo , _ := snapshot .NodeInfos ().Get (node .Name )
1611
1637
status := p .Filter (context .Background (), state , tt .pod , nodeInfo )
1612
- if status .IsSuccess () != tt .fits [node .Name ] {
1613
- t .Errorf ("[%s]: expected %v got %v" , node .Name , tt .fits [node .Name ], status .IsSuccess ())
1638
+ if len ( tt . wantStatusCode ) != 0 && status .Code () != tt .wantStatusCode [node .Name ] {
1639
+ t .Errorf ("[%s]: expected error code %v got %v" , node .Name , tt .wantStatusCode [node .Name ], status .Code ())
1614
1640
}
1615
1641
}
1616
1642
})
0 commit comments