From e2f51253c7e3767f3e8cfb5861dd6cf023903a43 Mon Sep 17 00:00:00 2001 From: "wangjianyu.wjy" Date: Fri, 24 May 2024 18:19:42 +0800 Subject: [PATCH] scheduler: make gang quickCheck earlier Signed-off-by: wangjianyu.wjy --- .../plugins/coscheduling/coscheduling.go | 17 +++++++++++++---- .../plugins/coscheduling/coscheduling_test.go | 7 ++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/pkg/scheduler/plugins/coscheduling/coscheduling.go b/pkg/scheduler/plugins/coscheduling/coscheduling.go index debc52cea..27fb91389 100644 --- a/pkg/scheduler/plugins/coscheduling/coscheduling.go +++ b/pkg/scheduler/plugins/coscheduling/coscheduling.go @@ -50,6 +50,7 @@ type Coscheduling struct { } var _ framework.QueueSortPlugin = &Coscheduling{} +var _ frameworkext.PreFilterTransformer = &Coscheduling{} var _ framework.PreFilterPlugin = &Coscheduling{} var _ framework.PostFilterPlugin = &Coscheduling{} var _ framework.PermitPlugin = &Coscheduling{} @@ -160,19 +161,27 @@ func (cs *Coscheduling) Less(podInfo1, podInfo2 *framework.QueuedPodInfo) bool { return podInfo1.Pod.Name < podInfo2.Pod.Name } -// PreFilter +// BeforePreFilter // if non-strict-mode, we only do step1 and step2: // i.Check whether childes in Gang has met the requirements of minimum number under each Gang, and reject the pod if negative. // ii.Check whether the Gang has been timeout(check the pod's annotation,later introduced at Permit section) or is inited, and reject the pod if positive. // iii.Check whether the Gang has met the scheduleCycleValid check, and reject the pod if negative. // iv.Try update scheduleCycle, scheduleCycleValid, childrenScheduleRoundMap as mentioned above. -func (cs *Coscheduling) PreFilter(ctx context.Context, state *framework.CycleState, pod *v1.Pod) (*framework.PreFilterResult, *framework.Status) { +func (cs *Coscheduling) BeforePreFilter(ctx context.Context, state *framework.CycleState, pod *v1.Pod) (*v1.Pod, bool, *framework.Status) { // If PreFilter fails, return framework.UnschedulableAndUnresolvable to avoid any preemption attempts. if err := cs.pgMgr.PreFilter(ctx, state, pod); err != nil { klog.ErrorS(err, "PreFilter failed", "pod", klog.KObj(pod)) - return nil, framework.NewStatus(framework.UnschedulableAndUnresolvable, err.Error()) + return nil, false, framework.NewStatus(framework.UnschedulableAndUnresolvable, err.Error()) } - return nil, framework.NewStatus(framework.Success, "") + return nil, false, framework.NewStatus(framework.Success, "") +} + +func (cs *Coscheduling) PreFilter(ctx context.Context, state *framework.CycleState, pod *v1.Pod) (*framework.PreFilterResult, *framework.Status) { + return nil, nil +} + +func (cs *Coscheduling) AfterPreFilter(ctx context.Context, state *framework.CycleState, pod *v1.Pod) *framework.Status { + return nil } // PostFilter diff --git a/pkg/scheduler/plugins/coscheduling/coscheduling_test.go b/pkg/scheduler/plugins/coscheduling/coscheduling_test.go index 8aed75518..627e0ab3a 100644 --- a/pkg/scheduler/plugins/coscheduling/coscheduling_test.go +++ b/pkg/scheduler/plugins/coscheduling/coscheduling_test.go @@ -1145,7 +1145,7 @@ func simulateScheduleOne(t *testing.T, ctx context.Context, sched *scheduler.Sch schedulingCycleCtx, cancel := context.WithCancel(ctx) defer cancel() - scheduleResult, err := schedulePod(schedulingCycleCtx, fwk, state, pod, scheduleInfo, injectFilterErr(pod)) + scheduleResult, err := schedulePod(schedulingCycleCtx, suit, fwk, state, pod, scheduleInfo, injectFilterErr(pod)) if err != nil { // SchedulePod() may have failed because the pod would not fit on any host, so we try to // preempt, with the expectation that the next time the pod is tried for scheduling it @@ -1212,13 +1212,14 @@ func simulateScheduleOne(t *testing.T, ctx context.Context, sched *scheduler.Sch }() } -func schedulePod(ctx context.Context, fwk framework.Framework, state *framework.CycleState, pod *corev1.Pod, info *debugPodScheduleInfo, injectFilterError bool) (result scheduler.ScheduleResult, err error) { +func schedulePod(ctx context.Context, suit *pluginTestSuit, fwk framework.Framework, state *framework.CycleState, pod *corev1.Pod, info *debugPodScheduleInfo, injectFilterError bool) (result scheduler.ScheduleResult, err error) { diagnosis := framework.Diagnosis{ NodeToStatusMap: make(framework.NodeToStatusMap), UnschedulablePlugins: sets.Set[string]{}, } // Run "prefilter" plugins. + suit.plugin.(*Coscheduling).BeforePreFilter(ctx, state, pod) _, s := fwk.RunPreFilterPlugins(ctx, state, pod) if !s.IsSuccess() { info.result = "PreFiler" @@ -1453,7 +1454,7 @@ func TestNoRejectWhenInvalidCycle(t *testing.T) { _, status := suit.plugin.(*Coscheduling).PostFilter(ctx, framework.NewCycleState(), allPods[0], nil) assert.False(t, status.IsSuccess()) - _, status = suit.plugin.(*Coscheduling).PreFilter(ctx, framework.NewCycleState(), memberPodsOfGang[util.GetId("default", gangNames[0])][0]) + _, _, status = suit.plugin.(*Coscheduling).BeforePreFilter(ctx, framework.NewCycleState(), memberPodsOfGang[util.GetId("default", gangNames[0])][0]) assert.False(t, status.IsSuccess()) for i := 0; i < 5; i++ {