Merge pull request #98340 from gavinfish/sched-preempt-pi

Scheduler: update potentialVictims as framework.PodInfo type
This commit is contained in:
Kubernetes Prow Robot 2021-01-24 08:50:53 -08:00 committed by GitHub
commit 6a1087ed40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 27 deletions

View File

@ -597,22 +597,21 @@ func selectVictimsOnNode(
nodeInfo *framework.NodeInfo, nodeInfo *framework.NodeInfo,
pdbs []*policy.PodDisruptionBudget, pdbs []*policy.PodDisruptionBudget,
) ([]*v1.Pod, int, *framework.Status) { ) ([]*v1.Pod, int, *framework.Status) {
var potentialVictims []*v1.Pod var potentialVictims []*framework.PodInfo
ph := fh.PreemptHandle() ph := fh.PreemptHandle()
removePod := func(rp *v1.Pod) error { removePod := func(rpi *framework.PodInfo) error {
if err := nodeInfo.RemovePod(rp); err != nil { if err := nodeInfo.RemovePod(rpi.Pod); err != nil {
return err return err
} }
status := ph.RunPreFilterExtensionRemovePod(ctx, state, pod, framework.NewPodInfo(rp), nodeInfo) status := ph.RunPreFilterExtensionRemovePod(ctx, state, pod, rpi, nodeInfo)
if !status.IsSuccess() { if !status.IsSuccess() {
return status.AsError() return status.AsError()
} }
return nil return nil
} }
addPod := func(ap *v1.Pod) error { addPod := func(api *framework.PodInfo) error {
podInfoToAdd := framework.NewPodInfo(ap) nodeInfo.AddPodInfo(api)
nodeInfo.AddPodInfo(podInfoToAdd) status := ph.RunPreFilterExtensionAddPod(ctx, state, pod, api, nodeInfo)
status := ph.RunPreFilterExtensionAddPod(ctx, state, pod, podInfoToAdd, nodeInfo)
if !status.IsSuccess() { if !status.IsSuccess() {
return status.AsError() return status.AsError()
} }
@ -621,10 +620,10 @@ func selectVictimsOnNode(
// As the first step, remove all the lower priority pods from the node and // As the first step, remove all the lower priority pods from the node and
// check if the given pod can be scheduled. // check if the given pod can be scheduled.
podPriority := corev1helpers.PodPriority(pod) podPriority := corev1helpers.PodPriority(pod)
for _, p := range nodeInfo.Pods { for _, pi := range nodeInfo.Pods {
if corev1helpers.PodPriority(p.Pod) < podPriority { if corev1helpers.PodPriority(pi.Pod) < podPriority {
potentialVictims = append(potentialVictims, p.Pod) potentialVictims = append(potentialVictims, pi)
if err := removePod(p.Pod); err != nil { if err := removePod(pi); err != nil {
return nil, 0, framework.NewStatus(framework.Error, err.Error()) return nil, 0, framework.NewStatus(framework.Error, err.Error())
} }
} }
@ -647,23 +646,24 @@ func selectVictimsOnNode(
} }
var victims []*v1.Pod var victims []*v1.Pod
numViolatingVictim := 0 numViolatingVictim := 0
sort.Slice(potentialVictims, func(i, j int) bool { return util.MoreImportantPod(potentialVictims[i], potentialVictims[j]) }) sort.Slice(potentialVictims, func(i, j int) bool { return util.MoreImportantPod(potentialVictims[i].Pod, potentialVictims[j].Pod) })
// Try to reprieve as many pods as possible. We first try to reprieve the PDB // Try to reprieve as many pods as possible. We first try to reprieve the PDB
// violating victims and then other non-violating ones. In both cases, we start // violating victims and then other non-violating ones. In both cases, we start
// from the highest priority victims. // from the highest priority victims.
violatingVictims, nonViolatingVictims := filterPodsWithPDBViolation(potentialVictims, pdbs) violatingVictims, nonViolatingVictims := filterPodsWithPDBViolation(potentialVictims, pdbs)
reprievePod := func(p *v1.Pod) (bool, error) { reprievePod := func(pi *framework.PodInfo) (bool, error) {
if err := addPod(p); err != nil { if err := addPod(pi); err != nil {
return false, err return false, err
} }
status := fh.RunFilterPluginsWithNominatedPods(ctx, state, pod, nodeInfo) status := fh.RunFilterPluginsWithNominatedPods(ctx, state, pod, nodeInfo)
fits := status.IsSuccess() fits := status.IsSuccess()
if !fits { if !fits {
if err := removePod(p); err != nil { if err := removePod(pi); err != nil {
return false, err return false, err
} }
victims = append(victims, p) rpi := pi.Pod
klog.V(5).Infof("Pod %v/%v is a potential preemption victim on node %v.", p.Namespace, p.Name, nodeInfo.Node().Name) victims = append(victims, rpi)
klog.V(5).Infof("Pod %v/%v is a potential preemption victim on node %v.", rpi.Namespace, rpi.Name, nodeInfo.Node().Name)
} }
return fits, nil return fits, nil
} }
@ -744,14 +744,14 @@ func getLowerPriorityNominatedPods(pn framework.PodNominator, pod *v1.Pod, nodeN
// preempted. // preempted.
// This function is stable and does not change the order of received pods. So, if it // This function is stable and does not change the order of received pods. So, if it
// receives a sorted list, grouping will preserve the order of the input list. // receives a sorted list, grouping will preserve the order of the input list.
func filterPodsWithPDBViolation(pods []*v1.Pod, pdbs []*policy.PodDisruptionBudget) (violatingPods, nonViolatingPods []*v1.Pod) { func filterPodsWithPDBViolation(podInfos []*framework.PodInfo, pdbs []*policy.PodDisruptionBudget) (violatingPodInfos, nonViolatingPodInfos []*framework.PodInfo) {
pdbsAllowed := make([]int32, len(pdbs)) pdbsAllowed := make([]int32, len(pdbs))
for i, pdb := range pdbs { for i, pdb := range pdbs {
pdbsAllowed[i] = pdb.Status.DisruptionsAllowed pdbsAllowed[i] = pdb.Status.DisruptionsAllowed
} }
for _, obj := range pods { for _, podInfo := range podInfos {
pod := obj pod := podInfo.Pod
pdbForPodIsViolated := false pdbForPodIsViolated := false
// A pod with no labels will not match any PDB. So, no need to check. // A pod with no labels will not match any PDB. So, no need to check.
if len(pod.Labels) != 0 { if len(pod.Labels) != 0 {
@ -783,12 +783,12 @@ func filterPodsWithPDBViolation(pods []*v1.Pod, pdbs []*policy.PodDisruptionBudg
} }
} }
if pdbForPodIsViolated { if pdbForPodIsViolated {
violatingPods = append(violatingPods, pod) violatingPodInfos = append(violatingPodInfos, podInfo)
} else { } else {
nonViolatingPods = append(nonViolatingPods, pod) nonViolatingPodInfos = append(nonViolatingPodInfos, podInfo)
} }
} }
return violatingPods, nonViolatingPods return violatingPodInfos, nonViolatingPodInfos
} }
func getPDBLister(informerFactory informers.SharedInformerFactory) policylisters.PodDisruptionBudgetLister { func getPDBLister(informerFactory informers.SharedInformerFactory) policylisters.PodDisruptionBudgetLister {

View File

@ -1016,9 +1016,6 @@ func TestDryRunPreemption(t *testing.T) {
} }
offset, numCandidates := pl.getOffsetAndNumCandidates(int32(len(nodeInfos))) offset, numCandidates := pl.getOffsetAndNumCandidates(int32(len(nodeInfos)))
got, _ := dryRunPreemption(context.Background(), fwk, state, pod, nodeInfos, tt.pdbs, offset, numCandidates) got, _ := dryRunPreemption(context.Background(), fwk, state, pod, nodeInfos, tt.pdbs, offset, numCandidates)
if err != nil {
t.Fatal(err)
}
// Sort the values (inner victims) and the candidate itself (by its NominatedNodeName). // Sort the values (inner victims) and the candidate itself (by its NominatedNodeName).
for i := range got { for i := range got {
victims := got[i].Victims().Pods victims := got[i].Victims().Pods