fix: sort deployment by last update time
Signed-off-by: hongming <talonwan@yunify.com>
This commit is contained in:
@@ -24,6 +24,7 @@ import (
|
||||
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
|
||||
@@ -108,10 +109,12 @@ func (*deploymentSearcher) fuzzy(fuzzy map[string]string, item *v1.Deployment) b
|
||||
return true
|
||||
}
|
||||
|
||||
func (*deploymentSearcher) compare(a, b *v1.Deployment, orderBy string) bool {
|
||||
func (s *deploymentSearcher) compare(a, b *v1.Deployment, orderBy string) bool {
|
||||
switch orderBy {
|
||||
case CreateTime:
|
||||
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
|
||||
case UpdateTime:
|
||||
return s.lastUpdateTime(a).Before(s.lastUpdateTime(b))
|
||||
case Name:
|
||||
fallthrough
|
||||
default:
|
||||
@@ -119,6 +122,16 @@ func (*deploymentSearcher) compare(a, b *v1.Deployment, orderBy string) bool {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *deploymentSearcher) lastUpdateTime(deployment *v1.Deployment) time.Time {
|
||||
lastUpdateTime := deployment.CreationTimestamp.Time
|
||||
for _, condition := range deployment.Status.Conditions {
|
||||
if condition.LastUpdateTime.After(lastUpdateTime) {
|
||||
lastUpdateTime = condition.LastUpdateTime.Time
|
||||
}
|
||||
}
|
||||
return lastUpdateTime
|
||||
}
|
||||
|
||||
func (s *deploymentSearcher) search(namespace string, conditions *params.Conditions, orderBy string, reverse bool) ([]interface{}, error) {
|
||||
deployments, err := informers.SharedInformerFactory().Apps().V1().Deployments().Lister().Deployments(namespace).List(labels.Everything())
|
||||
|
||||
|
||||
@@ -221,6 +221,14 @@ func (*podSearcher) fuzzy(fuzzy map[string]string, item *v1.Pod) bool {
|
||||
|
||||
func (*podSearcher) compare(a, b *v1.Pod, orderBy string) bool {
|
||||
switch orderBy {
|
||||
case StartTime:
|
||||
if a.Status.StartTime == nil {
|
||||
return false
|
||||
}
|
||||
if b.Status.StartTime == nil {
|
||||
return true
|
||||
}
|
||||
return a.Status.StartTime.Before(b.Status.StartTime)
|
||||
case CreateTime:
|
||||
return a.CreationTimestamp.Time.Before(b.CreationTimestamp.Time)
|
||||
case Name:
|
||||
|
||||
@@ -67,6 +67,7 @@ const (
|
||||
Role = "role"
|
||||
CreateTime = "createTime"
|
||||
UpdateTime = "updateTime"
|
||||
StartTime = "startTime"
|
||||
LastScheduleTime = "lastScheduleTime"
|
||||
chart = "chart"
|
||||
release = "release"
|
||||
|
||||
Reference in New Issue
Block a user