Skip to content

Commit 032b051

Browse files
committed
chore(scheduler): add filter integration tests for missing part plugins: TaintToleration plugin
1 parent 3a812ec commit 032b051

File tree

2 files changed

+185
-0
lines changed

2 files changed

+185
-0
lines changed

pkg/scheduler/testing/wrappers.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,12 @@ func (p *PodWrapper) Node(s string) *PodWrapper {
409409
return p
410410
}
411411

412+
// Tolerations sets `tolerations` as the tolerations of the inner pod.
413+
func (p *PodWrapper) Tolerations(tolerations []v1.Toleration) *PodWrapper {
414+
p.Spec.Tolerations = tolerations
415+
return p
416+
}
417+
412418
// NodeSelector sets `m` as the nodeSelector of the inner pod.
413419
func (p *PodWrapper) NodeSelector(m map[string]string) *PodWrapper {
414420
p.Spec.NodeSelector = m

test/integration/scheduler/filters/filters_test.go

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,185 @@ func TestInterPodAffinityWithNamespaceSelector(t *testing.T) {
13501350
}
13511351
}
13521352

1353+
func TestTaintTolerationFilter(t *testing.T) {
1354+
pause := imageutils.GetPauseImageName()
1355+
tests := []struct {
1356+
name string
1357+
nodes []*v1.Node
1358+
incomingPod *v1.Pod
1359+
fit bool
1360+
}{
1361+
{
1362+
name: "Pod tolerates node taint",
1363+
nodes: []*v1.Node{
1364+
st.MakeNode().Name("node-1").
1365+
Taints([]v1.Taint{
1366+
{
1367+
Key: "example.com/taint1",
1368+
Value: "value1",
1369+
Effect: v1.TaintEffectNoSchedule,
1370+
},
1371+
}).Obj(),
1372+
},
1373+
incomingPod: st.MakePod().Name("pod-1").
1374+
Tolerations([]v1.Toleration{
1375+
{
1376+
Key: "example.com/taint1",
1377+
Value: "value1",
1378+
Effect: v1.TaintEffectNoSchedule,
1379+
},
1380+
}).Container(pause).
1381+
Obj(),
1382+
fit: true,
1383+
},
1384+
{
1385+
name: "Pod does not tolerate node taint",
1386+
nodes: []*v1.Node{st.MakeNode().Name("node-2").
1387+
Taints([]v1.Taint{
1388+
{
1389+
Key: "example.com/taint1",
1390+
Value: "value1",
1391+
Effect: v1.TaintEffectNoSchedule,
1392+
},
1393+
}).Obj(),
1394+
},
1395+
incomingPod: st.MakePod().Name("pod-2").Container(pause).Obj(),
1396+
fit: false,
1397+
},
1398+
{
1399+
name: "Pod tolerates some but not all node taints",
1400+
nodes: []*v1.Node{st.MakeNode().Name("node-3").Taints([]v1.Taint{
1401+
{
1402+
Key: "example.com/taint1",
1403+
Value: "value1",
1404+
Effect: v1.TaintEffectNoSchedule,
1405+
},
1406+
{
1407+
Key: "example.com/taint2",
1408+
Value: "value2",
1409+
Effect: v1.TaintEffectNoSchedule,
1410+
},
1411+
}).Obj(),
1412+
},
1413+
incomingPod: st.MakePod().Name("pod-3").Tolerations([]v1.Toleration{
1414+
{
1415+
Key: "example.com/taint1",
1416+
Value: "value1",
1417+
Effect: v1.TaintEffectNoSchedule,
1418+
},
1419+
}).Container(pause).
1420+
Obj(),
1421+
fit: false,
1422+
},
1423+
{
1424+
name: "Pod tolerates all node taints",
1425+
nodes: []*v1.Node{
1426+
st.MakeNode().Name("node-4").Taints([]v1.Taint{
1427+
{
1428+
Key: "example.com/taint1",
1429+
Value: "value1",
1430+
Effect: v1.TaintEffectNoSchedule,
1431+
},
1432+
{
1433+
Key: "example.com/taint2",
1434+
Value: "value2",
1435+
Effect: v1.TaintEffectNoSchedule,
1436+
},
1437+
}).Obj(),
1438+
},
1439+
incomingPod: st.MakePod().Name("pod-4").Tolerations([]v1.Toleration{
1440+
{
1441+
Key: "example.com/taint1",
1442+
Value: "value1",
1443+
Effect: v1.TaintEffectNoSchedule,
1444+
},
1445+
{
1446+
Key: "example.com/taint2",
1447+
Value: "value2",
1448+
Effect: v1.TaintEffectNoSchedule,
1449+
},
1450+
}).Container(pause).Obj(),
1451+
fit: true,
1452+
},
1453+
{
1454+
name: "Node has one taint, pod has multiple tolerations and tolerates all node taints",
1455+
nodes: []*v1.Node{
1456+
st.MakeNode().Name("node-1").
1457+
Taints([]v1.Taint{
1458+
{
1459+
Key: "example.com/taint1",
1460+
Value: "value1",
1461+
Effect: v1.TaintEffectNoSchedule,
1462+
},
1463+
}).Obj(),
1464+
},
1465+
incomingPod: st.MakePod().Name("pod-5").Tolerations([]v1.Toleration{
1466+
{
1467+
Key: "example.com/taint1",
1468+
Value: "value1",
1469+
Effect: v1.TaintEffectNoSchedule,
1470+
},
1471+
{
1472+
Key: "example.com/taint2",
1473+
Value: "value2",
1474+
Effect: v1.TaintEffectNoSchedule,
1475+
},
1476+
}).Container(pause).Obj(),
1477+
fit: true,
1478+
},
1479+
{
1480+
name: "Node has no taint, pod has one toleration",
1481+
nodes: []*v1.Node{
1482+
st.MakeNode().Name("node-6").Obj(),
1483+
},
1484+
incomingPod: st.MakePod().Name("pod-6").Tolerations([]v1.Toleration{
1485+
{
1486+
Key: "example.com/taint1",
1487+
Value: "value1",
1488+
Effect: v1.TaintEffectNoSchedule,
1489+
},
1490+
}).Container(pause).Obj(),
1491+
fit: true,
1492+
},
1493+
}
1494+
for _, tt := range tests {
1495+
t.Run(tt.name, func(t *testing.T) {
1496+
testCtx := initTest(t, "taint-toleration-filter")
1497+
cs := testCtx.ClientSet
1498+
ns := testCtx.NS.Name
1499+
1500+
for i := range tt.nodes {
1501+
if _, err := createNode(cs, tt.nodes[i]); err != nil {
1502+
t.Fatalf("Failed to create node: %v", err)
1503+
}
1504+
}
1505+
1506+
// set namespace to pods
1507+
tt.incomingPod.SetNamespace(ns)
1508+
defer testutils.CleanupPods(testCtx.Ctx, cs, t, []*v1.Pod{tt.incomingPod})
1509+
1510+
testPod, err := cs.CoreV1().Pods(tt.incomingPod.Namespace).Create(testCtx.Ctx, tt.incomingPod, metav1.CreateOptions{})
1511+
if err != nil {
1512+
t.Fatalf("Failed to create pod during test: %v", err)
1513+
}
1514+
1515+
if tt.fit {
1516+
err = wait.PollUntilContextTimeout(testCtx.Ctx, pollInterval, wait.ForeverTestTimeout, false,
1517+
podScheduled(cs, testPod.Namespace, testPod.Name))
1518+
if err != nil {
1519+
t.Errorf("Test Failed: Expected pod %s/%s to be scheduled but got error: %v", testPod.Namespace, testPod.Name, err)
1520+
}
1521+
} else {
1522+
err = wait.PollUntilContextTimeout(testCtx.Ctx, pollInterval, wait.ForeverTestTimeout, false,
1523+
podUnschedulable(cs, testPod.Namespace, testPod.Name))
1524+
if err != nil {
1525+
t.Errorf("Test Failed: Expected pod %s/%s to be unschedulable but got error: %v", testPod.Namespace, testPod.Name, err)
1526+
}
1527+
}
1528+
})
1529+
}
1530+
}
1531+
13531532
// TestPodTopologySpreadFilter verifies that EvenPodsSpread predicate functions well.
13541533
func TestPodTopologySpreadFilter(t *testing.T) {
13551534
pause := imageutils.GetPauseImageName()

0 commit comments

Comments
 (0)