-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(platform): sort workload pods for page (#2224)
Co-authored-by: xdonggao <xdonggao@tencent.com>
- Loading branch information
1 parent
5b97a0d
commit 453512d
Showing
6 changed files
with
80 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package util | ||
|
||
import corev1 "k8s.io/api/core/v1" | ||
|
||
type Pods struct { | ||
pods []corev1.Pod | ||
} | ||
|
||
func NewPods(pods []corev1.Pod) Pods { | ||
return Pods{ | ||
pods: pods, | ||
} | ||
} | ||
|
||
func (p Pods) Len() int { | ||
return len(p.pods) | ||
} | ||
|
||
func (p Pods) Swap(i, j int) { | ||
p.pods[i], p.pods[j] = p.pods[j], p.pods[i] | ||
} | ||
|
||
func (p Pods) Less(i, j int) bool { | ||
// created at the same time, sort by the first letter of the pod name | ||
if p.pods[i].CreationTimestamp.Time == p.pods[j].CreationTimestamp.Time { | ||
return p.pods[i].Name > p.pods[j].Name | ||
} | ||
// the earliest created time comes first | ||
return p.pods[j].CreationTimestamp.After(p.pods[i].CreationTimestamp.Time) | ||
} | ||
|
||
func (p Pods) GetPods() []corev1.Pod { | ||
return p.pods | ||
} |