Skip to content

Commit 223ac36

Browse files
authored
Merge pull request kubernetes#128399 from JesseStutler/dra
Refactor the dynamicResources struct to DynamicResources
2 parents 74b9204 + f7003c7 commit 223ac36

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

pkg/scheduler/framework/plugins/dynamicresources/dynamicresources.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ type informationForClaim struct {
100100
allocation *resourceapi.AllocationResult
101101
}
102102

103-
// dynamicResources is a plugin that ensures that ResourceClaims are allocated.
104-
type dynamicResources struct {
103+
// DynamicResources is a plugin that ensures that ResourceClaims are allocated.
104+
type DynamicResources struct {
105105
enabled bool
106106
enableAdminAccess bool
107107
enableSchedulingQueueHint bool
@@ -171,10 +171,10 @@ type dynamicResources struct {
171171
func New(ctx context.Context, plArgs runtime.Object, fh framework.Handle, fts feature.Features) (framework.Plugin, error) {
172172
if !fts.EnableDynamicResourceAllocation {
173173
// Disabled, won't do anything.
174-
return &dynamicResources{}, nil
174+
return &DynamicResources{}, nil
175175
}
176176

177-
pl := &dynamicResources{
177+
pl := &DynamicResources{
178178
enabled: true,
179179
enableAdminAccess: fts.EnableDRAAdminAccess,
180180
enableSchedulingQueueHint: fts.EnableSchedulingQueueHint,
@@ -189,22 +189,22 @@ func New(ctx context.Context, plArgs runtime.Object, fh framework.Handle, fts fe
189189
return pl, nil
190190
}
191191

192-
var _ framework.PreEnqueuePlugin = &dynamicResources{}
193-
var _ framework.PreFilterPlugin = &dynamicResources{}
194-
var _ framework.FilterPlugin = &dynamicResources{}
195-
var _ framework.PostFilterPlugin = &dynamicResources{}
196-
var _ framework.ReservePlugin = &dynamicResources{}
197-
var _ framework.EnqueueExtensions = &dynamicResources{}
198-
var _ framework.PreBindPlugin = &dynamicResources{}
192+
var _ framework.PreEnqueuePlugin = &DynamicResources{}
193+
var _ framework.PreFilterPlugin = &DynamicResources{}
194+
var _ framework.FilterPlugin = &DynamicResources{}
195+
var _ framework.PostFilterPlugin = &DynamicResources{}
196+
var _ framework.ReservePlugin = &DynamicResources{}
197+
var _ framework.EnqueueExtensions = &DynamicResources{}
198+
var _ framework.PreBindPlugin = &DynamicResources{}
199199

200200
// Name returns name of the plugin. It is used in logs, etc.
201-
func (pl *dynamicResources) Name() string {
201+
func (pl *DynamicResources) Name() string {
202202
return Name
203203
}
204204

205205
// EventsToRegister returns the possible events that may make a Pod
206206
// failed by this plugin schedulable.
207-
func (pl *dynamicResources) EventsToRegister(_ context.Context) ([]framework.ClusterEventWithHint, error) {
207+
func (pl *DynamicResources) EventsToRegister(_ context.Context) ([]framework.ClusterEventWithHint, error) {
208208
if !pl.enabled {
209209
return nil, nil
210210
}
@@ -239,7 +239,7 @@ func (pl *dynamicResources) EventsToRegister(_ context.Context) ([]framework.Clu
239239
// PreEnqueue checks if there are known reasons why a pod currently cannot be
240240
// scheduled. When this fails, one of the registered events can trigger another
241241
// attempt.
242-
func (pl *dynamicResources) PreEnqueue(ctx context.Context, pod *v1.Pod) (status *framework.Status) {
242+
func (pl *DynamicResources) PreEnqueue(ctx context.Context, pod *v1.Pod) (status *framework.Status) {
243243
if !pl.enabled {
244244
return nil
245245
}
@@ -254,7 +254,7 @@ func (pl *dynamicResources) PreEnqueue(ctx context.Context, pod *v1.Pod) (status
254254
// an informer. It checks whether that change made a previously unschedulable
255255
// pod schedulable. It errs on the side of letting a pod scheduling attempt
256256
// happen. The delete claim event will not invoke it, so newObj will never be nil.
257-
func (pl *dynamicResources) isSchedulableAfterClaimChange(logger klog.Logger, pod *v1.Pod, oldObj, newObj interface{}) (framework.QueueingHint, error) {
257+
func (pl *DynamicResources) isSchedulableAfterClaimChange(logger klog.Logger, pod *v1.Pod, oldObj, newObj interface{}) (framework.QueueingHint, error) {
258258
originalClaim, modifiedClaim, err := schedutil.As[*resourceapi.ResourceClaim](oldObj, newObj)
259259
if err != nil {
260260
// Shouldn't happen.
@@ -318,7 +318,7 @@ func (pl *dynamicResources) isSchedulableAfterClaimChange(logger klog.Logger, po
318318
// isSchedulableAfterPodChange is invoked for update pod events reported by
319319
// an informer. It checks whether that change adds the ResourceClaim(s) that the
320320
// pod has been waiting for.
321-
func (pl *dynamicResources) isSchedulableAfterPodChange(logger klog.Logger, pod *v1.Pod, oldObj, newObj interface{}) (framework.QueueingHint, error) {
321+
func (pl *DynamicResources) isSchedulableAfterPodChange(logger klog.Logger, pod *v1.Pod, oldObj, newObj interface{}) (framework.QueueingHint, error) {
322322
_, modifiedPod, err := schedutil.As[*v1.Pod](nil, newObj)
323323
if err != nil {
324324
// Shouldn't happen.
@@ -351,7 +351,7 @@ func (pl *dynamicResources) isSchedulableAfterPodChange(logger klog.Logger, pod
351351
// attempt.
352352
//
353353
// The delete claim event will not invoke it, so newObj will never be nil.
354-
func (pl *dynamicResources) isSchedulableAfterResourceSliceChange(logger klog.Logger, pod *v1.Pod, oldObj, newObj interface{}) (framework.QueueingHint, error) {
354+
func (pl *DynamicResources) isSchedulableAfterResourceSliceChange(logger klog.Logger, pod *v1.Pod, oldObj, newObj interface{}) (framework.QueueingHint, error) {
355355
_, modifiedSlice, err := schedutil.As[*resourceapi.ResourceSlice](oldObj, newObj)
356356
if err != nil {
357357
// Shouldn't happen.
@@ -375,7 +375,7 @@ func (pl *dynamicResources) isSchedulableAfterResourceSliceChange(logger klog.Lo
375375
}
376376

377377
// podResourceClaims returns the ResourceClaims for all pod.Spec.PodResourceClaims.
378-
func (pl *dynamicResources) podResourceClaims(pod *v1.Pod) ([]*resourceapi.ResourceClaim, error) {
378+
func (pl *DynamicResources) podResourceClaims(pod *v1.Pod) ([]*resourceapi.ResourceClaim, error) {
379379
claims := make([]*resourceapi.ResourceClaim, 0, len(pod.Spec.ResourceClaims))
380380
if err := pl.foreachPodResourceClaim(pod, func(_ string, claim *resourceapi.ResourceClaim) {
381381
// We store the pointer as returned by the lister. The
@@ -391,7 +391,7 @@ func (pl *dynamicResources) podResourceClaims(pod *v1.Pod) ([]*resourceapi.Resou
391391

392392
// foreachPodResourceClaim checks that each ResourceClaim for the pod exists.
393393
// It calls an optional handler for those claims that it finds.
394-
func (pl *dynamicResources) foreachPodResourceClaim(pod *v1.Pod, cb func(podResourceName string, claim *resourceapi.ResourceClaim)) error {
394+
func (pl *DynamicResources) foreachPodResourceClaim(pod *v1.Pod, cb func(podResourceName string, claim *resourceapi.ResourceClaim)) error {
395395
for _, resource := range pod.Spec.ResourceClaims {
396396
claimName, mustCheckOwner, err := resourceclaim.Name(pod, &resource)
397397
if err != nil {
@@ -432,7 +432,7 @@ func (pl *dynamicResources) foreachPodResourceClaim(pod *v1.Pod, cb func(podReso
432432
// PreFilter invoked at the prefilter extension point to check if pod has all
433433
// immediate claims bound. UnschedulableAndUnresolvable is returned if
434434
// the pod cannot be scheduled at the moment on any node.
435-
func (pl *dynamicResources) PreFilter(ctx context.Context, state *framework.CycleState, pod *v1.Pod) (*framework.PreFilterResult, *framework.Status) {
435+
func (pl *DynamicResources) PreFilter(ctx context.Context, state *framework.CycleState, pod *v1.Pod) (*framework.PreFilterResult, *framework.Status) {
436436
if !pl.enabled {
437437
return nil, framework.NewStatus(framework.Skip)
438438
}
@@ -563,7 +563,7 @@ func (cl *claimListerForAssumeCache) ListAllAllocated() ([]*resourceapi.Resource
563563
}
564564

565565
// PreFilterExtensions returns prefilter extensions, pod add and remove.
566-
func (pl *dynamicResources) PreFilterExtensions() framework.PreFilterExtensions {
566+
func (pl *DynamicResources) PreFilterExtensions() framework.PreFilterExtensions {
567567
return nil
568568
}
569569

@@ -588,7 +588,7 @@ func getStateData(cs *framework.CycleState) (*stateData, error) {
588588
//
589589
// For claims that are unbound, it checks whether the claim might get allocated
590590
// for the node.
591-
func (pl *dynamicResources) Filter(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
591+
func (pl *DynamicResources) Filter(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
592592
if !pl.enabled {
593593
return nil
594594
}
@@ -675,7 +675,7 @@ func (pl *dynamicResources) Filter(ctx context.Context, cs *framework.CycleState
675675
// deallocated to help get the Pod schedulable. If yes, it picks one and
676676
// requests its deallocation. This only gets called when filtering found no
677677
// suitable node.
678-
func (pl *dynamicResources) PostFilter(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, filteredNodeStatusMap framework.NodeToStatusReader) (*framework.PostFilterResult, *framework.Status) {
678+
func (pl *DynamicResources) PostFilter(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, filteredNodeStatusMap framework.NodeToStatusReader) (*framework.PostFilterResult, *framework.Status) {
679679
if !pl.enabled {
680680
return nil, framework.NewStatus(framework.Unschedulable, "plugin disabled")
681681
}
@@ -708,7 +708,7 @@ func (pl *dynamicResources) PostFilter(ctx context.Context, cs *framework.CycleS
708708
}
709709

710710
// Reserve reserves claims for the pod.
711-
func (pl *dynamicResources) Reserve(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, nodeName string) (status *framework.Status) {
711+
func (pl *DynamicResources) Reserve(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, nodeName string) (status *framework.Status) {
712712
if !pl.enabled {
713713
return nil
714714
}
@@ -784,7 +784,7 @@ func (pl *dynamicResources) Reserve(ctx context.Context, cs *framework.CycleStat
784784

785785
// Unreserve clears the ReservedFor field for all claims.
786786
// It's idempotent, and does nothing if no state found for the given pod.
787-
func (pl *dynamicResources) Unreserve(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, nodeName string) {
787+
func (pl *DynamicResources) Unreserve(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, nodeName string) {
788788
if !pl.enabled {
789789
return
790790
}
@@ -832,7 +832,7 @@ func (pl *dynamicResources) Unreserve(ctx context.Context, cs *framework.CycleSt
832832
// If anything fails, we return an error and
833833
// the pod will have to go into the backoff queue. The scheduler will call
834834
// Unreserve as part of the error handling.
835-
func (pl *dynamicResources) PreBind(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, nodeName string) *framework.Status {
835+
func (pl *DynamicResources) PreBind(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, nodeName string) *framework.Status {
836836
if !pl.enabled {
837837
return nil
838838
}
@@ -863,7 +863,7 @@ func (pl *dynamicResources) PreBind(ctx context.Context, cs *framework.CycleStat
863863
// bindClaim gets called by PreBind for claim which is not reserved for the pod yet.
864864
// It might not even be allocated. bindClaim then ensures that the allocation
865865
// and reservation are recorded. This finishes the work started in Reserve.
866-
func (pl *dynamicResources) bindClaim(ctx context.Context, state *stateData, index int, pod *v1.Pod, nodeName string) (patchedClaim *resourceapi.ResourceClaim, finalErr error) {
866+
func (pl *DynamicResources) bindClaim(ctx context.Context, state *stateData, index int, pod *v1.Pod, nodeName string) (patchedClaim *resourceapi.ResourceClaim, finalErr error) {
867867
logger := klog.FromContext(ctx)
868868
claim := state.claims[index].DeepCopy()
869869
allocation := state.informationsForClaim[index].allocation

pkg/scheduler/framework/plugins/dynamicresources/dynamicresources_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ type testContext struct {
920920
client *fake.Clientset
921921
informerFactory informers.SharedInformerFactory
922922
claimAssumeCache *assumecache.AssumeCache
923-
p *dynamicResources
923+
p *DynamicResources
924924
nodeInfos []*framework.NodeInfo
925925
state *framework.CycleState
926926
}
@@ -1087,7 +1087,7 @@ func setup(t *testing.T, nodes []*v1.Node, claims []*resourceapi.ResourceClaim,
10871087
if err != nil {
10881088
t.Fatal(err)
10891089
}
1090-
tc.p = pl.(*dynamicResources)
1090+
tc.p = pl.(*DynamicResources)
10911091

10921092
// The tests use the API to create the objects because then reactors
10931093
// get triggered.

0 commit comments

Comments
 (0)