Skip to content

Commit c8e2d5b

Browse files
Add test case for a pod becoming schedulable when a node is added
We have little coverage around node addition and removal. Since distinct event handlers interact, it is important to cover this in integration tests. Signed-off-by: Aldo Culquicondor <[email protected]>
1 parent 35b9ab1 commit c8e2d5b

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

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)