Skip to content

Commit 6cf4ab3

Browse files
authored
Merge pull request kubernetes#91071 from alculquicondor/integration_new_node
Add test case for a pod becoming schedulable when a node is added
2 parents 0e8a2d2 + c8e2d5b commit 6cf4ab3

File tree

7 files changed

+118
-66
lines changed

7 files changed

+118
-66
lines changed

test/integration/scheduler/framework_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ func TestPreFilterPlugin(t *testing.T) {
507507
preFilterPlugin.rejectPreFilter = test.reject
508508
// Create a best effort pod.
509509
pod, err := createPausePod(testCtx.ClientSet,
510-
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
510+
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
511511
if err != nil {
512512
t.Errorf("Error while creating a test pod: %v", err)
513513
}
@@ -559,7 +559,7 @@ func TestScorePlugin(t *testing.T) {
559559
scorePlugin.failScore = fail
560560
// Create a best effort pod.
561561
pod, err := createPausePod(testCtx.ClientSet,
562-
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
562+
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
563563
if err != nil {
564564
t.Fatalf("Error while creating a test pod: %v", err)
565565
}
@@ -617,7 +617,7 @@ func TestNormalizeScorePlugin(t *testing.T) {
617617

618618
// Create a best effort pod.
619619
pod, err := createPausePod(testCtx.ClientSet,
620-
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
620+
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
621621
if err != nil {
622622
t.Fatalf("Error while creating a test pod: %v", err)
623623
}
@@ -666,7 +666,7 @@ func TestReservePlugin(t *testing.T) {
666666
reservePlugin.failReserve = fail
667667
// Create a best effort pod.
668668
pod, err := createPausePod(testCtx.ClientSet,
669-
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
669+
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
670670
if err != nil {
671671
t.Errorf("Error while creating a test pod: %v", err)
672672
}
@@ -744,7 +744,7 @@ func TestPrebindPlugin(t *testing.T) {
744744
preBindPlugin.rejectPreBind = test.reject
745745
// Create a best effort pod.
746746
pod, err := createPausePod(testCtx.ClientSet,
747-
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
747+
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
748748
if err != nil {
749749
t.Errorf("Error while creating a test pod: %v", err)
750750
}
@@ -819,7 +819,7 @@ func TestUnreservePlugin(t *testing.T) {
819819

820820
// Create a best effort pod.
821821
pod, err := createPausePod(testCtx.ClientSet,
822-
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
822+
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
823823
if err != nil {
824824
t.Errorf("Error while creating a test pod: %v", err)
825825
}
@@ -953,7 +953,7 @@ func TestBindPlugin(t *testing.T) {
953953

954954
// Create a best effort pod.
955955
pod, err := createPausePod(testCtx.ClientSet,
956-
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
956+
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
957957
if err != nil {
958958
t.Errorf("Error while creating a test pod: %v", err)
959959
}
@@ -1080,7 +1080,7 @@ func TestPostBindPlugin(t *testing.T) {
10801080

10811081
// Create a best effort pod.
10821082
pod, err := createPausePod(testCtx.ClientSet,
1083-
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
1083+
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
10841084
if err != nil {
10851085
t.Errorf("Error while creating a test pod: %v", err)
10861086
}
@@ -1165,7 +1165,7 @@ func TestPermitPlugin(t *testing.T) {
11651165

11661166
// Create a best effort pod.
11671167
pod, err := createPausePod(testCtx.ClientSet,
1168-
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
1168+
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
11691169
if err != nil {
11701170
t.Errorf("Error while creating a test pod: %v", err)
11711171
}
@@ -1214,7 +1214,7 @@ func TestMultiplePermitPlugins(t *testing.T) {
12141214
// Create a test pod.
12151215
podName := "test-pod"
12161216
pod, err := createPausePod(testCtx.ClientSet,
1217-
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: podName, Namespace: testCtx.NS.Name}))
1217+
initPausePod(&pausePodConfig{Name: podName, Namespace: testCtx.NS.Name}))
12181218
if err != nil {
12191219
t.Errorf("Error while creating a test pod: %v", err)
12201220
}
@@ -1269,7 +1269,7 @@ func TestPermitPluginsCancelled(t *testing.T) {
12691269
// Create a test pod.
12701270
podName := "test-pod"
12711271
pod, err := createPausePod(testCtx.ClientSet,
1272-
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: podName, Namespace: testCtx.NS.Name}))
1272+
initPausePod(&pausePodConfig{Name: podName, Namespace: testCtx.NS.Name}))
12731273
if err != nil {
12741274
t.Errorf("Error while creating a test pod: %v", err)
12751275
}
@@ -1328,12 +1328,12 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
13281328
// Create two pods. First pod to enter Permit() will wait and a second one will either
13291329
// reject or allow first one.
13301330
podA, err := createPausePod(testCtx.ClientSet,
1331-
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "pod-a", Namespace: testCtx.NS.Name}))
1331+
initPausePod(&pausePodConfig{Name: "pod-a", Namespace: testCtx.NS.Name}))
13321332
if err != nil {
13331333
t.Errorf("Error while creating the first pod: %v", err)
13341334
}
13351335
podB, err := createPausePod(testCtx.ClientSet,
1336-
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "pod-b", Namespace: testCtx.NS.Name}))
1336+
initPausePod(&pausePodConfig{Name: "pod-b", Namespace: testCtx.NS.Name}))
13371337
if err != nil {
13381338
t.Errorf("Error while creating the second pod: %v", err)
13391339
}
@@ -1403,7 +1403,7 @@ func TestFilterPlugin(t *testing.T) {
14031403
filterPlugin.failFilter = fail
14041404
// Create a best effort pod.
14051405
pod, err := createPausePod(testCtx.ClientSet,
1406-
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
1406+
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
14071407
if err != nil {
14081408
t.Errorf("Error while creating a test pod: %v", err)
14091409
}
@@ -1457,7 +1457,7 @@ func TestPreScorePlugin(t *testing.T) {
14571457
preScorePlugin.failPreScore = fail
14581458
// Create a best effort pod.
14591459
pod, err := createPausePod(testCtx.ClientSet,
1460-
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
1460+
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
14611461
if err != nil {
14621462
t.Errorf("Error while creating a test pod: %v", err)
14631463
}
@@ -1517,7 +1517,7 @@ func TestPreemptWithPermitPlugin(t *testing.T) {
15171517
}
15181518

15191519
// First pod will go waiting.
1520-
waitingPod := initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "waiting-pod", Namespace: testCtx.NS.Name, Priority: &lowPriority, Resources: &resourceRequest})
1520+
waitingPod := initPausePod(&pausePodConfig{Name: "waiting-pod", Namespace: testCtx.NS.Name, Priority: &lowPriority, Resources: &resourceRequest})
15211521
waitingPod.Spec.TerminationGracePeriodSeconds = new(int64)
15221522
waitingPod, err = createPausePod(testCtx.ClientSet, waitingPod)
15231523
if err != nil {
@@ -1532,7 +1532,7 @@ func TestPreemptWithPermitPlugin(t *testing.T) {
15321532

15331533
// Create second pod which should preempt first pod.
15341534
preemptorPod, err := createPausePod(testCtx.ClientSet,
1535-
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "preemptor-pod", Namespace: testCtx.NS.Name, Priority: &highPriority, Resources: &resourceRequest}))
1535+
initPausePod(&pausePodConfig{Name: "preemptor-pod", Namespace: testCtx.NS.Name, Priority: &highPriority, Resources: &resourceRequest}))
15361536
if err != nil {
15371537
t.Errorf("Error while creating the preemptor pod: %v", err)
15381538
}

test/integration/scheduler/plugins_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestNodeResourceLimits(t *testing.T) {
5454
}
5555

5656
podName := "pod-with-resource-limits"
57-
pod, err := runPausePod(testCtx.ClientSet, initPausePod(testCtx.ClientSet, &pausePodConfig{
57+
pod, err := runPausePod(testCtx.ClientSet, initPausePod(&pausePodConfig{
5858
Name: podName,
5959
Namespace: testCtx.NS.Name,
6060
Resources: &v1.ResourceRequirements{Requests: v1.ResourceList{

test/integration/scheduler/predicates_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828
"k8s.io/apimachinery/pkg/util/wait"
2929
utilfeature "k8s.io/apiserver/pkg/util/feature"
30+
"k8s.io/client-go/kubernetes"
3031
featuregatetesting "k8s.io/component-base/featuregate/testing"
3132
"k8s.io/kubernetes/pkg/features"
3233
st "k8s.io/kubernetes/pkg/scheduler/testing"
@@ -1036,3 +1037,54 @@ var (
10361037
hardSpread = v1.DoNotSchedule
10371038
softSpread = v1.ScheduleAnyway
10381039
)
1040+
1041+
func TestUnschedulablePodBecomesSchedulable(t *testing.T) {
1042+
tests := []struct {
1043+
name string
1044+
init func(kubernetes.Interface) error
1045+
pod *pausePodConfig
1046+
update func(kubernetes.Interface) error
1047+
}{
1048+
{
1049+
name: "node gets added",
1050+
pod: &pausePodConfig{
1051+
Name: "pod-1",
1052+
},
1053+
update: func(cs kubernetes.Interface) error {
1054+
_, err := createNode(cs, "node-1", nil)
1055+
return err
1056+
},
1057+
},
1058+
// TODO(#91111): Add more test cases.
1059+
}
1060+
for _, tt := range tests {
1061+
t.Run(tt.name, func(t *testing.T) {
1062+
testCtx := initTest(t, "scheduler-informer")
1063+
defer testutils.CleanupTest(t, testCtx)
1064+
if tt.init != nil {
1065+
if err := tt.init(testCtx.ClientSet); err != nil {
1066+
t.Fatal(err)
1067+
}
1068+
}
1069+
tt.pod.Namespace = testCtx.NS.Name
1070+
pod, err := createPausePod(testCtx.ClientSet, initPausePod(tt.pod))
1071+
if err != nil {
1072+
t.Fatal(err)
1073+
}
1074+
if err := waitForPodUnschedulable(testCtx.ClientSet, pod); err != nil {
1075+
t.Errorf("Pod %v got scheduled: %v", pod.Name, err)
1076+
}
1077+
if err := tt.update(testCtx.ClientSet); err != nil {
1078+
t.Fatal(err)
1079+
}
1080+
if err := testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
1081+
t.Errorf("Pod %v was not scheduled: %v", pod.Name, err)
1082+
}
1083+
// Make sure pending queue is empty.
1084+
pendingPods := len(testCtx.Scheduler.SchedulingQueue.PendingPods())
1085+
if pendingPods != 0 {
1086+
t.Errorf("pending pods queue is not empty, size is: %d", pendingPods)
1087+
}
1088+
})
1089+
}
1090+
}

0 commit comments

Comments
 (0)