mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-13 13:55:41 +00:00
Merge pull request #117903 from sourcelliu/dynamic
feature(DynamicResources): return Skip in PreFilter
This commit is contained in:
commit
bc8e312857
@ -305,7 +305,7 @@ func (pl *dynamicResources) podResourceClaims(pod *v1.Pod) ([]*resourcev1alpha2.
|
|||||||
// the pod cannot be scheduled at the moment on any node.
|
// 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) {
|
func (pl *dynamicResources) PreFilter(ctx context.Context, state *framework.CycleState, pod *v1.Pod) (*framework.PreFilterResult, *framework.Status) {
|
||||||
if !pl.enabled {
|
if !pl.enabled {
|
||||||
return nil, nil
|
return nil, framework.NewStatus(framework.Skip)
|
||||||
}
|
}
|
||||||
logger := klog.FromContext(ctx)
|
logger := klog.FromContext(ctx)
|
||||||
|
|
||||||
@ -321,10 +321,10 @@ func (pl *dynamicResources) PreFilter(ctx context.Context, state *framework.Cycl
|
|||||||
return nil, statusUnschedulable(logger, err.Error())
|
return nil, statusUnschedulable(logger, err.Error())
|
||||||
}
|
}
|
||||||
logger.V(5).Info("pod resource claims", "pod", klog.KObj(pod), "resourceclaims", klog.KObjSlice(claims))
|
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
|
// If the pod does not reference any claim,
|
||||||
// anything for it.
|
// DynamicResources Filter has nothing to do with the Pod.
|
||||||
if len(claims) == 0 {
|
if len(claims) == 0 {
|
||||||
return nil, nil
|
return nil, framework.NewStatus(framework.Skip)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.availableOnNodes = make([]*nodeaffinity.NodeSelector, len(claims))
|
s.availableOnNodes = make([]*nodeaffinity.NodeSelector, len(claims))
|
||||||
|
@ -207,9 +207,18 @@ func TestPlugin(t *testing.T) {
|
|||||||
|
|
||||||
prepare prepare
|
prepare prepare
|
||||||
want want
|
want want
|
||||||
|
disable bool
|
||||||
}{
|
}{
|
||||||
"empty": {
|
"empty": {
|
||||||
pod: st.MakePod().Name("foo").Namespace("default").Obj(),
|
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": {
|
"claim-reference": {
|
||||||
pod: podWithClaimName,
|
pod: podWithClaimName,
|
||||||
@ -463,6 +472,16 @@ func TestPlugin(t *testing.T) {
|
|||||||
pod: podWithClaimName,
|
pod: podWithClaimName,
|
||||||
claims: []*resourcev1alpha2.ResourceClaim{inUseClaim},
|
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 {
|
for name, tc := range testcases {
|
||||||
@ -475,6 +494,7 @@ func TestPlugin(t *testing.T) {
|
|||||||
nodes = []*v1.Node{workerNode}
|
nodes = []*v1.Node{workerNode}
|
||||||
}
|
}
|
||||||
testCtx := setup(t, nodes, tc.claims, tc.classes, tc.schedulings)
|
testCtx := setup(t, nodes, tc.claims, tc.classes, tc.schedulings)
|
||||||
|
testCtx.p.enabled = !tc.disable
|
||||||
|
|
||||||
initialObjects := testCtx.listAll(t)
|
initialObjects := testCtx.listAll(t)
|
||||||
result, status := testCtx.p.PreFilter(testCtx.ctx, testCtx.state, tc.pod)
|
result, status := testCtx.p.PreFilter(testCtx.ctx, testCtx.state, tc.pod)
|
||||||
@ -482,6 +502,9 @@ func TestPlugin(t *testing.T) {
|
|||||||
assert.Equal(t, tc.want.preFilterResult, result)
|
assert.Equal(t, tc.want.preFilterResult, result)
|
||||||
testCtx.verify(t, tc.want.prefilter, initialObjects, result, status)
|
testCtx.verify(t, tc.want.prefilter, initialObjects, result, status)
|
||||||
})
|
})
|
||||||
|
if status.IsSkip() {
|
||||||
|
return
|
||||||
|
}
|
||||||
unschedulable := status.Code() != framework.Success
|
unschedulable := status.Code() != framework.Success
|
||||||
|
|
||||||
var potentialNodes []*v1.Node
|
var potentialNodes []*v1.Node
|
||||||
|
Loading…
Reference in New Issue
Block a user