From 6e2ea32fc897653d2feded28da69951829475ce1 Mon Sep 17 00:00:00 2001 From: mantuliu <240951888@qq.com> Date: Wed, 10 May 2023 18:07:00 +0800 Subject: [PATCH] feature(DynamicResources): return Skip in PreFilter --- .../dynamicresources/dynamicresources.go | 8 +++---- .../dynamicresources/dynamicresources_test.go | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/pkg/scheduler/framework/plugins/dynamicresources/dynamicresources.go b/pkg/scheduler/framework/plugins/dynamicresources/dynamicresources.go index 081b77f51ce..7502408192d 100644 --- a/pkg/scheduler/framework/plugins/dynamicresources/dynamicresources.go +++ b/pkg/scheduler/framework/plugins/dynamicresources/dynamicresources.go @@ -305,7 +305,7 @@ func (pl *dynamicResources) podResourceClaims(pod *v1.Pod) ([]*resourcev1alpha2. // the pod cannot be scheduled at the moment on any node. func (pl *dynamicResources) PreFilter(ctx context.Context, state *framework.CycleState, pod *v1.Pod) (*framework.PreFilterResult, *framework.Status) { if !pl.enabled { - return nil, nil + return nil, framework.NewStatus(framework.Skip) } logger := klog.FromContext(ctx) @@ -321,10 +321,10 @@ func (pl *dynamicResources) PreFilter(ctx context.Context, state *framework.Cycl return nil, statusUnschedulable(logger, err.Error()) } logger.V(5).Info("pod resource claims", "pod", klog.KObj(pod), "resourceclaims", klog.KObjSlice(claims)) - // If the pod does not reference any claim, we don't need to do - // anything for it. + // If the pod does not reference any claim, + // DynamicResources Filter has nothing to do with the Pod. if len(claims) == 0 { - return nil, nil + return nil, framework.NewStatus(framework.Skip) } s.availableOnNodes = make([]*nodeaffinity.NodeSelector, len(claims)) diff --git a/pkg/scheduler/framework/plugins/dynamicresources/dynamicresources_test.go b/pkg/scheduler/framework/plugins/dynamicresources/dynamicresources_test.go index 5d09769aa39..ade79d3b9e2 100644 --- a/pkg/scheduler/framework/plugins/dynamicresources/dynamicresources_test.go +++ b/pkg/scheduler/framework/plugins/dynamicresources/dynamicresources_test.go @@ -207,9 +207,18 @@ func TestPlugin(t *testing.T) { prepare prepare want want + disable bool }{ "empty": { pod: st.MakePod().Name("foo").Namespace("default").Obj(), + want: want{ + prefilter: result{ + status: framework.NewStatus(framework.Skip), + }, + postfilter: result{ + status: framework.NewStatus(framework.Unschedulable, `no new claims to deallocate`), + }, + }, }, "claim-reference": { pod: podWithClaimName, @@ -437,6 +446,16 @@ func TestPlugin(t *testing.T) { pod: podWithClaimName, claims: []*resourcev1alpha2.ResourceClaim{inUseClaim}, }, + "disable": { + pod: podWithClaimName, + claims: []*resourcev1alpha2.ResourceClaim{inUseClaim}, + want: want{ + prefilter: result{ + status: framework.NewStatus(framework.Skip), + }, + }, + disable: true, + }, } for name, tc := range testcases { @@ -449,6 +468,7 @@ func TestPlugin(t *testing.T) { nodes = []*v1.Node{workerNode} } testCtx := setup(t, nodes, tc.claims, tc.classes, tc.schedulings) + testCtx.p.enabled = !tc.disable initialObjects := testCtx.listAll(t) result, status := testCtx.p.PreFilter(testCtx.ctx, testCtx.state, tc.pod) @@ -456,6 +476,9 @@ func TestPlugin(t *testing.T) { assert.Equal(t, tc.want.preFilterResult, result) testCtx.verify(t, tc.want.prefilter, initialObjects, result, status) }) + if status.IsSkip() { + return + } unschedulable := status.Code() != framework.Success var potentialNodes []*v1.Node