Skip to content

Commit 06d3cd3

Browse files
committed
use slices library instead
1 parent 38c2a96 commit 06d3cd3

File tree

1 file changed

+3
-30
lines changed

1 file changed

+3
-30
lines changed

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

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ func (pl *dynamicResources) isSchedulableAfterPodSchedulingContextChange(logger
731731
// before moving DRA to beta.
732732
if podScheduling.Spec.SelectedNode != "" {
733733
for _, claimStatus := range podScheduling.Status.ResourceClaims {
734-
if sliceContains(claimStatus.UnsuitableNodes, podScheduling.Spec.SelectedNode) {
734+
if slices.Contains(claimStatus.UnsuitableNodes, podScheduling.Spec.SelectedNode) {
735735
logger.V(5).Info("PodSchedulingContext has unsuitable selected node, schedule immediately", "pod", klog.KObj(pod), "selectedNode", podScheduling.Spec.SelectedNode, "podResourceName", claimStatus.Name)
736736
return framework.Queue, nil
737737
}
@@ -769,15 +769,6 @@ func podSchedulingHasClaimInfo(podScheduling *resourcev1alpha2.PodSchedulingCont
769769
return false
770770
}
771771

772-
func sliceContains(hay []string, needle string) bool {
773-
for _, item := range hay {
774-
if item == needle {
775-
return true
776-
}
777-
}
778-
return false
779-
}
780-
781772
// podResourceClaims returns the ResourceClaims for all pod.Spec.PodResourceClaims.
782773
func (pl *dynamicResources) podResourceClaims(pod *v1.Pod) ([]*resourcev1alpha2.ResourceClaim, error) {
783774
claims := make([]*resourcev1alpha2.ResourceClaim, 0, len(pod.Spec.ResourceClaims))
@@ -1330,22 +1321,13 @@ func haveAllPotentialNodes(schedulingCtx *resourcev1alpha2.PodSchedulingContext,
13301321
return false
13311322
}
13321323
for _, node := range nodes {
1333-
if !haveNode(schedulingCtx.Spec.PotentialNodes, node.Node().Name) {
1324+
if !slices.Contains(schedulingCtx.Spec.PotentialNodes, node.Node().Name) {
13341325
return false
13351326
}
13361327
}
13371328
return true
13381329
}
13391330

1340-
func haveNode(nodeNames []string, nodeName string) bool {
1341-
for _, n := range nodeNames {
1342-
if n == nodeName {
1343-
return true
1344-
}
1345-
}
1346-
return false
1347-
}
1348-
13491331
// Reserve reserves claims for the pod.
13501332
func (pl *dynamicResources) Reserve(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, nodeName string) (status *framework.Status) {
13511333
if !pl.enabled {
@@ -1402,7 +1384,7 @@ func (pl *dynamicResources) Reserve(ctx context.Context, cs *framework.CycleStat
14021384
// scheduler will pick it forever even when it cannot satisfy
14031385
// the claim.
14041386
if state.podSchedulingState.schedulingCtx == nil ||
1405-
!containsNode(state.podSchedulingState.schedulingCtx.Spec.PotentialNodes, nodeName) {
1387+
!slices.Contains(state.podSchedulingState.schedulingCtx.Spec.PotentialNodes, nodeName) {
14061388
potentialNodes := []string{nodeName}
14071389
state.podSchedulingState.potentialNodes = &potentialNodes
14081390
logger.V(5).Info("asking for information about single potential node", "pod", klog.KObj(pod), "node", klog.ObjectRef{Name: nodeName})
@@ -1478,15 +1460,6 @@ func (pl *dynamicResources) Reserve(ctx context.Context, cs *framework.CycleStat
14781460
return statusPending(logger, "waiting for resource driver to provide information", "pod", klog.KObj(pod))
14791461
}
14801462

1481-
func containsNode(hay []string, needle string) bool {
1482-
for _, node := range hay {
1483-
if node == needle {
1484-
return true
1485-
}
1486-
}
1487-
return false
1488-
}
1489-
14901463
// Unreserve clears the ReservedFor field for all claims.
14911464
// It's idempotent, and does nothing if no state found for the given pod.
14921465
func (pl *dynamicResources) Unreserve(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, nodeName string) {

0 commit comments

Comments
 (0)