Avoid panic in cronjob sorting
This change handles the case where the ith cronjob may have its start time set to nil. Previously, the Less method could cause a panic in case the ith cronjob had its start time set to nil, but the jth cronjob did not. It would panic when calling Before on a nil StartTime.
This commit is contained in:
@@ -196,13 +196,14 @@ func (o byJobStartTime) Len() int { return len(o) }
|
||||
func (o byJobStartTime) Swap(i, j int) { o[i], o[j] = o[j], o[i] }
|
||||
|
||||
func (o byJobStartTime) Less(i, j int) bool {
|
||||
if o[j].Status.StartTime == nil {
|
||||
return o[i].Status.StartTime != nil
|
||||
if o[i].Status.StartTime == nil && o[j].Status.StartTime != nil {
|
||||
return false
|
||||
}
|
||||
if o[i].Status.StartTime != nil && o[j].Status.StartTime == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
if o[i].Status.StartTime.Equal(o[j].Status.StartTime) {
|
||||
return o[i].Name < o[j].Name
|
||||
}
|
||||
|
||||
return o[i].Status.StartTime.Before(o[j].Status.StartTime)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user