mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 18:24:07 +00:00
fix(dra plugin): when there is no resourceclaim, return directly
This commit is contained in:
parent
27ec5de863
commit
ed826dddfe
@ -576,6 +576,11 @@ func (pl *DynamicResources) PostFilter(ctx context.Context, cs *framework.CycleS
|
|||||||
if !pl.enabled {
|
if !pl.enabled {
|
||||||
return nil, framework.NewStatus(framework.Unschedulable, "plugin disabled")
|
return nil, framework.NewStatus(framework.Unschedulable, "plugin disabled")
|
||||||
}
|
}
|
||||||
|
// If a Pod doesn't have any resource claims attached to it, there is no need for further processing.
|
||||||
|
// Thus we provide a fast path for this case to avoid unnecessary computations.
|
||||||
|
if len(pod.Spec.ResourceClaims) == 0 {
|
||||||
|
return nil, framework.NewStatus(framework.Unschedulable)
|
||||||
|
}
|
||||||
logger := klog.FromContext(ctx)
|
logger := klog.FromContext(ctx)
|
||||||
state, err := getStateData(cs)
|
state, err := getStateData(cs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -290,6 +290,8 @@ func TestPlugin(t *testing.T) {
|
|||||||
prepare prepare
|
prepare prepare
|
||||||
want want
|
want want
|
||||||
|
|
||||||
|
// enableDRAAdminAccess is set to true if the DRAAdminAccess feature gate is enabled.
|
||||||
|
enableDRAAdminAccess bool
|
||||||
// Feature gates. False is chosen so that the uncommon case
|
// Feature gates. False is chosen so that the uncommon case
|
||||||
// doesn't need to be set.
|
// doesn't need to be set.
|
||||||
disableDRA bool
|
disableDRA bool
|
||||||
@ -301,7 +303,7 @@ func TestPlugin(t *testing.T) {
|
|||||||
status: framework.NewStatus(framework.Skip),
|
status: framework.NewStatus(framework.Skip),
|
||||||
},
|
},
|
||||||
postfilter: result{
|
postfilter: result{
|
||||||
status: framework.NewStatus(framework.Unschedulable, `no new claims to deallocate`),
|
status: framework.NewStatus(framework.Unschedulable),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -554,9 +556,10 @@ func TestPlugin(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"request-admin-access": {
|
"request-admin-access-with-DRAAdminAccess-featuregate": {
|
||||||
// Because the pending claim asks for admin access, allocation succeeds despite resources
|
// When the DRAAdminAccess feature gate is enabled,
|
||||||
// being exhausted.
|
// Because the pending claim asks for admin access,
|
||||||
|
// allocation succeeds despite resources being exhausted.
|
||||||
pod: podWithClaimName,
|
pod: podWithClaimName,
|
||||||
claims: []*resourceapi.ResourceClaim{adminAccess(pendingClaim), otherAllocatedClaim},
|
claims: []*resourceapi.ResourceClaim{adminAccess(pendingClaim), otherAllocatedClaim},
|
||||||
classes: []*resourceapi.DeviceClass{deviceClass},
|
classes: []*resourceapi.DeviceClass{deviceClass},
|
||||||
@ -582,6 +585,24 @@ func TestPlugin(t *testing.T) {
|
|||||||
assumedClaim: reserve(adminAccess(allocatedClaim), podWithClaimName),
|
assumedClaim: reserve(adminAccess(allocatedClaim), podWithClaimName),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
enableDRAAdminAccess: true,
|
||||||
|
},
|
||||||
|
"request-admin-access-without-DRAAdminAccess-featuregate": {
|
||||||
|
// When the DRAAdminAccess feature gate is disabled,
|
||||||
|
// even though the pending claim requests admin access,
|
||||||
|
// the scheduler returns an unschedulable status.
|
||||||
|
pod: podWithClaimName,
|
||||||
|
claims: []*resourceapi.ResourceClaim{adminAccess(pendingClaim), otherAllocatedClaim},
|
||||||
|
classes: []*resourceapi.DeviceClass{deviceClass},
|
||||||
|
objs: []apiruntime.Object{workerNodeSlice},
|
||||||
|
want: want{
|
||||||
|
filter: perNodeResult{
|
||||||
|
workerNode.Name: {
|
||||||
|
status: framework.NewStatus(framework.UnschedulableAndUnresolvable, `claim default/my-pod-my-resource, request req-1: admin access is requested, but the feature is disabled`),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
enableDRAAdminAccess: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
"structured-ignore-allocated-admin-access": {
|
"structured-ignore-allocated-admin-access": {
|
||||||
@ -768,6 +789,9 @@ func TestPlugin(t *testing.T) {
|
|||||||
prefilter: result{
|
prefilter: result{
|
||||||
status: framework.NewStatus(framework.Skip),
|
status: framework.NewStatus(framework.Skip),
|
||||||
},
|
},
|
||||||
|
postfilter: result{
|
||||||
|
status: framework.NewStatus(framework.Unschedulable, `plugin disabled`),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
disableDRA: true,
|
disableDRA: true,
|
||||||
},
|
},
|
||||||
@ -783,6 +807,7 @@ func TestPlugin(t *testing.T) {
|
|||||||
nodes = []*v1.Node{workerNode}
|
nodes = []*v1.Node{workerNode}
|
||||||
}
|
}
|
||||||
features := feature.Features{
|
features := feature.Features{
|
||||||
|
EnableDRAAdminAccess: tc.enableDRAAdminAccess,
|
||||||
EnableDynamicResourceAllocation: !tc.disableDRA,
|
EnableDynamicResourceAllocation: !tc.disableDRA,
|
||||||
}
|
}
|
||||||
testCtx := setup(t, nodes, tc.claims, tc.classes, tc.objs, features)
|
testCtx := setup(t, nodes, tc.claims, tc.classes, tc.objs, features)
|
||||||
@ -801,9 +826,6 @@ 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 []*framework.NodeInfo
|
var potentialNodes []*framework.NodeInfo
|
||||||
@ -912,9 +934,9 @@ type testContext struct {
|
|||||||
|
|
||||||
func (tc *testContext) verify(t *testing.T, expected result, initialObjects []metav1.Object, result interface{}, status *framework.Status) {
|
func (tc *testContext) verify(t *testing.T, expected result, initialObjects []metav1.Object, result interface{}, status *framework.Status) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
if expectedErr := status.AsError(); expectedErr != nil {
|
if actualErr := status.AsError(); actualErr != nil {
|
||||||
// Compare only the error strings.
|
// Compare only the error strings.
|
||||||
assert.ErrorContains(t, status.AsError(), expectedErr.Error())
|
assert.ErrorContains(t, actualErr, expected.status.AsError().Error())
|
||||||
} else {
|
} else {
|
||||||
assert.Equal(t, expected.status, status)
|
assert.Equal(t, expected.status, status)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user