mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Merge pull request #97794 from chendave/cleanup_status
Refactor: rewrite `Merge` method to address readability and efficiency
This commit is contained in:
commit
faaae71427
@ -77,6 +77,15 @@ const (
|
|||||||
// This list should be exactly the same as the codes iota defined above in the same order.
|
// This list should be exactly the same as the codes iota defined above in the same order.
|
||||||
var codes = []string{"Success", "Error", "Unschedulable", "UnschedulableAndUnresolvable", "Wait", "Skip"}
|
var codes = []string{"Success", "Error", "Unschedulable", "UnschedulableAndUnresolvable", "Wait", "Skip"}
|
||||||
|
|
||||||
|
// statusPrecedence defines a map from status to its precedence, larger value means higher precedent.
|
||||||
|
var statusPrecedence = map[Code]int{
|
||||||
|
Error: 3,
|
||||||
|
UnschedulableAndUnresolvable: 2,
|
||||||
|
Unschedulable: 1,
|
||||||
|
// Any other statuses we know today, `Skip` or `Wait`, will take precedence over `Success`.
|
||||||
|
Success: -1,
|
||||||
|
}
|
||||||
|
|
||||||
func (c Code) String() string {
|
func (c Code) String() string {
|
||||||
return codes[c]
|
return codes[c]
|
||||||
}
|
}
|
||||||
@ -184,28 +193,19 @@ func (p PluginToStatus) Merge() *Status {
|
|||||||
}
|
}
|
||||||
|
|
||||||
finalStatus := NewStatus(Success)
|
finalStatus := NewStatus(Success)
|
||||||
var hasUnschedulableAndUnresolvable, hasUnschedulable bool
|
|
||||||
for _, s := range p {
|
for _, s := range p {
|
||||||
if s.Code() == Error {
|
if s.Code() == Error {
|
||||||
finalStatus.err = s.AsError()
|
finalStatus.err = s.AsError()
|
||||||
} else if s.Code() == UnschedulableAndUnresolvable {
|
|
||||||
hasUnschedulableAndUnresolvable = true
|
|
||||||
} else if s.Code() == Unschedulable {
|
|
||||||
hasUnschedulable = true
|
|
||||||
}
|
}
|
||||||
finalStatus.code = s.Code()
|
if statusPrecedence[s.Code()] > statusPrecedence[finalStatus.code] {
|
||||||
|
finalStatus.code = s.Code()
|
||||||
|
}
|
||||||
|
|
||||||
for _, r := range s.reasons {
|
for _, r := range s.reasons {
|
||||||
finalStatus.AppendReason(r)
|
finalStatus.AppendReason(r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if finalStatus.err != nil {
|
|
||||||
finalStatus.code = Error
|
|
||||||
} else if hasUnschedulableAndUnresolvable {
|
|
||||||
finalStatus.code = UnschedulableAndUnresolvable
|
|
||||||
} else if hasUnschedulable {
|
|
||||||
finalStatus.code = Unschedulable
|
|
||||||
}
|
|
||||||
return finalStatus
|
return finalStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user