feature(DynamicResources): return Skip in PreFilter

This commit is contained in:
mantuliu 2023-05-10 18:07:00 +08:00
parent fda4ca0d8a
commit 6e2ea32fc8
2 changed files with 27 additions and 4 deletions

View File

@ -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))

View File

@ -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