Skip to content

Commit d3edcb7

Browse files
authored
Merge pull request kubernetes#93490 from Huang-Wei/flake-post-filter
Fix integration test flake on TestFilter and TestPostFilter
2 parents 8e8b6a0 + 94fc18c commit d3edcb7

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

test/integration/scheduler/framework_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ 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"
3233
"k8s.io/kubernetes/pkg/scheduler"
3334
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
3435
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder"
@@ -216,6 +217,14 @@ func (sp *ScoreWithNormalizePlugin) ScoreExtensions() framework.ScoreExtensions
216217
return sp
217218
}
218219

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+
219228
// Name returns name of the plugin.
220229
func (fp *FilterPlugin) Name() string {
221230
return filterPluginName
@@ -230,7 +239,9 @@ func (fp *FilterPlugin) reset() {
230239
// Filter is a test function that returns an error or nil, depending on the
231240
// value of "failFilter".
232241
func (fp *FilterPlugin) Filter(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
233-
fp.numFilterCalled++
242+
if !schedAttempted(pod) {
243+
fp.numFilterCalled++
244+
}
234245

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

404415
func (pp *PostFilterPlugin) PostFilter(ctx context.Context, state *framework.CycleState, pod *v1.Pod, _ framework.NodeToStatusMap) (*framework.PostFilterResult, *framework.Status) {
405-
pp.numPostFilterCalled++
416+
if !schedAttempted(pod) {
417+
pp.numPostFilterCalled++
418+
}
419+
406420
nodeInfos, err := pp.fh.SnapshotSharedLister().NodeInfos().List()
407421
if err != nil {
408422
return nil, framework.NewStatus(framework.Error, err.Error())

0 commit comments

Comments
 (0)