Skip to content

Commit 9af4ad5

Browse files
authored
Merge pull request kubernetes#93550 from Huang-Wei/refix-postfilter-flake
Deflake scheduler PostFilter and Filter integration test
2 parents db28b02 + 539272c commit 9af4ad5

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

test/integration/scheduler/framework_test.go

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"k8s.io/apimachinery/pkg/runtime"
3030
"k8s.io/apimachinery/pkg/util/wait"
3131
clientset "k8s.io/client-go/kubernetes"
32-
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
3332
"k8s.io/kubernetes/pkg/scheduler"
3433
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
3534
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder"
@@ -217,14 +216,6 @@ func (sp *ScoreWithNormalizePlugin) ScoreExtensions() framework.ScoreExtensions
217216
return sp
218217
}
219218

220-
// schedAttempted returns true if the scheduler already attempted to schedule the pod.
221-
// Note that the logic used here works only for our integration tests because kubelet is not running,
222-
// and so the condition will continue to exist even if the pod eventually got scheduled.
223-
func schedAttempted(pod *v1.Pod) bool {
224-
_, cond := podutil.GetPodCondition(&pod.Status, v1.PodScheduled)
225-
return cond != nil && cond.Status == v1.ConditionFalse && cond.Reason == v1.PodReasonUnschedulable
226-
}
227-
228219
// Name returns name of the plugin.
229220
func (fp *FilterPlugin) Name() string {
230221
return filterPluginName
@@ -239,9 +230,7 @@ func (fp *FilterPlugin) reset() {
239230
// Filter is a test function that returns an error or nil, depending on the
240231
// value of "failFilter".
241232
func (fp *FilterPlugin) Filter(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
242-
if !schedAttempted(pod) {
243-
fp.numFilterCalled++
244-
}
233+
fp.numFilterCalled++
245234

246235
if fp.failFilter {
247236
return framework.NewStatus(framework.Error, fmt.Sprintf("injecting failure for pod %v", pod.Name))
@@ -413,10 +402,7 @@ func (pp *PostFilterPlugin) Name() string {
413402
}
414403

415404
func (pp *PostFilterPlugin) PostFilter(ctx context.Context, state *framework.CycleState, pod *v1.Pod, _ framework.NodeToStatusMap) (*framework.PostFilterResult, *framework.Status) {
416-
if !schedAttempted(pod) {
417-
pp.numPostFilterCalled++
418-
}
419-
405+
pp.numPostFilterCalled++
420406
nodeInfos, err := pp.fh.SnapshotSharedLister().NodeInfos().List()
421407
if err != nil {
422408
return nil, framework.NewStatus(framework.Error, err.Error())
@@ -676,17 +662,22 @@ func TestPostFilterPlugin(t *testing.T) {
676662
if err = wait.Poll(10*time.Millisecond, 10*time.Second, podUnschedulable(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
677663
t.Errorf("Didn't expect the pod to be scheduled.")
678664
}
665+
if filterPlugin.numFilterCalled < tt.expectFilterNumCalled {
666+
t.Errorf("Expected the filter plugin to be called at least %v times, but got %v.", tt.expectFilterNumCalled, filterPlugin.numFilterCalled)
667+
}
668+
if postFilterPlugin.numPostFilterCalled < tt.expectPostFilterNumCalled {
669+
t.Errorf("Expected the postfilter plugin to be called at least %v times, but got %v.", tt.expectPostFilterNumCalled, postFilterPlugin.numPostFilterCalled)
670+
}
679671
} else {
680672
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
681673
t.Errorf("Expected the pod to be scheduled. error: %v", err)
682674
}
683-
}
684-
685-
if filterPlugin.numFilterCalled != tt.expectFilterNumCalled {
686-
t.Errorf("Expected the filter plugin to be called %v times, but got %v.", tt.expectFilterNumCalled, filterPlugin.numFilterCalled)
687-
}
688-
if postFilterPlugin.numPostFilterCalled != tt.expectPostFilterNumCalled {
689-
t.Errorf("Expected the postfilter plugin to be called %v times, but got %v.", tt.expectPostFilterNumCalled, postFilterPlugin.numPostFilterCalled)
675+
if filterPlugin.numFilterCalled != tt.expectFilterNumCalled {
676+
t.Errorf("Expected the filter plugin to be called %v times, but got %v.", tt.expectFilterNumCalled, filterPlugin.numFilterCalled)
677+
}
678+
if postFilterPlugin.numPostFilterCalled != tt.expectPostFilterNumCalled {
679+
t.Errorf("Expected the postfilter plugin to be called %v times, but got %v.", tt.expectPostFilterNumCalled, postFilterPlugin.numPostFilterCalled)
680+
}
690681
}
691682
})
692683
}
@@ -1688,14 +1679,16 @@ func TestFilterPlugin(t *testing.T) {
16881679
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podUnschedulable(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
16891680
t.Errorf("Didn't expect the pod to be scheduled.")
16901681
}
1682+
if filterPlugin.numFilterCalled < 1 {
1683+
t.Errorf("Expected the filter plugin to be called at least 1 time, but got %v.", filterPlugin.numFilterCalled)
1684+
}
16911685
} else {
16921686
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
16931687
t.Errorf("Expected the pod to be scheduled. error: %v", err)
16941688
}
1695-
}
1696-
1697-
if filterPlugin.numFilterCalled != 1 {
1698-
t.Errorf("Expected the filter plugin to be called 1 time, but got %v.", filterPlugin.numFilterCalled)
1689+
if filterPlugin.numFilterCalled != 1 {
1690+
t.Errorf("Expected the filter plugin to be called 1 time, but got %v.", filterPlugin.numFilterCalled)
1691+
}
16991692
}
17001693

17011694
filterPlugin.reset()

0 commit comments

Comments
 (0)