Skip to content

Commit e8b9d1d

Browse files
committed
feature: Added filter integration tests for missing part plugins: NodePorts plugin
1 parent c4434c3 commit e8b9d1d

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed

test/integration/scheduler/filters/filters_test.go

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ var (
4949
createPausePod = testutils.CreatePausePod
5050
deletePod = testutils.DeletePod
5151
getPod = testutils.GetPod
52+
runPausePod = testutils.RunPausePod
5253
initPausePod = testutils.InitPausePod
5354
initTest = testutils.InitTestSchedulerWithNS
5455
podScheduledIn = testutils.PodScheduledIn
56+
podScheduled = testutils.PodScheduled
5557
podUnschedulable = testutils.PodUnschedulable
5658
waitForPodUnschedulable = testutils.WaitForPodUnschedulable
5759
)
@@ -1822,6 +1824,129 @@ func TestPodTopologySpreadFilter(t *testing.T) {
18221824
}
18231825
}
18241826

1827+
func TestNodePortsFilter(t *testing.T) {
1828+
pause := imageutils.GetPauseImageName()
1829+
tests := []struct {
1830+
name string
1831+
existingPods []*v1.Pod
1832+
incomingPod *v1.Pod
1833+
fit bool
1834+
}{
1835+
{
1836+
name: "Port Conflict on Node",
1837+
existingPods: []*v1.Pod{
1838+
st.MakePod().Name("test-1").
1839+
Containers([]v1.Container{st.MakeContainer().Name("test-1-container").Image(pause).
1840+
ContainerPort([]v1.ContainerPort{
1841+
{
1842+
HostIP: "127.0.0.1",
1843+
ContainerPort: 8081,
1844+
HostPort: 8081,
1845+
Protocol: "TCP",
1846+
},
1847+
{
1848+
HostIP: "127.0.0.1",
1849+
ContainerPort: 8082,
1850+
HostPort: 8082,
1851+
Protocol: "TCP",
1852+
},
1853+
}).Obj()}).
1854+
Obj(),
1855+
},
1856+
incomingPod: st.MakePod().Name("test-2").
1857+
Containers([]v1.Container{st.MakeContainer().Name("test-2-container").Image(pause).
1858+
ContainerPort([]v1.ContainerPort{
1859+
{
1860+
HostIP: "127.0.0.1",
1861+
ContainerPort: 8081,
1862+
HostPort: 8081,
1863+
Protocol: "TCP",
1864+
},
1865+
}).Obj()}).
1866+
Obj(),
1867+
fit: false,
1868+
},
1869+
{
1870+
name: "No Port Conflict on Node",
1871+
existingPods: []*v1.Pod{
1872+
st.MakePod().Name("test-1").
1873+
Containers([]v1.Container{st.MakeContainer().Name("test-1-container").Image(pause).
1874+
ContainerPort([]v1.ContainerPort{
1875+
{
1876+
HostIP: "127.0.0.1",
1877+
HostPort: 8081,
1878+
ContainerPort: 8081,
1879+
Protocol: "TCP",
1880+
},
1881+
{
1882+
HostIP: "127.0.0.1",
1883+
HostPort: 8082,
1884+
ContainerPort: 8082,
1885+
Protocol: "TCP",
1886+
},
1887+
}).Obj()}).
1888+
Obj(),
1889+
},
1890+
incomingPod: st.MakePod().Name("test-2").
1891+
Containers([]v1.Container{st.MakeContainer().Name("test-2-container").Image(pause).
1892+
ContainerPort([]v1.ContainerPort{
1893+
{
1894+
HostIP: "127.0.0.1",
1895+
HostPort: 8080,
1896+
ContainerPort: 8080,
1897+
Protocol: "TCP",
1898+
},
1899+
}).Obj()}).
1900+
Obj(),
1901+
fit: true,
1902+
},
1903+
}
1904+
for _, tt := range tests {
1905+
t.Run(tt.name, func(t *testing.T) {
1906+
testCtx := initTest(t, "node-ports-filter")
1907+
cs := testCtx.ClientSet
1908+
ns := testCtx.NS.Name
1909+
1910+
if _, err := createNode(cs, st.MakeNode().Name("node-0").Obj()); err != nil {
1911+
t.Fatalf("Failed to create node: %v", err)
1912+
}
1913+
1914+
// set namespace to pods
1915+
tt.incomingPod.SetNamespace(ns)
1916+
for i := range tt.existingPods {
1917+
tt.existingPods[i].SetNamespace(ns)
1918+
}
1919+
allPods := append([]*v1.Pod{tt.incomingPod}, tt.existingPods...)
1920+
defer testutils.CleanupPods(testCtx.Ctx, cs, t, allPods)
1921+
1922+
for _, pod := range tt.existingPods {
1923+
if _, err := runPausePod(testCtx.ClientSet, pod); err != nil {
1924+
t.Fatalf("Failed to create existing pod: %v", err)
1925+
}
1926+
}
1927+
1928+
testPod, err := cs.CoreV1().Pods(tt.incomingPod.Namespace).Create(testCtx.Ctx, tt.incomingPod, metav1.CreateOptions{})
1929+
if err != nil {
1930+
t.Fatalf("Failed to create pod during test: %v", err)
1931+
}
1932+
1933+
if tt.fit {
1934+
err = wait.PollUntilContextTimeout(testCtx.Ctx, pollInterval, wait.ForeverTestTimeout, false,
1935+
podScheduled(cs, testPod.Namespace, testPod.Name))
1936+
if err != nil {
1937+
t.Errorf("Test Failed: Expected pod %s/%s to be scheduled but got error: %v", testPod.Namespace, testPod.Name, err)
1938+
}
1939+
} else {
1940+
err = wait.PollUntilContextTimeout(testCtx.Ctx, pollInterval, wait.ForeverTestTimeout, false,
1941+
podUnschedulable(cs, testPod.Namespace, testPod.Name))
1942+
if err != nil {
1943+
t.Errorf("Test Failed: Expected pod %s/%s to be unschedulable but got error: %v", testPod.Namespace, testPod.Name, err)
1944+
}
1945+
}
1946+
})
1947+
}
1948+
}
1949+
18251950
var (
18261951
hardSpread = v1.DoNotSchedule
18271952
)

0 commit comments

Comments
 (0)