mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 16:29:21 +00:00
feature: Added filter integration tests for missing part plugins: NodePorts plugin
This commit is contained in:
parent
c4434c3161
commit
e8b9d1d93f
@ -49,9 +49,11 @@ var (
|
|||||||
createPausePod = testutils.CreatePausePod
|
createPausePod = testutils.CreatePausePod
|
||||||
deletePod = testutils.DeletePod
|
deletePod = testutils.DeletePod
|
||||||
getPod = testutils.GetPod
|
getPod = testutils.GetPod
|
||||||
|
runPausePod = testutils.RunPausePod
|
||||||
initPausePod = testutils.InitPausePod
|
initPausePod = testutils.InitPausePod
|
||||||
initTest = testutils.InitTestSchedulerWithNS
|
initTest = testutils.InitTestSchedulerWithNS
|
||||||
podScheduledIn = testutils.PodScheduledIn
|
podScheduledIn = testutils.PodScheduledIn
|
||||||
|
podScheduled = testutils.PodScheduled
|
||||||
podUnschedulable = testutils.PodUnschedulable
|
podUnschedulable = testutils.PodUnschedulable
|
||||||
waitForPodUnschedulable = testutils.WaitForPodUnschedulable
|
waitForPodUnschedulable = testutils.WaitForPodUnschedulable
|
||||||
)
|
)
|
||||||
@ -1822,6 +1824,129 @@ func TestPodTopologySpreadFilter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNodePortsFilter(t *testing.T) {
|
||||||
|
pause := imageutils.GetPauseImageName()
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
existingPods []*v1.Pod
|
||||||
|
incomingPod *v1.Pod
|
||||||
|
fit bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Port Conflict on Node",
|
||||||
|
existingPods: []*v1.Pod{
|
||||||
|
st.MakePod().Name("test-1").
|
||||||
|
Containers([]v1.Container{st.MakeContainer().Name("test-1-container").Image(pause).
|
||||||
|
ContainerPort([]v1.ContainerPort{
|
||||||
|
{
|
||||||
|
HostIP: "127.0.0.1",
|
||||||
|
ContainerPort: 8081,
|
||||||
|
HostPort: 8081,
|
||||||
|
Protocol: "TCP",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
HostIP: "127.0.0.1",
|
||||||
|
ContainerPort: 8082,
|
||||||
|
HostPort: 8082,
|
||||||
|
Protocol: "TCP",
|
||||||
|
},
|
||||||
|
}).Obj()}).
|
||||||
|
Obj(),
|
||||||
|
},
|
||||||
|
incomingPod: st.MakePod().Name("test-2").
|
||||||
|
Containers([]v1.Container{st.MakeContainer().Name("test-2-container").Image(pause).
|
||||||
|
ContainerPort([]v1.ContainerPort{
|
||||||
|
{
|
||||||
|
HostIP: "127.0.0.1",
|
||||||
|
ContainerPort: 8081,
|
||||||
|
HostPort: 8081,
|
||||||
|
Protocol: "TCP",
|
||||||
|
},
|
||||||
|
}).Obj()}).
|
||||||
|
Obj(),
|
||||||
|
fit: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "No Port Conflict on Node",
|
||||||
|
existingPods: []*v1.Pod{
|
||||||
|
st.MakePod().Name("test-1").
|
||||||
|
Containers([]v1.Container{st.MakeContainer().Name("test-1-container").Image(pause).
|
||||||
|
ContainerPort([]v1.ContainerPort{
|
||||||
|
{
|
||||||
|
HostIP: "127.0.0.1",
|
||||||
|
HostPort: 8081,
|
||||||
|
ContainerPort: 8081,
|
||||||
|
Protocol: "TCP",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
HostIP: "127.0.0.1",
|
||||||
|
HostPort: 8082,
|
||||||
|
ContainerPort: 8082,
|
||||||
|
Protocol: "TCP",
|
||||||
|
},
|
||||||
|
}).Obj()}).
|
||||||
|
Obj(),
|
||||||
|
},
|
||||||
|
incomingPod: st.MakePod().Name("test-2").
|
||||||
|
Containers([]v1.Container{st.MakeContainer().Name("test-2-container").Image(pause).
|
||||||
|
ContainerPort([]v1.ContainerPort{
|
||||||
|
{
|
||||||
|
HostIP: "127.0.0.1",
|
||||||
|
HostPort: 8080,
|
||||||
|
ContainerPort: 8080,
|
||||||
|
Protocol: "TCP",
|
||||||
|
},
|
||||||
|
}).Obj()}).
|
||||||
|
Obj(),
|
||||||
|
fit: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
testCtx := initTest(t, "node-ports-filter")
|
||||||
|
cs := testCtx.ClientSet
|
||||||
|
ns := testCtx.NS.Name
|
||||||
|
|
||||||
|
if _, err := createNode(cs, st.MakeNode().Name("node-0").Obj()); err != nil {
|
||||||
|
t.Fatalf("Failed to create node: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// set namespace to pods
|
||||||
|
tt.incomingPod.SetNamespace(ns)
|
||||||
|
for i := range tt.existingPods {
|
||||||
|
tt.existingPods[i].SetNamespace(ns)
|
||||||
|
}
|
||||||
|
allPods := append([]*v1.Pod{tt.incomingPod}, tt.existingPods...)
|
||||||
|
defer testutils.CleanupPods(testCtx.Ctx, cs, t, allPods)
|
||||||
|
|
||||||
|
for _, pod := range tt.existingPods {
|
||||||
|
if _, err := runPausePod(testCtx.ClientSet, pod); err != nil {
|
||||||
|
t.Fatalf("Failed to create existing pod: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
testPod, err := cs.CoreV1().Pods(tt.incomingPod.Namespace).Create(testCtx.Ctx, tt.incomingPod, metav1.CreateOptions{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to create pod during test: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if tt.fit {
|
||||||
|
err = wait.PollUntilContextTimeout(testCtx.Ctx, pollInterval, wait.ForeverTestTimeout, false,
|
||||||
|
podScheduled(cs, testPod.Namespace, testPod.Name))
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Test Failed: Expected pod %s/%s to be scheduled but got error: %v", testPod.Namespace, testPod.Name, err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = wait.PollUntilContextTimeout(testCtx.Ctx, pollInterval, wait.ForeverTestTimeout, false,
|
||||||
|
podUnschedulable(cs, testPod.Namespace, testPod.Name))
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Test Failed: Expected pod %s/%s to be unschedulable but got error: %v", testPod.Namespace, testPod.Name, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
hardSpread = v1.DoNotSchedule
|
hardSpread = v1.DoNotSchedule
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user