Skip to content

Commit 0b91def

Browse files
authored
Merge pull request kubernetes#127872 from kerthcet/cleanup/find-cancidate
Refactor the sample logging output
2 parents 06fb818 + 693d4fa commit 0b91def

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

pkg/scheduler/framework/preemption/preemption.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,8 @@ func (ev *Evaluator) findCandidates(ctx context.Context, allNodes []*framework.N
238238
return nil, nil, err
239239
}
240240

241-
offset, numCandidates := ev.GetOffsetAndNumCandidates(int32(len(potentialNodes)))
242-
if loggerV := logger.V(5); logger.Enabled() {
243-
var sample []string
244-
for i := offset; i < offset+10 && i < int32(len(potentialNodes)); i++ {
245-
sample = append(sample, potentialNodes[i].Node().Name)
246-
}
247-
loggerV.Info("Selected candidates from a pool of nodes", "potentialNodesCount", len(potentialNodes), "offset", offset, "sampleLength", len(sample), "sample", sample, "candidates", numCandidates)
248-
}
249-
return ev.DryRunPreemption(ctx, pod, potentialNodes, pdbs, offset, numCandidates)
241+
offset, candidatesNum := ev.GetOffsetAndNumCandidates(int32(len(potentialNodes)))
242+
return ev.DryRunPreemption(ctx, pod, potentialNodes, pdbs, offset, candidatesNum)
250243
}
251244

252245
// callExtenders calls given <extenders> to select the list of feasible candidates.
@@ -546,18 +539,24 @@ func getLowerPriorityNominatedPods(logger klog.Logger, pn framework.PodNominator
546539
// candidates, ones that do not violate PDB are preferred over ones that do.
547540
// NOTE: This method is exported for easier testing in default preemption.
548541
func (ev *Evaluator) DryRunPreemption(ctx context.Context, pod *v1.Pod, potentialNodes []*framework.NodeInfo,
549-
pdbs []*policy.PodDisruptionBudget, offset int32, numCandidates int32) ([]Candidate, *framework.NodeToStatus, error) {
542+
pdbs []*policy.PodDisruptionBudget, offset int32, candidatesNum int32) ([]Candidate, *framework.NodeToStatus, error) {
550543

551544
fh := ev.Handler
552-
nonViolatingCandidates := newCandidateList(numCandidates)
553-
violatingCandidates := newCandidateList(numCandidates)
545+
nonViolatingCandidates := newCandidateList(candidatesNum)
546+
violatingCandidates := newCandidateList(candidatesNum)
554547
ctx, cancel := context.WithCancel(ctx)
555548
defer cancel()
556549
nodeStatuses := framework.NewDefaultNodeToStatus()
550+
551+
logger := klog.FromContext(ctx)
552+
logger.V(5).Info("Dry run the preemption", "potentialNodesNumber", len(potentialNodes), "pdbsNumber", len(pdbs), "offset", offset, "candidatesNumber", candidatesNum)
553+
557554
var statusesLock sync.Mutex
558555
var errs []error
559556
checkNode := func(i int) {
560557
nodeInfoCopy := potentialNodes[(int(offset)+i)%len(potentialNodes)].Snapshot()
558+
logger.V(5).Info("Check the potential node for preemption", "node", nodeInfoCopy.Node().Name)
559+
561560
stateCopy := ev.State.Clone()
562561
pods, numPDBViolations, status := ev.SelectVictimsOnNode(ctx, stateCopy, pod, nodeInfoCopy, pdbs)
563562
if status.IsSuccess() && len(pods) != 0 {
@@ -575,7 +574,7 @@ func (ev *Evaluator) DryRunPreemption(ctx context.Context, pod *v1.Pod, potentia
575574
violatingCandidates.add(c)
576575
}
577576
nvcSize, vcSize := nonViolatingCandidates.size(), violatingCandidates.size()
578-
if nvcSize > 0 && nvcSize+vcSize >= numCandidates {
577+
if nvcSize > 0 && nvcSize+vcSize >= candidatesNum {
579578
cancel()
580579
}
581580
return

0 commit comments

Comments
 (0)