Skip to content

Commit f7003c7

Browse files
committed
Refactor the dynamicResources struct to DynamicResources
1 parent 685b8b3 commit f7003c7

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
enableSchedulingQueueHint bool
107107

@@ -170,10 +170,10 @@ type dynamicResources struct {
170170
func New(ctx context.Context, plArgs runtime.Object, fh framework.Handle, fts feature.Features) (framework.Plugin, error) {
171171
if !fts.EnableDynamicResourceAllocation {
172172
// Disabled, won't do anything.
173-
return &dynamicResources{}, nil
173+
return &DynamicResources{}, nil
174174
}
175175

176-
pl := &dynamicResources{
176+
pl := &DynamicResources{
177177
enabled: true,
178178
enableSchedulingQueueHint: fts.EnableSchedulingQueueHint,
179179

@@ -187,22 +187,22 @@ func New(ctx context.Context, plArgs runtime.Object, fh framework.Handle, fts fe
187187
return pl, nil
188188
}
189189

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

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

203203
// EventsToRegister returns the possible events that may make a Pod
204204
// failed by this plugin schedulable.
205-
func (pl *dynamicResources) EventsToRegister(_ context.Context) ([]framework.ClusterEventWithHint, error) {
205+
func (pl *DynamicResources) EventsToRegister(_ context.Context) ([]framework.ClusterEventWithHint, error) {
206206
if !pl.enabled {
207207
return nil, nil
208208
}
@@ -237,7 +237,7 @@ func (pl *dynamicResources) EventsToRegister(_ context.Context) ([]framework.Clu
237237
// PreEnqueue checks if there are known reasons why a pod currently cannot be
238238
// scheduled. When this fails, one of the registered events can trigger another
239239
// attempt.
240-
func (pl *dynamicResources) PreEnqueue(ctx context.Context, pod *v1.Pod) (status *framework.Status) {
240+
func (pl *DynamicResources) PreEnqueue(ctx context.Context, pod *v1.Pod) (status *framework.Status) {
241241
if !pl.enabled {
242242
return nil
243243
}
@@ -252,7 +252,7 @@ func (pl *dynamicResources) PreEnqueue(ctx context.Context, pod *v1.Pod) (status
252252
// an informer. It checks whether that change made a previously unschedulable
253253
// pod schedulable. It errs on the side of letting a pod scheduling attempt
254254
// happen. The delete claim event will not invoke it, so newObj will never be nil.
255-
func (pl *dynamicResources) isSchedulableAfterClaimChange(logger klog.Logger, pod *v1.Pod, oldObj, newObj interface{}) (framework.QueueingHint, error) {
255+
func (pl *DynamicResources) isSchedulableAfterClaimChange(logger klog.Logger, pod *v1.Pod, oldObj, newObj interface{}) (framework.QueueingHint, error) {
256256
originalClaim, modifiedClaim, err := schedutil.As[*resourceapi.ResourceClaim](oldObj, newObj)
257257
if err != nil {
258258
// Shouldn't happen.
@@ -316,7 +316,7 @@ func (pl *dynamicResources) isSchedulableAfterClaimChange(logger klog.Logger, po
316316
// isSchedulableAfterPodChange is invoked for update pod events reported by
317317
// an informer. It checks whether that change adds the ResourceClaim(s) that the
318318
// pod has been waiting for.
319-
func (pl *dynamicResources) isSchedulableAfterPodChange(logger klog.Logger, pod *v1.Pod, oldObj, newObj interface{}) (framework.QueueingHint, error) {
319+
func (pl *DynamicResources) isSchedulableAfterPodChange(logger klog.Logger, pod *v1.Pod, oldObj, newObj interface{}) (framework.QueueingHint, error) {
320320
_, modifiedPod, err := schedutil.As[*v1.Pod](nil, newObj)
321321
if err != nil {
322322
// Shouldn't happen.
@@ -349,7 +349,7 @@ func (pl *dynamicResources) isSchedulableAfterPodChange(logger klog.Logger, pod
349349
// attempt.
350350
//
351351
// The delete claim event will not invoke it, so newObj will never be nil.
352-
func (pl *dynamicResources) isSchedulableAfterResourceSliceChange(logger klog.Logger, pod *v1.Pod, oldObj, newObj interface{}) (framework.QueueingHint, error) {
352+
func (pl *DynamicResources) isSchedulableAfterResourceSliceChange(logger klog.Logger, pod *v1.Pod, oldObj, newObj interface{}) (framework.QueueingHint, error) {
353353
_, modifiedSlice, err := schedutil.As[*resourceapi.ResourceSlice](oldObj, newObj)
354354
if err != nil {
355355
// Shouldn't happen.
@@ -373,7 +373,7 @@ func (pl *dynamicResources) isSchedulableAfterResourceSliceChange(logger klog.Lo
373373
}
374374

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

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

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

@@ -586,7 +586,7 @@ func getStateData(cs *framework.CycleState) (*stateData, error) {
586586
//
587587
// For claims that are unbound, it checks whether the claim might get allocated
588588
// for the node.
589-
func (pl *dynamicResources) Filter(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
589+
func (pl *DynamicResources) Filter(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
590590
if !pl.enabled {
591591
return nil
592592
}
@@ -673,7 +673,7 @@ func (pl *dynamicResources) Filter(ctx context.Context, cs *framework.CycleState
673673
// deallocated to help get the Pod schedulable. If yes, it picks one and
674674
// requests its deallocation. This only gets called when filtering found no
675675
// suitable node.
676-
func (pl *dynamicResources) PostFilter(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, filteredNodeStatusMap framework.NodeToStatusReader) (*framework.PostFilterResult, *framework.Status) {
676+
func (pl *DynamicResources) PostFilter(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, filteredNodeStatusMap framework.NodeToStatusReader) (*framework.PostFilterResult, *framework.Status) {
677677
if !pl.enabled {
678678
return nil, framework.NewStatus(framework.Unschedulable, "plugin disabled")
679679
}
@@ -706,7 +706,7 @@ func (pl *dynamicResources) PostFilter(ctx context.Context, cs *framework.CycleS
706706
}
707707

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

783783
// Unreserve clears the ReservedFor field for all claims.
784784
// It's idempotent, and does nothing if no state found for the given pod.
785-
func (pl *dynamicResources) Unreserve(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, nodeName string) {
785+
func (pl *DynamicResources) Unreserve(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, nodeName string) {
786786
if !pl.enabled {
787787
return
788788
}
@@ -830,7 +830,7 @@ func (pl *dynamicResources) Unreserve(ctx context.Context, cs *framework.CycleSt
830830
// If anything fails, we return an error and
831831
// the pod will have to go into the backoff queue. The scheduler will call
832832
// Unreserve as part of the error handling.
833-
func (pl *dynamicResources) PreBind(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, nodeName string) *framework.Status {
833+
func (pl *DynamicResources) PreBind(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, nodeName string) *framework.Status {
834834
if !pl.enabled {
835835
return nil
836836
}
@@ -861,7 +861,7 @@ func (pl *dynamicResources) PreBind(ctx context.Context, cs *framework.CycleStat
861861
// bindClaim gets called by PreBind for claim which is not reserved for the pod yet.
862862
// It might not even be allocated. bindClaim then ensures that the allocation
863863
// and reservation are recorded. This finishes the work started in Reserve.
864-
func (pl *dynamicResources) bindClaim(ctx context.Context, state *stateData, index int, pod *v1.Pod, nodeName string) (patchedClaim *resourceapi.ResourceClaim, finalErr error) {
864+
func (pl *DynamicResources) bindClaim(ctx context.Context, state *stateData, index int, pod *v1.Pod, nodeName string) (patchedClaim *resourceapi.ResourceClaim, finalErr error) {
865865
logger := klog.FromContext(ctx)
866866
claim := state.claims[index].DeepCopy()
867867
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
@@ -847,7 +847,7 @@ type testContext struct {
847847
client *fake.Clientset
848848
informerFactory informers.SharedInformerFactory
849849
claimAssumeCache *assumecache.AssumeCache
850-
p *dynamicResources
850+
p *DynamicResources
851851
nodeInfos []*framework.NodeInfo
852852
state *framework.CycleState
853853
}
@@ -1014,7 +1014,7 @@ func setup(t *testing.T, nodes []*v1.Node, claims []*resourceapi.ResourceClaim,
10141014
if err != nil {
10151015
t.Fatal(err)
10161016
}
1017-
tc.p = pl.(*dynamicResources)
1017+
tc.p = pl.(*DynamicResources)
10181018

10191019
// The tests use the API to create the objects because then reactors
10201020
// get triggered.

0 commit comments

Comments
 (0)