mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +00:00
Merge pull request #98364 from gavinfish/sched-error-interpod
Scheduler: wrap errors from DefaultPreemption and InterPodAffinity plugins
This commit is contained in:
commit
bfac3e9309
@ -624,7 +624,7 @@ func selectVictimsOnNode(
|
||||
if corev1helpers.PodPriority(pi.Pod) < podPriority {
|
||||
potentialVictims = append(potentialVictims, pi)
|
||||
if err := removePod(pi); err != nil {
|
||||
return nil, 0, framework.NewStatus(framework.Error, err.Error())
|
||||
return nil, 0, framework.AsStatus(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -669,7 +669,7 @@ func selectVictimsOnNode(
|
||||
}
|
||||
for _, p := range violatingVictims {
|
||||
if fits, err := reprievePod(p); err != nil {
|
||||
return nil, 0, framework.NewStatus(framework.Error, err.Error())
|
||||
return nil, 0, framework.AsStatus(err)
|
||||
} else if !fits {
|
||||
numViolatingVictim++
|
||||
}
|
||||
@ -677,7 +677,7 @@ func selectVictimsOnNode(
|
||||
// Now we try to reprieve non-violating victims.
|
||||
for _, p := range nonViolatingVictims {
|
||||
if _, err := reprievePod(p); err != nil {
|
||||
return nil, 0, framework.NewStatus(framework.Error, err.Error())
|
||||
return nil, 0, framework.AsStatus(err)
|
||||
}
|
||||
}
|
||||
return victims, numViolatingVictim, framework.NewStatus(framework.Success)
|
||||
|
@ -240,10 +240,10 @@ func (pl *InterPodAffinity) PreFilter(ctx context.Context, cycleState *framework
|
||||
var nodesWithRequiredAntiAffinityPods []*framework.NodeInfo
|
||||
var err error
|
||||
if allNodes, err = pl.sharedLister.NodeInfos().List(); err != nil {
|
||||
return framework.NewStatus(framework.Error, fmt.Sprintf("failed to list NodeInfos: %v", err))
|
||||
return framework.AsStatus(fmt.Errorf("failed to list NodeInfos: %w", err))
|
||||
}
|
||||
if nodesWithRequiredAntiAffinityPods, err = pl.sharedLister.NodeInfos().HavePodsWithRequiredAntiAffinityList(); err != nil {
|
||||
return framework.NewStatus(framework.Error, fmt.Sprintf("failed to list NodeInfos with pods with affinity: %v", err))
|
||||
return framework.AsStatus(fmt.Errorf("failed to list NodeInfos with pods with affinity: %w", err))
|
||||
}
|
||||
|
||||
podInfo := framework.NewPodInfo(pod)
|
||||
@ -278,7 +278,7 @@ func (pl *InterPodAffinity) PreFilterExtensions() framework.PreFilterExtensions
|
||||
func (pl *InterPodAffinity) AddPod(ctx context.Context, cycleState *framework.CycleState, podToSchedule *v1.Pod, podInfoToAdd *framework.PodInfo, nodeInfo *framework.NodeInfo) *framework.Status {
|
||||
state, err := getPreFilterState(cycleState)
|
||||
if err != nil {
|
||||
return framework.NewStatus(framework.Error, err.Error())
|
||||
return framework.AsStatus(err)
|
||||
}
|
||||
state.updateWithPod(podInfoToAdd, nodeInfo.Node(), 1)
|
||||
return nil
|
||||
@ -288,7 +288,7 @@ func (pl *InterPodAffinity) AddPod(ctx context.Context, cycleState *framework.Cy
|
||||
func (pl *InterPodAffinity) RemovePod(ctx context.Context, cycleState *framework.CycleState, podToSchedule *v1.Pod, podInfoToRemove *framework.PodInfo, nodeInfo *framework.NodeInfo) *framework.Status {
|
||||
state, err := getPreFilterState(cycleState)
|
||||
if err != nil {
|
||||
return framework.NewStatus(framework.Error, err.Error())
|
||||
return framework.AsStatus(err)
|
||||
}
|
||||
state.updateWithPod(podInfoToRemove, nodeInfo.Node(), -1)
|
||||
return nil
|
||||
@ -378,7 +378,7 @@ func (pl *InterPodAffinity) Filter(ctx context.Context, cycleState *framework.Cy
|
||||
|
||||
state, err := getPreFilterState(cycleState)
|
||||
if err != nil {
|
||||
return framework.NewStatus(framework.Error, err.Error())
|
||||
return framework.AsStatus(err)
|
||||
}
|
||||
|
||||
if !satisfyPodAffinity(state, nodeInfo) {
|
||||
|
@ -138,7 +138,7 @@ func (pl *InterPodAffinity) PreScore(
|
||||
}
|
||||
|
||||
if pl.sharedLister == nil {
|
||||
return framework.NewStatus(framework.Error, fmt.Sprintf("InterPodAffinity PreScore with empty shared lister found"))
|
||||
return framework.NewStatus(framework.Error, "empty shared lister in InterPodAffinity PreScore")
|
||||
}
|
||||
|
||||
affinity := pod.Spec.Affinity
|
||||
@ -152,19 +152,19 @@ func (pl *InterPodAffinity) PreScore(
|
||||
if hasPreferredAffinityConstraints || hasPreferredAntiAffinityConstraints {
|
||||
allNodes, err = pl.sharedLister.NodeInfos().List()
|
||||
if err != nil {
|
||||
framework.NewStatus(framework.Error, fmt.Sprintf("get all nodes from shared lister error, err: %v", err))
|
||||
framework.AsStatus(fmt.Errorf("failed to get all nodes from shared lister: %w", err))
|
||||
}
|
||||
} else {
|
||||
allNodes, err = pl.sharedLister.NodeInfos().HavePodsWithAffinityList()
|
||||
if err != nil {
|
||||
framework.NewStatus(framework.Error, fmt.Sprintf("get pods with affinity list error, err: %v", err))
|
||||
framework.AsStatus(fmt.Errorf("failed to get pods with affinity list: %w", err))
|
||||
}
|
||||
}
|
||||
|
||||
podInfo := framework.NewPodInfo(pod)
|
||||
if podInfo.ParseError != nil {
|
||||
// Ideally we never reach here, because errors will be caught by PreFilter
|
||||
return framework.NewStatus(framework.Error, fmt.Sprintf("parsing pod: %+v", podInfo.ParseError))
|
||||
return framework.AsStatus(fmt.Errorf("failed to parse pod: %w", podInfo.ParseError))
|
||||
}
|
||||
|
||||
state := &preScoreState{
|
||||
@ -224,14 +224,14 @@ func getPreScoreState(cycleState *framework.CycleState) (*preScoreState, error)
|
||||
// Note: the returned "score" is positive for pod-affinity, and negative for pod-antiaffinity.
|
||||
func (pl *InterPodAffinity) Score(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod, nodeName string) (int64, *framework.Status) {
|
||||
nodeInfo, err := pl.sharedLister.NodeInfos().Get(nodeName)
|
||||
if err != nil || nodeInfo.Node() == nil {
|
||||
return 0, framework.NewStatus(framework.Error, fmt.Sprintf("getting node %q from Snapshot: %v, node is nil: %v", nodeName, err, nodeInfo.Node() == nil))
|
||||
if err != nil {
|
||||
return 0, framework.AsStatus(fmt.Errorf("failed to get node %q from Snapshot: %w", nodeName, err))
|
||||
}
|
||||
node := nodeInfo.Node()
|
||||
|
||||
s, err := getPreScoreState(cycleState)
|
||||
if err != nil {
|
||||
return 0, framework.NewStatus(framework.Error, err.Error())
|
||||
return 0, framework.AsStatus(err)
|
||||
}
|
||||
var score int64
|
||||
for tpKey, tpValues := range s.topologyScore {
|
||||
@ -247,7 +247,7 @@ func (pl *InterPodAffinity) Score(ctx context.Context, cycleState *framework.Cyc
|
||||
func (pl *InterPodAffinity) NormalizeScore(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod, scores framework.NodeScoreList) *framework.Status {
|
||||
s, err := getPreScoreState(cycleState)
|
||||
if err != nil {
|
||||
return framework.NewStatus(framework.Error, err.Error())
|
||||
return framework.AsStatus(err)
|
||||
}
|
||||
if len(s.topologyScore) == 0 {
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user