forked from volcano-sh/volcano
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request volcano-sh#34 from lminzhw/scheduler_detailed_event
support scheduler detailed event
- Loading branch information
Showing
11 changed files
with
202 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package api | ||
|
||
import ( | ||
"fmt" | ||
"sort" | ||
"strings" | ||
|
||
"k8s.io/kubernetes/pkg/scheduler/algorithm" | ||
) | ||
|
||
const ( | ||
// NodePodNumberExceeded means pods in node exceed the allocatable pod number | ||
NodePodNumberExceeded = "node(s) pod number exceeded" | ||
// NodeResourceFitFailed means node could not fit the request of pod | ||
NodeResourceFitFailed = "node(s) resource fit failed" | ||
|
||
// AllNodeUnavailableMsg is the default error message | ||
AllNodeUnavailableMsg = "all nodes are unavailable" | ||
) | ||
|
||
// FitErrors is set of FitError on many nodes | ||
type FitErrors struct { | ||
nodes map[string]*FitError | ||
err string | ||
} | ||
|
||
// NewFitErrors returns an FitErrors | ||
func NewFitErrors() *FitErrors { | ||
f := new(FitErrors) | ||
f.nodes = make(map[string]*FitError) | ||
return f | ||
} | ||
|
||
// SetError set the common error message in FitErrors | ||
func (f *FitErrors) SetError(err string) { | ||
f.err = err | ||
} | ||
|
||
// SetNodeError set the node error in FitErrors | ||
func (f *FitErrors) SetNodeError(nodeName string, err error) { | ||
var fe *FitError | ||
switch obj := err.(type) { | ||
case *FitError: | ||
obj.NodeName = nodeName | ||
fe = obj | ||
default: | ||
fe = &FitError{ | ||
NodeName: nodeName, | ||
Reasons: []string{obj.Error()}, | ||
} | ||
} | ||
|
||
f.nodes[nodeName] = fe | ||
} | ||
|
||
// Error returns the final error message | ||
func (f *FitErrors) Error() string { | ||
reasons := make(map[string]int) | ||
|
||
for _, node := range f.nodes { | ||
for _, reason := range node.Reasons { | ||
reasons[reason]++ | ||
} | ||
} | ||
|
||
sortReasonsHistogram := func() []string { | ||
reasonStrings := []string{} | ||
for k, v := range reasons { | ||
reasonStrings = append(reasonStrings, fmt.Sprintf("%v %v", v, k)) | ||
} | ||
sort.Strings(reasonStrings) | ||
return reasonStrings | ||
} | ||
if f.err == "" { | ||
f.err = AllNodeUnavailableMsg | ||
} | ||
reasonMsg := fmt.Sprintf(f.err+": %v.", strings.Join(sortReasonsHistogram(), ", ")) | ||
return reasonMsg | ||
} | ||
|
||
// FitError describe the reason why task could not fit that node | ||
type FitError struct { | ||
taskNamespace string | ||
taskName string | ||
NodeName string | ||
Reasons []string | ||
} | ||
|
||
// NewFitError return FitError by message | ||
func NewFitError(task *TaskInfo, node *NodeInfo, message ...string) *FitError { | ||
fe := &FitError{ | ||
taskName: task.Name, | ||
taskNamespace: task.Namespace, | ||
NodeName: node.Name, | ||
Reasons: message, | ||
} | ||
return fe | ||
} | ||
|
||
// NewFitErrorByReasons return FitError by reasons | ||
func NewFitErrorByReasons(task *TaskInfo, node *NodeInfo, reasons ...algorithm.PredicateFailureReason) *FitError { | ||
message := make([]string, 0, len(reasons)) | ||
for _, reason := range reasons { | ||
message = append(message, reason.GetReason()) | ||
} | ||
return NewFitError(task, node, message...) | ||
} | ||
|
||
// Error returns the final error message | ||
func (f *FitError) Error() string { | ||
return fmt.Sprintf("task %s/%s on node %s fit failed: %s", f.taskNamespace, f.taskName, f.NodeName, strings.Join(f.Reasons, ", ")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.