Remove scheduler plugins package's dependency from core package
This commit is contained in:
@@ -30,6 +30,7 @@ import (
|
||||
"k8s.io/client-go/informers"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/tools/events"
|
||||
"k8s.io/component-helpers/scheduling/corev1"
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/kube-scheduler/config/v1beta1"
|
||||
"k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||
@@ -594,6 +595,90 @@ func (f *frameworkImpl) runPostFilterPlugin(ctx context.Context, pl framework.Po
|
||||
return r, s
|
||||
}
|
||||
|
||||
// RunFilterPluginsWithNominatedPods runs the set of configured filter plugins
|
||||
// for nominated pod on the given node.
|
||||
// This function is called from two different places: Schedule and Preempt.
|
||||
// When it is called from Schedule, we want to test whether the pod is
|
||||
// schedulable on the node with all the existing pods on the node plus higher
|
||||
// and equal priority pods nominated to run on the node.
|
||||
// When it is called from Preempt, we should remove the victims of preemption
|
||||
// and add the nominated pods. Removal of the victims is done by
|
||||
// SelectVictimsOnNode(). Preempt removes victims from PreFilter state and
|
||||
// NodeInfo before calling this function.
|
||||
func (f *frameworkImpl) RunFilterPluginsWithNominatedPods(ctx context.Context, state *framework.CycleState, pod *v1.Pod, info *framework.NodeInfo) *framework.Status {
|
||||
var status *framework.Status
|
||||
|
||||
ph := f.PreemptHandle()
|
||||
podsAdded := false
|
||||
// We run filters twice in some cases. If the node has greater or equal priority
|
||||
// nominated pods, we run them when those pods are added to PreFilter state and nodeInfo.
|
||||
// If all filters succeed in this pass, we run them again when these
|
||||
// nominated pods are not added. This second pass is necessary because some
|
||||
// filters such as inter-pod affinity may not pass without the nominated pods.
|
||||
// If there are no nominated pods for the node or if the first run of the
|
||||
// filters fail, we don't run the second pass.
|
||||
// We consider only equal or higher priority pods in the first pass, because
|
||||
// those are the current "pod" must yield to them and not take a space opened
|
||||
// for running them. It is ok if the current "pod" take resources freed for
|
||||
// lower priority pods.
|
||||
// Requiring that the new pod is schedulable in both circumstances ensures that
|
||||
// we are making a conservative decision: filters like resources and inter-pod
|
||||
// anti-affinity are more likely to fail when the nominated pods are treated
|
||||
// as running, while filters like pod affinity are more likely to fail when
|
||||
// the nominated pods are treated as not running. We can't just assume the
|
||||
// nominated pods are running because they are not running right now and in fact,
|
||||
// they may end up getting scheduled to a different node.
|
||||
for i := 0; i < 2; i++ {
|
||||
stateToUse := state
|
||||
nodeInfoToUse := info
|
||||
if i == 0 {
|
||||
var err error
|
||||
podsAdded, stateToUse, nodeInfoToUse, err = addNominatedPods(ctx, ph, pod, state, info)
|
||||
if err != nil {
|
||||
return framework.NewStatus(framework.Error, err.Error())
|
||||
}
|
||||
} else if !podsAdded || !status.IsSuccess() {
|
||||
break
|
||||
}
|
||||
|
||||
statusMap := ph.RunFilterPlugins(ctx, stateToUse, pod, nodeInfoToUse)
|
||||
status = statusMap.Merge()
|
||||
if !status.IsSuccess() && !status.IsUnschedulable() {
|
||||
return status
|
||||
}
|
||||
}
|
||||
|
||||
return status
|
||||
}
|
||||
|
||||
// addNominatedPods adds pods with equal or greater priority which are nominated
|
||||
// to run on the node. It returns 1) whether any pod was added, 2) augmented cycleState,
|
||||
// 3) augmented nodeInfo.
|
||||
func addNominatedPods(ctx context.Context, ph framework.PreemptHandle, pod *v1.Pod, state *framework.CycleState, nodeInfo *framework.NodeInfo) (bool, *framework.CycleState, *framework.NodeInfo, error) {
|
||||
if ph == nil || nodeInfo.Node() == nil {
|
||||
// This may happen only in tests.
|
||||
return false, state, nodeInfo, nil
|
||||
}
|
||||
nominatedPods := ph.NominatedPodsForNode(nodeInfo.Node().Name)
|
||||
if len(nominatedPods) == 0 {
|
||||
return false, state, nodeInfo, nil
|
||||
}
|
||||
nodeInfoOut := nodeInfo.Clone()
|
||||
stateOut := state.Clone()
|
||||
podsAdded := false
|
||||
for _, p := range nominatedPods {
|
||||
if corev1.PodPriority(p) >= corev1.PodPriority(pod) && p.UID != pod.UID {
|
||||
nodeInfoOut.AddPod(p)
|
||||
status := ph.RunPreFilterExtensionAddPod(ctx, stateOut, pod, p, nodeInfoOut)
|
||||
if !status.IsSuccess() {
|
||||
return false, state, nodeInfo, status.AsError()
|
||||
}
|
||||
podsAdded = true
|
||||
}
|
||||
}
|
||||
return podsAdded, stateOut, nodeInfoOut, nil
|
||||
}
|
||||
|
||||
// RunPreScorePlugins runs the set of configured pre-score plugins. If any
|
||||
// of these plugins returns any status other than "Success", the given pod is rejected.
|
||||
func (f *frameworkImpl) RunPreScorePlugins(
|
||||
|
||||
Reference in New Issue
Block a user